/*
// -- all the cool things in Furnine Under construction page happens here
// -- designed and developed by ashanjay (ashanjay.com)
*/
//////////////////////////////////////////////////////////////////////////////

//disable sentitive features
var admin_switch="yes";

//your email address box
function hoverEM(){
	$('input#email_temp').click(function(){
		$('#login01').hide();
		$('#login02').show();
		$('#emailA').focus();
	});
}
	
//admin panel functions
function generl(){
	$('#ad_close').click(function(){
		$('#adminPanel').fadeOut().html("");
		$('#shadow').fadeOut();
		setTimeout("location.reload()",1500);
	});	
	
	//Percentage up and down button functions
	$('#cm_down').click(function(){
		$('#ad_save').fadeIn();
		var marg= parseInt($('#cm_no').css('marginTop'));
		var marG = marg - 46;
		if(marg!= (-460)){
			$('#cm_no').animate({
				marginTop: marG
			})
		}
	});
	$('#cm_up').click(function(){
		$('#ad_save').fadeIn();
		var margt= parseInt($('#cm_no').css('marginTop'));
		var margT = margt + 46;
		if(margt!= (0)){
			$('#cm_no').animate({
				marginTop: margT
			})
		}
	});
	
	//Currently working focus related functions
	$('.ad_h4[name=currWork]').click(function(){
		$(this).hide();
		$('#currW_holder').fadeIn().focus();
		$('#currW').focus();
	});
	$('#currW_holder .sfbtn').click(function(){
		$('#currW_holder').hide();
		$('.ad_h4[name=currWork]').fadeIn();
	});
	
	//Expiration date focus related functions
	$('#expireD').click(function(){
		$(this).hide();
		$('#expDS_holder').fadeIn();
	});
	$('#expDS_holder .sfbtn[name=cancel]').click(function(){
		$('#expDS_holder').hide();
		$('#expireD').fadeIn();
	});
	
	//facebook
	socialBTN('facebook','fb');
	//Twitter
	socialBTN('twitter','tw');
	
	//pop up admin window positioning
	$(window).resize(function() {
		resizeADM();
	});
	resizeADM();
}

// ########################################################################### //
//resize admin window function
function resizeADM(){
	var wit= $('#adminPanel').width();
	var Hwi=$(window).width();	
	var pect=parseInt((((Hwi- wit)/2)/Hwi)*100);	
	$('#adminPanel').css('left', pect+'%');
}

//Function to animate social media buttons
function socialBTN(str, str2){//example str=facebook str2=fb
	$('.ad_h4[name='+str+']').click(function(){
		if($('.row:not(#'+str2+'_row)').css('display')=="none"){
			$('#'+str2+'_row').slideToggle();
		}else{
			$('.row:not(#'+str2+'_row)').slideUp();
			$('#'+str2+'_row').slideToggle();			
		}	
	});
	$('#'+str2+'_row .sfbtn[name=cancel]').click(function(){
		if($('#'+str2+'_row input[name='+str2+'link]').val()==""){
			$('#'+str2+'_row').slideUp();
		}else{
			$('#'+str2+'LK_p').fadeIn();
			$('#'+str2+'_row .edtBar').hide();
		}		
	});
	$('#'+str2+'LK_p').click(function(){
		$(this).hide();
		$('#'+str2+'_row .edtBar').fadeIn().focus();
	});
}


//Initiate XML HTTP request for AJAX
var xhr = false;
function initAll() {
  xhr = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 xhr = new XMLHttpRequest();
	 if (xhr.overrideMimeType) {
		// set type accordingly to anticipated content type
		//xhr.overrideMimeType('text/xml');
		xhr.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   xhr = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!xhr) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
}

//Check entered email address
function infoR(obj){
	initAll();	
	var email = $("#emailA").val();

	var url='admin.php?taskDO=checker&email='+email;
	xhr.onreadystatechange =function(){
		if(xhr.readyState==4){
			var response=xhr.responseText;
			var update=new Array();
			
			if(response.indexOf('|$|'!=-1)){
				update=response.split('|$|');
				if(update[0]=="admin"){
					if($('.BadMsg').css('display')=='block'){$('.BadMsg').hide();						
						$('#get_update').css('borderColor', '#D1D1D1');
					}					
					$('#shadow').fadeIn();
					$('#adminPanel').html(update[1]);
					$('#adminPanel').fadeIn();
					generl();
				}
				if(update[0]=="noEM"){//incorrect email address
					$('#get_update').css('borderColor', '#dd730c');
					$('.BadMsg').html('Invalid email address, please try again!').fadeIn();
				}
				if(update[0]=="EM"){//sent email
					$('#get_update').slideUp();
					if($('.BadMsg').css('display')=='block'){$('.BadMsg').hide();						
						$('#get_update').css('borderColor', '#D1D1D1');
					}
					$('.GoodMsg').html('We will keep you updated on what\'s happening!!').fadeIn();
				}
			}	
		}	
	}
	xhr.open("GET",url,true);
	xhr.send(null);	
}


//Save percentage completed
function savePECT(){
	var perct= (parseInt((parseInt($('#cm_no').css('marginTop')))/46))*(-10);
	
	initAll();	
	$('.blank p').html("Loading..").fadeIn();
	var url='admin.php?taskDO=sPect&perct='+perct;
	xhr.onreadystatechange =function(){
		if(xhr.readyState==4){
			var response=xhr.responseText;
			if(response=="yes"){
				$('#ad_save').fadeOut();				
				hideNY("Successfully updated!");
			}			
		}
	}
	xhr.open("GET",url,true);
	xhr.send(null);	
}

//Save expiration date information
function expDS(){
	var month=$('.expire select[name=month]').val();
	var date=$('.expire select[name=date]').val();
	var year=$('.expire select[name=year]').val();
	
	initAll();	
	$('.blank p').html("Loading..").fadeIn();
	var url='admin.php?taskDO=expDS&month='+month+'&date='+date+'&year='+year;
	xhr.onreadystatechange =function(){
		if(xhr.readyState==4){
			var response=xhr.responseText;
			var update=new Array();
			if(response.indexOf('|$|'!=-1)){
				update=response.split('|$|');
				
				if(update[0]=="yes"){				
					$('#expireD').html(date+" "+update[1]+" "+year).fadeIn();
					$('#expDS_holder').hide();		
					hideNY("Successfully updated!");
				}
			}
		}
	}
	xhr.open("GET",url,true);
	xhr.send(null);	
}

//Save currently working status
if(admin_switch=="yes"){

	function sCwork(){
		if(admin_switch=="yes"){
			var currW= $('#currW').val();
			
			initAll();	
			$('.blank p').html("Loading..").fadeIn();
			var url='admin.php?taskDO=sCwork&currW='+currW;
			xhr.onreadystatechange =function(){
				if(xhr.readyState==4){
					var response=xhr.responseText;
					if(response=="yes"){	
						$('.ad_h4[name=currWork]').html(currW).fadeIn();
						$('#currW_holder').hide();		
						hideNY("Successfully updated!");
					}
				}
			}
			xhr.open("GET",url,true);
			xhr.send(null);	
		}
	}

	//Save facebook information
	function fbLK(){
		if(admin_switch=="yes"){
			var faceB=$('#fb_row input[name=fblink]').val();
			initAll();	
			$('.blank p').html("Loading..").fadeIn();
			var url='admin.php?taskDO=fbLK&faceB='+faceB;
			xhr.onreadystatechange =function(){
				if(xhr.readyState==4){
					var response=xhr.responseText;
					if(response=="yes"){	
						if(faceB==""){
							$('#fbLK_p').html("Click here to add link!").fadeIn();
							$('#fb_row .edtBar').hide();		
							hideNY("Successfully updated!");
						}else{
							$('#fbLK_p').html(faceB).fadeIn();
							$('#fb_row .edtBar').hide();		
							hideNY("Successfully updated!");
						}
					}
				}
			}
			xhr.open("GET",url,true);
			xhr.send(null);	
		}
	}

	//Save twitter information
	function twLK(){
		if(admin_switch=="yes"){
			var twit=$('#tw_row input[name=twlink]').val();
			initAll();	
			$('.blank p').html("Loading..").fadeIn();
			var url='admin.php?taskDO=twLK&twit='+twit;
			xhr.onreadystatechange =function(){
				if(xhr.readyState==4){
					var response=xhr.responseText;
					if(response=="yes"){	
						if(twit==""){
							$('#twLK_p').html("Click here to add only the twitter username!").fadeIn();
							$('#tw_row .edtBar').hide();		
							hideNY("Successfully updated!");
						}else{
							$('#twLK_p').html(twit).fadeIn();
							$('#tw_row .edtBar').hide();		
							hideNY("Successfully updated!");
						}
					}
				}
			}
			xhr.open("GET",url,true);
			xhr.send(null);	
		}
	}

}


//hide the status notification : only for .ad_h5
function hideNY(str){	
	$('.blank p').html(str);	
	setTimeout("$('.blank p').fadeOut('')",5000);	
}


