//This function is used in login areas
//pass foo('open') opens it...etc
//it then focuses to username
function foo(swing){
	if(swing =='open'){
		$('#bompa_stuff').show('slow');
		$('#login_stuff').hide('fast');
		$('#login_username').focus();
	}else{
		$('#bompa_stuff').hide('slow');
		$('#login_stuff').show('fast');
	}
}



// validates email address
// function checkEmail(email) {
// //if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/(email)) {
// var regexp = /^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$/
// if (regexp.test(email)) {
// return true;
// } else {
// return false;
// }
// }


// Removes leading whitespaces
function LTrim( value ) {

	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {

	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {

	return LTrim(RTrim(value));
}

var errorMessageHideTimer;


// This function opens links in an external window in a standards compliant way.
// To use it, code the link like this:
// <a href="document.html" onclick="setTargetBlank(this);">external link</a>
function setTargetBlank(thelink) {
	thelink.target = "_blank";
}


// hide a given HTML element
function hideElement(id) {
	var element = document.getElementById(id);
	element.style.display = 'none';
}


// show a given HTML element
function showElement(id) {
	var element = document.getElementById(id);
	element.style.display = '';
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioName) {

	var radioObj = document.getElementsByName(radioName);

	if (!radioObj) {
		return '';
	}
	var radioLength = radioObj.length;
	if (radioLength == undefined) {
		if(radioObj.checked) {
			return radioObj.value;
		} else {
			return '';
		}
	}
	for (var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return '';
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value=obj.value.substring(0,mlength);
		return false;
	}
	return true;
}

// Validate if a required radio selection has been made or not.
function radioIsChecked(radio_element) {
	// In the case where a user has access only to one band,
	// form.catbandid.length will return UNDEFINED
	// because HTML forms require at least TWO radio buttons. This simple check
	// will return true under that
	// condition, because if there is only one band to choose from, it is
	// automatically checked by default, so
	// we always return true to escape the band check.
	if(!radio_element.length) {
		return true;
	}
	for (i = 0; i < radio_element.length; i++) {
	   	if (radio_element[i].checked) {
	    	return true;
	    }
	}
   	return false;
}


// confirm before submitting a form
function confirmSubmit(msg) {
	if (typeof msg == 'undefined') {
		msg = 'Are you sure you wish to delete this?' + "\n" + 'This cannot be undone!!';
	}
	var agree = confirm(msg);
	if (agree) {
		return true;
	} else {
		return false;
	}
}


// Check all songs in a setlist
function checkAllSongBoxes(){
	var songs_are_checked	= document.getElementById('checkall_songs');
	var checkbox_elements 		= document.getElementsByName('song_array[]');

	to_be_checked = toggleCheckTracker(songs_are_checked);
	toggleChecks(checkbox_elements, to_be_checked);
}


// Check all genres
function checkAllGenres(){
	var genres_are_checked	= document.getElementById('checkall_genres');
	var checkbox_elements 	= document.getElementsByName('genres[]');

	to_be_checked = toggleCheckTracker(genres_are_checked);
	toggleChecks(checkbox_elements, to_be_checked);
}


// loop through all checkboxes and toggle their checked status
function toggleChecks(element, checked) {
	for (var i=0; i < element.length; i++){
		element[i].checked = checked;
	}
}


// sets the tracker element so we know if all checks are currently ON or OFF
function toggleCheckTracker(element) {
	if (element.value == 'false'){
		to_be_checked = 1
		element.value = 'true';
	} else {
		to_be_checked = 0
		element.value = 'false';
	}
	return to_be_checked;
}






function daysInMonth(iMonth, iYear) {

	return 32 - new Date(iYear, iMonth, 32).getDate();

}

function date_month_change() {

	var month = document.getElementById('birthday_month').value;
	month = month-1; // important!!! javscript treats january as 0th month,
						// february as 1st month etc..
	var day = document.getElementById('birthday_day').value;
	var year = document.getElementById('birth_year').value;
	var lastDay;
	switch(month+1) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			lastDay = 31;
		break;
		case 2:
			lastDay = 29;
		break;
		case 4:
		case 6:
		case 9:
		case 11:
			lastDay = 30;
		break;

	}
	if(	month >= 0 && year != "") {
		lastDay = daysInMonth(month, year);
	}
	if(month < 0) {
		lastDay = 31;
	}
	var previousSelectedDay = document.getElementById('birthday_day').value;
	document.getElementById('birthday_day').options.length = 0;
	var option = document.createElement("OPTION");
	theText=document.createTextNode("Day:");
	option.appendChild(theText);
	option.value = "99";
	document.getElementById("birthday_day").appendChild(option);
	for(i=1; i<=lastDay; i++) {
		var option = document.createElement("OPTION");
		theText=document.createTextNode(i);
		option.appendChild(theText);
		option.value = i;
		if(previousSelectedDay == i) {
			option.selected = true;
		}
		document.getElementById("birthday_day").appendChild(option);
	}

}


function showLogin(redirection,url) {

	if(redirection==1){
		jQuery("#dest").val(redirection);
	}
	// if(index == 1) {
		var position = jQuery("#header_login_link").position();
		var position1 = jQuery("#menu").position();
		var s = (position.left+position1.left)+'px';
		// var s = (position1.left)+'px';
		document.getElementById('login_outer').style.left=s;
		// document.getElementById('login_outer').style.left='547px';
	// }
	if (!jQuery("#login_outer-registration").is(":hidden")) {
		closeRegistration();
	}

	if (jQuery("#login_outer").is(":hidden")) {
		jQuery('#login_outer').slideDown('slow');
	}
}

function showRegistration(index) {
	var position = jQuery("#header_register_link").position();
	var position1 = jQuery("#menu").position();
	var s = (position.left+position1.left)+'px';
	document.getElementById('login_outer-registration').style.left=s;

	if (!jQuery("#login_outer").is(":hidden")) {
		closeLogin();
	}
	if (jQuery("#login_outer-registration").is(":hidden")) {
		jQuery('#login_outer-registration').slideDown('slow');
	}
}
function closeLogin() {
	jQuery('#login_outer').slideUp('slow');
}
function closeRegistration() {
	jQuery('#login_outer-registration').slideUp('slow');
}


function showNotification(message){
	if ($('#notificationBar').length) {
		jQuery('#notificationBar').html("<p onclick='hideErrorMessageAtTop()'>"+String(message)+"</p>");
		jQuery("#notificationBar").slideDown("slow");
		errorMessageHideTimer = setTimeout('jQuery("#notificationBar").slideUp("slow")',3000);
	}else{
		alert(message);
	}
}

function hideErrorMessageAtTop(){
	if(errorMessageHideTimer!=null)
		clearTimeout(errorMessageHideTimer);
	jQuery("#notificationBar").slideUp("slow");
}

function showSuccessMsg(message){
	jQuery('#successMsg').html("<p onclick='hideSuccessMsg()'>"+String(message)+"</p>");
	jQuery("#successMsg").slideDown("slow");
	errorMessageHideTimer = setTimeout('jQuery("#successMsg").slideUp("slow")',3000);
}

function hideSuccessMsg(){
	if(errorMessageHideTimer!=null)
		clearTimeout(errorMessageHideTimer);
	jQuery("#successMsg").slideUp("slow");
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function isUrl(s) {
	var regexp = new RegExp(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/);
	return regexp.test(s);
}

function moveup(id){
	// document.getElementById(id).style.top=2+"px";
	// if(id!=null && id!=""){
	// $("#"+id+"").addClass("top_style2");
	// }

}
function movedown(id){
	// document.getElementById(id).style.top=7+"px";
	// if(id!=null && id!=""){
	// $("#"+id+"").addClass("top_style7");
	// }
}



function showMessage(message){
	showNotification(message);
	/*
	 * jQuery('#notificationBar').html(message);
	 * jQuery("#notificationBar").slideDown("slow");
	 * setTimeout('jQuery("#notificationBar").slideUp("slow")',3000);
	 */
}


function show_list(e) {

		if (!e) e = window.event;
		if (e.target) el = e.target;
		else if (e.srcElement) el = e.srcElement;
		var id = el.id;

		if(document.getElementById('list_box'))	{
			if(id == 'search_text') {
				if(document.getElementById('search_text').value == '') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else if(id == 'venue_list'){
				if(document.getElementById('search_text').value == '') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else if(id=='cloth_list'){
				if(document.getElementById('search_text').value == '') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else if(id=='user_list'){
				if(document.getElementById('search_text').value == '') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else if(id=='band_list'){
				if(document.getElementById('search_text').value == '') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else{
				if(document.getElementById('search_text').value == '') {
				document.getElementById('search_text').value='';
			}
				document.getElementById('list_box').style.display="none";
			}
		}


}

function show_list_index(e) {

		if (!e) e = window.event;
		if (e.target) el = e.target;
		else if (e.srcElement) el = e.srcElement;
		var id = el.id;

		/*
		 * alert("1"+jQuery("#list_box").parents("#search"));
		 * if(jQuery("#list_box").parent() == jQuery("#search")){ var position =
		 * jQuery("#search").position(); alert(position.left);
		 * document.getElementById('list_box').style.left = position.left; }
		 */

		if(document.getElementById('list_box'))	{
			if(id == 'search_text') {
				if(document.getElementById('search_text').value == 'Search for Band, Venue, Company or User') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
				document.getElementById('search_text').style.color="black";
			}else if(id == 'venue_list'){
				if(document.getElementById('search_text').value == 'Search for Band, Venue, Company or User') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else if(id=='cloth_list'){
				if(document.getElementById('search_text').value == 'Search for Band, Venue, Company or User') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else if(id=='user_list'){
				if(document.getElementById('search_text').value == 'Search for Band, Venue, Company or User') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else if(id=='band_list'){
				if(document.getElementById('search_text').value == 'Search for Band, Venue, Company or User') {
				document.getElementById('search_text').value='';
				}
				document.getElementById('list_box').style.display="block";
			}else{
				if(document.getElementById('search_text').value == '') {
				document.getElementById('search_text').value='Search for Band, Venue, Company or User';
				}
				document.getElementById('list_box').style.display="none";
			}
		}


}

function select_list_item(val,e) {

	if (!e) e = window.event;
	if (e.target) el = e.target;
	else if (e.srcElement) el = e.srcElement;
	var id = el.id;

	if(id == 'venue_list' || id=='cloth_list' || id=='band_list' || id=='user_list') {
		document.getElementById('list_box').style.display="block";
	}

	if(val == 'band') {
		document.getElementById('band_list').className="active";
		document.getElementById('venue_list').className="";
		document.getElementById('user_list').className="";
		document.getElementById('cloth_list').className="";
		document.getElementById('selected_item').value =0;
		document.getElementById("cloth_list").style.background = "";
	}
	if(val == 'venue') {
		document.getElementById('band_list').className="";
		document.getElementById('venue_list').className="active";
		document.getElementById('user_list').className="";
		document.getElementById('cloth_list').className="";
		document.getElementById('selected_item').value =1;
		document.getElementById("cloth_list").style.background = "";
	}
	if(val == 'user') {
		document.getElementById('band_list').className="";
		document.getElementById('venue_list').className="";
		document.getElementById('user_list').className="active";
		document.getElementById('cloth_list').className="";
		document.getElementById("cloth_list").style.background = "";
		document.getElementById('selected_item').value =3;
	}
	if(val == 'company') {
		document.getElementById('band_list').className="";
		document.getElementById('venue_list').className="";
		document.getElementById('user_list').className="";
		document.getElementById('cloth_list').className="active";
		document.getElementById('selected_item').value =2;
		// document.getElementById("city_list").style.background =
		// 'url(../../../images/bg_dropdown_hover_facebbok_search.png)';
	}
	document.getElementById('search_text').focus();
}
function select_list_item_search(val) {

	if(val == 'band') {
		document.getElementById('band_list').className="active";
		document.getElementById('venue_list').className="";
		document.getElementById('cloth_list').className="";
		document.getElementById('user_list').className="";
		document.getElementById('selected_item').value =0;
		document.getElementById("cloth_list").style.background = "";
	}
	if(val == 'venue') {
		document.getElementById('band_list').className="";
		document.getElementById('venue_list').className="active";
		document.getElementById('user_list').className="";
		document.getElementById('cloth_list').className="";
		document.getElementById('selected_item').value =1;
		document.getElementById("cloth_list").style.background = "";
	}
	if(val == 'cloth') {
		document.getElementById('band_list').className="";
		document.getElementById('venue_list').className="";
		document.getElementById('user_list').className="";
		document.getElementById('cloth_list').className="active";
		document.getElementById('selected_item').value =2;
		// document.getElementById("city_list").style.background =
		// 'url(../../../images/bg_dropdown_hover_facebbok_search.png)';
	}
	if(val == 'user') {
		document.getElementById('band_list').className="";
		document.getElementById('venue_list').className="";
		document.getElementById('cloth_list').className="";
		document.getElementById('user_list').className="active";
		document.getElementById("cloth_list").style.background = "";
		document.getElementById('selected_item').value =3;
	}

}

function show_image1() {

	 document.getElementById("cloth_list").style.background = 'url(../../images/bg_dropdown_hover_facebbok_search.png)';
}
function hide_image1() {
		if(document.getElementById("cloth_list").className == "active")
			document.getElementById("cloth_list").style.background = 'url(../../images/bg_dropdown_hover_facebbok_search.png)';
		else
		document.getElementById("cloth_list").style.background = "";
}
function urlmatch(url) {
	// return
	// url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
	var companyUrl =url;
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(companyUrl))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function isNumber(n) {
	  return !isNaN(parseFloat(n)) && isFinite(n);
	}

function isNumberKey(evt) {
 var charCode = (evt.which) ? evt.which : event.keyCode;
 if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;

 return true;
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}
var newsUrl = '';
var page = 0;
function loadNews(url){
	newsUrl = url;
	page =0;
	jQuery('#contentNews').html('<img class="loadingimg" src="./images/ajax-loader.gif" alt="News is loading.." />');
	jQuery.get(url, function(data) {
		jQuery('#contentNews').html(data);
	});


}

function loadAjaxUrl(url, divID, params){
	var data = '?1';
	for(var i in params){
		data += '&' + i + '=' + params[i];
	}
	jQuery.ajax({
		url: url,
		data : data,
		cache : false,
		success: function(data){
			jQuery(divID).html(data);
		}
	});
}

function ajaxCall(url, divID, params){
	var data = '?1';
	for(var i in params){
		data += '&' + i + '=' + params[i];
	}
	jQuery.ajax({
		url: url,
		data : data,
		cache : false,
		success: function(data){
			console.log(data);
			if(data.divID && data.html){
				jQuery(data.divID).html(data.html);
			}

		}
	});
}

function makeModal(){

	// select all the a tag with name equal to modal
	jQuery('a[name=modal]').click(function(e) {
		// Cancel the link behavior
		e.preventDefault();

		// Get the A tag
		var id = jQuery(this).attr('href');

		// Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();

		// Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});

		// transition effect
		jQuery('#mask').fadeIn(1000);
		jQuery('#mask').fadeTo("slow",0.8);

		// Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();

		// Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);

		// transition effect
		jQuery(id).fadeIn(2000);

	});

	// if close button is clicked
	jQuery('.window .close').click(function (e) {
		// Cancel the link behavior
		e.preventDefault();

		jQuery('#mask').hide();
		jQuery('.window').hide();
	});

	// if mask is clicked
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
	});

}

function showEmailUpdate() {

	var position = jQuery("#header_login_link").position();
	var position1 = jQuery("#menu").position();
	var s = (position.left+position1.left)+'px';
	document.getElementById('email_update_outer').style.left=s;
	if (jQuery("#email_update_outer").is(":hidden")) {
		jQuery('#email_update_outer').slideDown('slow');
	}
}

function closeEmailUpdate() {
	jQuery('#email_update_outer').slideUp('slow');
}

function removeFacebookStyles() {
	jQuery(".FBConnectButton_Simple").removeClass("FBConnectButton_Simple");
	jQuery(".FBConnectButton_Text_Simple").addClass("whiteText");
	jQuery(".FBConnectButton_Text_Simple").removeClass("FBConnectButton_Text_Simple");
}

function modify_facebook_share(id,imgSrc,title) {
	var link = document.getElementById(id);
	link.href="http://www.facebook.com/sharer.php?u="+imgSrc+"&t="+title;

	var outerspan = jQuery("#"+id+".FBConnectButton_Simple");
	var innerspan = jQuery("#"+id+".FBConnectButton_Text_Simple");
	jQuery(".FBConnectButton_Simple").removeClass("FBConnectButton_Simple");
	jQuery(".FBConnectButton_Text_Simple").addClass("whiteText");
	jQuery(".FBConnectButton_Text_Simple").removeClass("FBConnectButton_Text_Simple");

}

function twitterShare(status) {

	window.open('http://twitter.com/home?status='+status,'','width=800,height=600,scrollbars=1');
}

function myspaceVideoShare(title,video_code,video_url) {

	window.open('http://www.myspace.com/Modules/PostTo/Pages/?t='+title+'&c='+video_url,'','width=800,height=600,scrollbars=1');

}

function myspacePhotoShare(title,photo_url) {

	window.open('http://www.myspace.com/Modules/PostTo/Pages/?t='+title+'&c='+photo_url,'','width=800,height=600,scrollbars=1');
}

function facebookPhotoShare(title,url) {

	window.open('http://www.facebook.com/sharer.php?u='+url+'&t='+title,'','width=800,height=600,scrollbars=1');
}


function twitterShareBlog(url,contentid) {
	var status = jQuery('#'+contentid).val();
	window.open('http://twitter.com/home?status='+status+' view full article at: '+url,'','width=800,height=600,scrollbars=1');
}

function myspaceShareBlog(title,url,contentid) {
	var content = jQuery('#'+contentid).val();

	window.open('http://www.myspace.com/Modules/PostTo/Pages/?t='+title+'&u='+url+'&c='+content+' view full article at: '+url,'','width=800,height=600,scrollbars=1');
}

function facebookShareBlog(title,url,contentid) {
	var content = jQuery('#'+contentid).val();
	window.open('http://www.facebook.com/sharer.php?t='+title+'&u='+url,'','width=800,height=600,scrollbars=1');
}

/* css browser selector */
var css_browser_selector = function() {
	var ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

/*
 * scroll the message box to the top offset of browser's scrool bar
 * <!--shiraz--> $(window).scroll(function() {
 * $('#notificationBar').animate({top:$(window).scrollTop()+"px" },{queue:
 * false, duration: 350}); });
 */

function showRegistrationOption(pagetype, siturl) {
	if(pagetype == 1) {
		jQuery('#login_outer').hide();
		jQuery('#firstname').focus();
	} else {
		window.location.href = siturl + 'register.php';
	}
}

function createCookieProfile(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie ( cookie_name ){
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function gotomyprofile(url) {
	createCookieProfile('redirectCookieFbconnect',"",-1);
	window.location.href = url;
}



function addFriend(friend_id, siteurl) {

		url = siteurl+'ajax/addFriend.php?friend_id='+friend_id;
		jQuery.get(url, function(data) {
			if(data == 0) {
				showNotification('Error in adding friend');
				return;
			} else {
				if(data.indexOf("login") > 0) {
					showNotification('Please login to continue');
					showLogin(1);
				} else {
					jQuery('#addfriend_div').html(data);
				}
				// showSuccessMsg("Your comment has been deleted successfully");
				// showNotification(message)
			}
		});
}


function showNewStuff() {
	jQuery("#new-stuff").show();

	if(jQuery("#updates-div").attr("display") != "none"){
		jQuery("#updates-div").hide();
	}
}

function showUpdates(){
	jQuery("#updates-div").show();
	getUpdates();

	if(jQuery("#new-stuff").attr("display") != "none"){
		jQuery("#new-stuff").hide();
	}


}
function getUpdates(){
	var siteURL = '<?php echo SITEURL ?>';
			jQuery('#res_tst').html('<br /><img src="'+siteurl+'images/ajax-loader-small.gif" /><br /><br />');
        	jQuery(document).ready(function(){
				url = siteurl+'ajax/printUpdates.php';
				jQuery.get(url, function(data) {
					var res_str	=	data.split("~")
					jQuery("#res_tst").html(res_str[0]);
					if(parseInt(res_str[1]) > 0) {
						jQuery("#update_count").html(res_str[1]);
						jQuery(".updates-point").show();
					} else {
						jQuery(".updates-point").hide();
					}

				});
	});
}
function closeUpdateDiv(){
	jQuery('#updates-div').hide();
}

function jsNavigation(stat){
	var f_count			=	Number($('#f_current').val());
	var f_count_next	=	Number(f_count)+1;
	var f_count_prev	=	Number(f_count)-1;

	if(stat=="next"){
		jQuery('.'+ f_count).hide();
		jQuery('.'+ f_count_next).show();
		$('#f_current').val(f_count_next);
	} else if(stat=="prev") {
		jQuery('.'+ f_count).hide();
		jQuery('.'+ f_count_prev).show();
		$('#f_current').val(f_count_prev);
	}

	var f_count			=	Number($('#f_current').val());

	// alert('count :'+f_count+' prev:'+f_count_prev+' nect '+f_count_next);

	if(f_count==Number($('#f_max').val())){
		$('#f_nav_next').hide();
	} else {
		$('#f_nav_next').show();
	}

	if(Number(f_count)==1){
		$('#f_nav_prev').hide();
	} else {
		$('#f_nav_prev').show();
	}


}

function jsNavigationBand(stat){
	var b_count			=	Number($('#b_current').val());
	var b_count_next	=	Number(b_count)+1;
	var b_count_prev	=	Number(b_count)-1;

	if(stat=="next"){
		jQuery('.b_'+ b_count).hide();
		jQuery('.b_'+ b_count_next).show();
		$('#b_current').val(b_count_next);
	} else if(stat=="prev") {
		jQuery('.b_'+ b_count).hide();
		jQuery('.b_'+ b_count_prev).show();
		$('#b_current').val(b_count_prev);
	}

	var b_count			=	Number($('#b_current').val());

	// alert('count :'+b_count+' prev:'+b_count_prev+' next '+b_count_next);

	if(b_count==Number($('#b_max').val())){
		$('#b_nav_next').hide();
	} else {
		$('#b_nav_next').show();
	}

	if(Number(b_count)==1){
		$('#b_nav_prev').hide();
	} else {
		$('#b_nav_prev').show();
	}


}

function jsNavigationCloth(stat){
	var c_count			=	Number($('#c_current').val());
	var c_count_next	=	Number(c_count)+1;
	var c_count_prev	=	Number(c_count)-1;

	if(stat=="next"){
		jQuery('.c_'+ c_count).hide();
		jQuery('.c_'+ c_count_next).show();
		$('#c_current').val(c_count_next);
	} else if(stat=="prev") {
		jQuery('.c_'+ c_count).hide();
		jQuery('.c_'+ c_count_prev).show();
		$('#c_current').val(c_count_prev);
	}

	var c_count			=	Number($('#c_current').val());

	// alert('count :'+b_count+' prev:'+b_count_prev+' next '+b_count_next);

	if(c_count==Number($('#c_max').val())){
		$('#c_nav_next').hide();
	} else {
		$('#c_nav_next').show();
	}

	if(Number(c_count)==1){
		$('#c_nav_prev').hide();
	} else {
		$('#c_nav_prev').show();
	}


}



function getNewStuff(page){
	url = siteurl+'ajax/getlatestStuff.php?page='+page;
	jQuery(".product_container").html('<img class="loadingimg" src="./images/ajax-loader-small.gif" alt="Item is loading.." />');
	jQuery.get(url, function(data) {
		jQuery("#new-stuff").html(data);
	});
}

function closeNewStuffDiv(){
	jQuery('#new-stuff').hide();
	getNewStuff(0);
}



function fbconnect_btnclick(){
	url = siteurl+'ajax/confirmFacebookConnectLoginAttempt.php';
		jQuery.get(url, function(data) {
			window.location.reload();
	});
}
function clearUpdatePopup(){
	jQuery(document).ready(function(){
				url = siteurl+'ajax/clearUpdates.php';
				jQuery.get(url, function(data) {
				// alert(data);
				});
	});

	getUpdates();
}


function changeSearchTextColor(textColor) {
	jQuery("#search_text").css({color:'#'+textColor});
}

function updateFaves(){
	$.ajax({
		   type: "GET",
		   url: siteurl+"ajax/LoadFaves.php",
		   data: "not_used=1",
		   success: function(msg){
			   if(msg==''){
				   showSuccessMsg('Error');
			   }else{
				   $('#faves').html(msg);
			   }
		   }
	});
}

function deleteFromMyFavorites(id){
	if(!confirm("Are you sure to remove this band from your favorite?")){
		return;
	}
	$.ajax({
		   type: "GET",
		   url: siteurl+"ajax/removefavoriteband.php",
		   data: "band_id="+id,
		   success: function(msg){
		     if(msg==1){
		 		jQuery("#userBand"+id).hide();
				favcount = parseInt(jQuery("#favcount").html());
				favcount = favcount - 1;
				jQuery("#favcount").html(favcount+'');
				updateFaves();
				showSuccessMsg('The band has been removed from your favorite.');
		     }else{
		    	 showNotification('Error in removing the band from your favorites');
		     }
		   }
	});

	/*
	 * url = 'ajax/removefavoriteband.php?band_id='+id; jQuery.get(url,
	 * function(data) { if(data == 1) { jQuery("#userBand"+id).remove();
	 * favcount = parseInt(jQuery("#favcount").html()); favcount = favcount - 1;
	 * jQuery("#favcount").html(favcount+''); showSuccessMsg('The band has been
	 * removed from your favorite.'); return; } else { showNotification('Error
	 * in removing the band from your favorites'); } });
	 */
}

function deleteFromMyFavoritesCompany(id){
	if(!confirm("Are you sure to remove this company from your favorite?")){
		return;
	}
	url = 'ajax/removefavoritecompany.php?cloth_id='+id;
	jQuery.get(url, function(data) {
		if(data == 1) {
 			jQuery("#userBand"+id).remove();
			favcount = parseInt(jQuery("#favcount").html());
			favcount = favcount - 1;
			jQuery("#favcount").html(favcount+'');
			showSuccessMsg('The company has been removed from your favorite.');
			return;
		} else {
			showNotification('Error in removing company from your favorites');
		}
	});
}

function closeTellFriendsDiv() {

	jQuery("#tellfriends-div").hide();
}

function showTellYourFriends() {

	var newstuff_left = jQuery('#li_newstuff').offset().left;
	var newstuff_top = jQuery('#li_newstuff').offset().top;
	jQuery("#tellfriends-div").css({left:parseInt(newstuff_left-50)+"px", top:parseInt(newstuff_top+150)+"px"});
	jQuery("#tellfriends-div").show();
}

function tellYourFriends() {

	if(jQuery('#quickUpdateTextFriends').val().trim() == '') {
		showNotification('Enter message');
		return false;
	}
	closeTellFriendsDiv();
	showSuccessMsg('Message posted on your favorite sites.');
	var options = {
		dataType:  'json',
		success:	function(data) {} // post-submit callback
	};
	jQuery('#form-post-review-networks').ajaxSubmit(options);
}

function clearAllNewStuff(){
	url = siteurl+'ajax/getlatestStuff.php?clearall=true';
	jQuery(".product_container").html('<img class="loadingimg" src="./images/ajax-loader-small.gif" alt="clearing all your new stuff.." />');
	jQuery.get(url, function(data) {
		jQuery("#new-stuff").html(data);
		jQuery("#newstuffcount-span").parent().hide();
		showSuccessMsg('All of your new stuff has been removed.');
	});
}

function Show_Popup(action, userid) {
	var hpos = (jQuery(window).height()/2) - (400/2);
	var wpos = (jQuery(window).width()/2) - (632/2);

	var popupNavHeight = jQuery('#contentPage').height() + jQuery('#header').height() + jQuery('#footer').height();

	jQuery('#popupNav').css({'opacity': '0.75','height': popupNavHeight}).fadeIn('slow');
	jQuery('#windowNav').css('top', hpos + 'px').css('left', wpos + "px").fadeIn('fast');
	// I added a function call here to insert my demo into the #window div
}

function Close_Popup() {
	jQuery('#popupNav').fadeOut('fast');
	jQuery('#windowNav').fadeOut('fast');
}

jQuery(document).ready(function() {
	jQuery('#icon_nav').hover(
			function() { jQuery('#windowNav .close').fadeOut('fast')},
			function() { jQuery('#windowNav .close').fadeIn('fast')}
	);
});




