$lightboxOn = false;
var sliderHeight = "75px";
function showLightBoxLarge(){
	if(!$lightboxOn){
		$('#lightbox-large-wrapper').show();
		positionLightBoxLarge();
		$(window).resize(positionLightBoxLarge);
		$('#lightbox-large-container').show();
		$lightboxOn = true;
	}
} 
function closeLightBoxLarge(){
	$('#lightbox-large-wrapper').hide();
	$('#lightbox-large-container').hide();
	$lightboxOn = false;
}
function positionLightBoxLarge(){
	centerLightBox($('#lightbox-large-container'));
}
function positionLightBox(){
	centerLightBox($('#lightbox-container'));
}
function closeLightBox(){
	$('#lightbox-wrapper').hide();
	$('#lightbox-container').hide();
	$lightboxOn = false;
	var dt = new Date(), 
	expiryTime = dt.setTime( dt.getTime() + 20000 );
	document.cookie = "cookieset=popupcookie; path=/ ; expires=" + dt.toGMTString();
	document.cookie = "expireTime="+expiryTime+"; path=/ ; expires=" + dt.toGMTString();
	showFacebookConnectPopUp('1');
var chk=document.getElementById('sliderarea');
if(chk){
chk.style.display="block";
}

 }
function showLightBox(){
	if(!$lightboxOn){
		$('#lightbox-wrapper').show();
		positionLightBox();
		$(window).resize(positionLightBox);
		$('#lightbox-container').show();
		$lightboxOn = true;
	}
}
function centerLightBox(obj){
	$top = ($(window).height() - $(obj).outerHeight())/2;
	$top = $top < 0?0:$top;
	$left = ($(window).width() - $(obj).outerWidth())/2;
	$(obj).css('top',$top);
	$(obj).css('left',$left);
}
function showFacebookConnectPopUp(delay){
	if(delay=='0'){
		var time = (typeof time == "undefined")?2000:0;
		var timer = setTimeout('showLightBox()',time);
	}else{
		var time = (typeof time == "undefined")?20000:0;
		var timer = setTimeout("showLightBox()",time);
	}
}
function showFacebookConnectSignup(){
	showLightBox();
}
function sliderAction(obj){ 
	 if ($(obj).attr('rel') == "closed"){ 
       sliderOpen(obj); 
       $(obj).attr('rel','open'); 
       $(obj).parent().parent().find(".slider_menu a").text('- less'); 
   }else if ($(obj).attr('rel') == "open"){ 
       sliderClose(obj); 
       $(obj).attr('rel','closed'); 
       $(obj).parent().parent().find(".slider_menu a").text('+ more'); 
   } 
   return false; 
} 
function sliderOpen(obj){ 
   var open_height = $(obj).parent().parent().find(".slider").attr("box_h") +"px"; 
   $(obj).parent().parent().find(".slider").animate({"height": open_height}, {duration: "medium" }); 
} 
function sliderClose(obj){ 
   $(obj).parent().parent().find(".slider").animate({"height": sliderHeight}, {duration: "medium" }); 
}	
function clearFunc(id,val){
	if(id==val){
		document.getElementById(id).value = "";
	}
}
function showFunc(id,val){
	if(val==""){
		document.getElementById(id).value = id;
	}
}
function pwdCreateFocus() {
    $('#fake-create-password').hide();
    $('#create-password').show();
    $('#create-password').focus();
}
function pwdCreateBlur() {
    if ($('#create-password').attr('value') == '') {
        $('#create-password').hide();
        $('#fake-create-password').show();
        $('#fake-create-password').css('background','#eeeeee');
    }
}
function pwdRepeatFocus() {
    $('#fake-repeat-password').hide();
    $('#repeat-password').show();
    $('#repeat-password').focus();
}

function pwdRepeatBlur() {
    if ($('#repeat-password').attr('value') == '') {
        $('#repeat-password').hide();
        $('#fake-repeat-password').show();
        $('#fake-repeat-password').css('background','#eeeeee');
    }
}
function checkSubmitNorthContact(server){
	$('.north-contact-activity-message').text("");
	$('#north-contact-activity').css("display","block");
	var count = 0;
	$('.account-middle input').each(function(index){
		 var name = $(this).attr('id').replace("-", " ");
		 if(name == $(this).val()){
			count = 2;
		 }else if(($(this).attr('id') == "fake-create-password") && ($(this).val() == "Create password")){
			count = 2;
		}else if(($(this).attr('id') == "fake-repeat-password") && ($(this).val() == "Repeat password")){
			count = 2;
		}
	});
	$('.error').each(function(index) {
		if($(this).text()!=""){
			count = 1;
		}
 	});
	
 	if(count == '1'){
 		$('#north-contact-activity').css("display","none");
 		alert('Please fix the errors shown below.');
 	}else if(count == '2'){
 		$('#north-contact-activity').css("display","none");
 		alert('At least one of your fields contains invalid information.');
	 }else{
		var company = $('#company-name').val();
		var firstName = $('#first-name').val();
		var lastName = $('#last-name').val();
		var email = $('#email').val();
		var country = 'United States of America';
		var username = $('#user-name').val();
		var password = $('#create-password').val();
		var name = firstName+" "+lastName;
		$.ajax({
			   type: "POST",
			   url: server+"/ajax/north-contact-signup.php",
			   data: "company="+company+"&name="+name+"&email="+email+"&country="+country+"&username="+username+"&password="+password,
			   success: function(data){
			   var a = data.indexOf("Code");
			   var b = data.indexOf(',');
			   if(a>'0'){
				   var errorCode = data.substring((a+6),b);
				   if(errorCode == '150'){
					   alert('Chosen email address is already being used! Please Try Again!');
				   }else if(errorCode == '172'){
					   alert('You can create a maximum of five (5) clients per thirty (30) minutes! Please Try Again after sometime!');
				   }else if(errorCode == '151'){
					   alert('The chosen username is already being used, either by the designer or by a client! Please Try Again!');
				   }else if(errorCode == '173'){
					   alert('You cannot set client billing options for clients without Create Send access! Please Try Again!');
				   }
				   $('.north-contact-activity-message').text("There was an error while creating your Account. Please try again.");
			   }else{
				   $('.north-contact-activity-message').text("Account Successfully Created!");
				   $('#username').val(username);
				   $('#password').val(password);
				   $('#loginForm').submit();
			   }
				   $('#north-contact-activity').css("display","none");
			   },
			   error: function(data){
				   $('#north-contact-activity').css("display","none");
				   $('.north-contact-activity-message').text("There was an error while creating your Account. Please try again.");
			   }
		 });
 	}
}	
function showInstall(canvas_name,show,value){
	if(show){
		$("#step-1").css("display","none");
	    $("#step-2").css("display","block");
	    $("select#fan-page option[value='"+value+"']").attr("selected", "selected");
		$('#install-form').show();
		$action = $("#install-form").attr('href');
		$position = $action.lastIndexOf("=");
		$action = $action.slice(0,$position);
		$action = $action+'='+encodeURIComponent("http://apps.facebook.com/"+canvas_name+"/?edit&fp="+value+"&install");
		$("#install-form").attr('href',$action);
	}else{
		$("#step-1").css("display","block");
	    $("#step-2").css("display","none");
	    $("select#fan-page option[value='"+value+"']").attr("selected", "selected");
		$('#install-form').hide();
	}	
		
 }
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function updateCursorPosition(e){
	cX = e.pageX; cY = e.pageY;
}
function updateCursorPositionDocAll(e){ 
	cX = event.clientX; cY = event.clientY;
}
if(document.all) { document.onmousemove = updateCursorPositionDocAll; }
else { document.onmousemove = updateCursorPosition; }
function assignPosition(d) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
		}
	else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
		}
	else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
		}
	if(document.all) {
		cX += rX; 
		cY += rY;
		}
	d.style.left = (cX+7) + "px";
	d.style.top = (cY+6) + "px";
}
function hideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function showContent(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	assignPosition(dd);
	dd.style.display = "block";
}
function reverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	assignPosition(dd);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}
