//This function is Customizable
//This Function is used to create overlay popup in Jquery
//Customized Version 1.0
//Author : Alipta Ballav

var popupStatus = 0;
var popupId;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").css({
			"width": document.documentElement.scrollWidth,
			"height": document.documentElement.scrollHeight
		});
		$("#backgroundPopup").fadeIn("slow");
		$(popupId).fadeIn("slow");
		popupStatus = 1;
	}
}
function setPopupId(id)
{
	popupId = "#"+id;
	
}

function loadPreview(){
	//loads preview after saving only if it is disabled
	/* if ( NOT SAVED YET)
		  line for SAVING
	*/
		var heightValue = document.documentElement.scrollHeight + 500
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").css({
			"height": "200%"
		});
		$("#backgroundPopup").css({
			"width" : document.documentElement.scrollWidth,
			"height":  heightValue
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#previewwebsite").fadeIn("slow");
		$("#ExternalFAQPreview").fadeIn("slow");
		$("#previewwebsite123").fadeIn("slow");
		$("#previewwebsite143").fadeIn("slow");
		$("#backgroundPopup").css({
			"height": document.documentElement.scrollHeight
		});
		
		popupStatus = 1;
		//popupStatus++;
		
}

function loadSsgViewPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").css({
			"height": document.documentElement.scrollHeight
		});
		$("#backgroundPopup123").css({
			"opacity": "13"
		});
		$("#backgroundPopup123").css({
			"height": document.documentElement.scrollHeight
		});
		$("#backgroundPopup123").fadeIn("slow");
		$("#backgroundPopup").fadeIn("slow");
		$("#ssgPopupContact").fadeIn("slow");
		$("#testPopupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		
		if(popupId == "#flashOverlay")
  		{
   			$("#flashOverlay").fadeOut("slow", function() {removeFlash(); });
  		}
		
		$(popupId).fadeOut("slow");		
		$("#popupContact2").fadeOut("slow");
		$("#previewwebsite").fadeOut("slow");
		$("#ExternalFAQPreview").fadeOut("slow");
		$("#previewwebsite123").fadeOut("slow");
		$("#previewwebsite143").fadeOut("slow");
		$("#loginPopupContact").fadeOut("slow");
		$("#ssgPopupContact").fadeOut("slow");
		$("#testPopupContact").fadeOut("slow");
		$("#ChangeYourPassword").fadeOut("slow");
		$("#ChangeYourPasswordConfirm").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#ChangeYourPassword").fadeOut("slow");
		$("#ChangeYourPasswordConfirm").fadeIn("slow");
		setPopupId("ChangeYourPasswordConfirm")//centering with css
		centerPopup();
		//load popup
		loadPopup();
		hideListControls();
		popupStatus = 1;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	//1 commented var windowHeight = document.documentElement.clientHeight;
	//2 commented var windowHeight = document.body.clientHeight;
	var windowHeight = document.documentElement.scrollHeight
	//alert(windowHeight);
 	if( window.innerHeight && window.scrollMaxY ) // Firefox
	{
         var windowHeight1 = window.innerHeight + window.scrollMaxY;
   	}
	
	
	else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
   		{

             windowHeight = document.body.scrollHeight;
       	}
	   
	 else
	 { 
	  
	  	windowHeight = document.body.offsetHeight + document.body.offsetTop;
		
	 }
	
	//var windowHeight = document.body.scrollHeight;
	
	//var windowHeight = document.body.clientHeight;
	//alert(windowHeight);
	//var windowHeight3 = document.body.scrollHeight;
	//var windowHeight2 = document.height;
	//var popupHeight = $("#popupContact").height();
	//var popupWidth = $("#popupContact").width();
	var popupHeight = $(popupId).height();
	var popupWidth = $(popupId).width();
	var previewHeight = $("#previewwebsite").height();
	var previewWidth = $("#previewwebsite").width();
	var mangHeight = $("#previewwebsite123").height();
	var editHeight = $("#previewwebsite143").height();
	var editWidth = $("#previewwebsite143").height();
	var mangWidth = $("#previewwebsite123").width();
	var ssgPopupHeight = $("#ssgPopupContact").height();
	var ssgPopupWidth = $("#ssgPopupContact").width();
		var testPopupHeight = $("#testPopupContact").height();
	var testPopupWidth = $("#testPopupContact").width();
	var previewWidthExFAQ = $("#ExternalFAQPreview").width();
	//centering
	$("#previewwebsite").css({
					
						   
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": 25,
		"left": 150+(windowWidth/2-previewWidth/2-150)
	});
	$("#previewwebsite123").css({
					
						   
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": 0,
		"left":(windowWidth/2-previewWidth/2-500)
	});
	$("#previewwebsite143").css({
					
						   
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": 0,
		"left":(windowWidth/2-previewWidth/2-500)
	});
	$("#ssgPopupContact").css({
		"position": "absolute",
		"top": 40, 
		"left": windowWidth/2-ssgPopupWidth/2
	});
		$("#testPopupContact").css({
		"position": "absolute",
		"top": 40, 
		"left": windowWidth/2-testPopupWidth/2
	});
	$("#ExternalFAQPreview").css({
					
						   
		"position": "absolute"
		//"top": windowHeight/2-popupHeight/2,
		//"top": 25
		//"left": 150+(windowWidth/2-previewWidthExFAQ/2-150)
	});
	$(popupId).css({
										   
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": 225,
		"left": windowWidth/2-popupWidth/2
	});
	
	
	$("#flashOverlay").css({
  		"position": "absolute",
 		//"top": windowHeight/2-popupHeight/2,
  		"top": 100,
 		"left": windowWidth/2-popupWidth/2
 	}); 
	
	
	$("#ChangeYourPassword").css({
		"position": "absolute",
		"top": 100, 
		"left": windowWidth/2-popupWidth/2
	});
	$("#popupContactguide").css({
						   
						   
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": 17,
		"left": windowWidth/2-popupWidth/2
	});
	$("#camspanPopUp").css({
										   
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"top": 75,
		
		"left": windowWidth/2-popupWidth/2
	});	
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	$("#backgroundPopup123").css({
		"height": windowHeight
	});
	
	
	//only for FireFox
	$("#backgroundPopup").css({
		"height": windowHeight1
	});
	$("#backgroundPopup123").css({
		"height": windowHeight1
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	
	$(".flashVideo").click(function(){
  flashInit() 
  setPopupId("flashOverlay")
  //centering with css
  centerPopup();
  //load popup
  loadPopup();  
 });
	
	
	
	//LOADING POPUP
	//Click the button event!
	$(".button").click(function(){
		setPopupId("popupContact")
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		
		if(document.getElementById('username') != null) {
			document.getElementById('username').focus()
		}
		//for select disable
		//document.myForm.change.disabled=true;

	});
	$(".button1").click(function(){
		setPopupId("popupContact3")
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		//for select disable
		//document.myForm.change.disabled=true;

	});
	$(".button2").click(function(){
		setPopupId("popupContact4")
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		//for select disable
		//document.myForm.change.disabled=true;
		document.getElementById('username1').focus();

	});
	$(".button3").click(function(){
		setPopupId("popupContact5")
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		//for select disable
		//document.myForm.change.disabled=true;

	});
	$(".loginbutton").click(function(){
		$(".flashDiv").hide();
	    switchid('a1');
		setPopupId("loginPopupContact")//centering with css
		centerPopup();
		//load popup
		loadPopup();
		document.getElementById('loginusername').focus()
		//for select disable
		//document.myForm.change.disabled=true;

	});
		$("#logoutButton").click(function(){
	   // switchid('a1');
		setPopupId("PopupWarning")//centering with css
		centerPopup();
		//load popup
		loadPopup();
		hideListControls();
		//document.getElementById('loginusername').focus()
		//for select disable
		//document.myForm.change.disabled=true;

	});
		$(".alertPoupId").click(function(){
	   // switchid('a1');
		setPopupId("AlertPopup")//centering with css
		centerPopup();
		//load popup
		loadPopup();
		//document.getElementById('loginusername').focus()
		//for select disable
		//document.myForm.change.disabled=true;

	});
	$("#clickHereToChangeYourPassword").click(function(){
	   // switchid('a1');
		setPopupId("ChangeYourPassword")//centering with css
		centerPopup();
		//load popup
		loadPopup();
		hideListControls();
		document.getElementById('currentpassword').focus()
		document.getElementById('currentpassword').value = ''
		document.getElementById('newpassword').value = ''
		document.getElementById('confirmpassword2').value = ''
		$("#success2").removeClass('errorcolor2').text("");
	 	$("#success2").removeClass('successcolor2').text("");
		$("#success").removeClass('errorcolor2').text("");
	 	$("#success").removeClass('successcolor2').text("");
		$("#curpassLabel").removeClass('redcolor');
		$("#newpassLabel").removeClass('redcolor');
		$("#confpassLabel").removeClass('redcolor');
		$("#errorinfo").text("");
		if(errorFlag) {
			errorFlag = false;
		} 
		if(document.getElementById('SaveButtonOn') != null) {
			document.getElementById('SaveButtonOn').style.display='none';
		}
		if(document.getElementById('SaveButtonOff') != null) {
			document.getElementById('SaveButtonOff').style.display='inline';
		}	
		//passwordmatch2();
		//for select disable
		//document.myForm.change.disabled=true;

	});
	$("#SaveButton").click(function(){
	   // switchid('a1');
		setPopupId("ChangeYourPasswordConfirm")//centering with css
		centerPopup();
		//load popup
		//loadPopup();
		hideListControls();
		//document.getElementById('loginusername').focus()
		//for select disable
		//document.myForm.change.disabled=true;

	});

	$(".preview").click(function(){
		//centering with css
		centerPopup();
		loadPreview();
	});
	$("#ExternalFAQ").click(function(){
		//centering with css
		loadPreview();
		centerPopup();
		init();
		document.getElementById('hideDiv').style.display = 'none';
 		document.getElementById('showDiv').style.display = 'block';
	});
	
	$(".preview2").click(function(){
	
		//centering with css
		centerPopup();
		loadPreview();
	});
	$(".guideline").click(function(){
  		setPopupId("popupContactguide")
		//centering with css
		centerPopup();
  		//load popup
  		loadPopup();
  		//for select disable
  		//document.myForm.change.disabled=true;
	 });
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
		//document.getElementById('button').style.display = 'none'
		//for select enable
		//document.myForm.change.disabled=false;
	});
	
	 $("#EmailGuidelines").click(function(){
   
      checkAgree()
	  setPopupId("camspanPopUp")//centering with css
	  centerPopup();
	  //load popup
	  loadPopup();
 	});
	
	
	$("#popupbuttonClose2").click(function(){
		disablePopup();
	});
	$("#popupbuttonClose").click(function(){
	
	$(".flashDiv").show();
		disablePopup();
	});
	$("#popupbuttonClose3").click(function(){
		disablePopup();
	});
	$("#popupbuttonClose4").click(function(){
		disablePopup();
	});
	$("#popupbuttonClose5").click(function(){
		disablePopup();
	});
	$("#popupbuttonClose").click(function(){
		disablePopup();
	});
	$(".popupcloseButton").click(function(){
		disablePopup();
	});
	
	$("#btnSubmit").click(function(){
		disablePopup();
		//document.getElementById('button').style.display = 'none'
		//for select enable
		//document.myForm.change.disabled=false;
	});
	
	$(".popupClose").click(function(){
  		disablePopup();
 	});
 	
 	$("#popupbuttonCloseFlash").click(function(){
   		disablePopup();
 	});
 	
	
	//Click out event!
	//$("#backgroundPopup").click(function(){
		//disablePopup();
	//});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			$(".flashDiv").show();
			disablePopup();
		}
	});
	
});

