﻿/***************************/
//@Author: Zulfaqar Naqvi
//@website: www.seisoms.com
//@email: zulfiqar.naqvi@seismologyonline.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var currentEnableDiv = "";

var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}


//loading popup with jQuery magic!
function loadPopup(divId){
	//loads popup only if it is disabled
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
        if (Browser.Version() < 7) {
		hideSelectBoxes();
		}
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery(divId).fadeIn("slow");
		popupStatus = 1;
		
	}
}

//disabling popup with jQuery magic!
function disablePopup(divId){
	//disables popup only if it is enabled
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery(divId).fadeOut("slow");
		popupStatus = 0;
		showSelectBoxes();
		try{document.getElementById('headerimg').style.display='block';}catch(exx){}
	}
}

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}



function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


//centering popup
function centerPopup(divId){
	//request data for centering
	var windowWidth = document.documentElement.scrollWidth;
	var windowHeight = document.documentElement.scrollHeight;
	var popupHeight = jQuery(divId).height();
	var popupWidth = jQuery(divId).width();
	var top = 0;
	
	var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
	top = arrayPageScroll[1] + (arrayPageSize[3] / 15);
		
	//centering
	jQuery(divId).css({
		"position": "absolute",
		"top": top,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight,
		"width": windowWidth
	});
	
}


jQuery(document).ready(function(){
	
	//LOADING POPUP
	jQuery("#mySavedSearchesHref").click(function(){
		//centering with css
		centerPopup("#MyAccountSignIn");
		//load popup
		loadPopup("#MyAccountSignIn");
		
		currentEnableDiv = "#MyAccountSignIn";
		
	});
	
		//LOADING POPUP 
	jQuery("#mySavedSearchesHref1").click(function(){
		//centering with css
		centerPopup("#MyAccountSignIn");
		//load popup
		loadPopup("#MyAccountSignIn");
		currentEnableDiv = "#MyAccountSignIn";
	});
	
	jQuery(".starAnchor").click(function(){
		//centering with css
		centerPopup("#MyAccountSignIn");
		//load popup
		loadPopup("#MyAccountSignIn");
		currentEnableDiv = "#MyAccountSignIn";
	});
	
	
	//LOADING POPUP
	jQuery("#mySavedSearches").click(function(){
		//centering with css
		centerPopup("#AddToMySavedSearches");
		//load popup
		loadPopup("#AddToMySavedSearches");
		currentEnableDiv = "#AddToMySavedSearches";
	});
	
		//LOADING POPUP
	jQuery("#mySavedSearches1").click(function(){
		//centering with css
		centerPopup("#AddToMySavedSearches");
		//load popup
		loadPopup("#AddToMySavedSearches");
		currentEnableDiv = "#AddToMySavedSearches";
	});
	
	
	jQuery("#ForgotPassword").click(function(){
		//centering with css
		try{
		document.getElementById("MyAccountSignIn").style.display = "none";
		}catch(err){}
		centerPopup("#MyAccountForgotPassword");
		//load popup
		popupStatus = 0;
		loadPopup("#MyAccountForgotPassword");
		currentEnableDiv = "#MyAccountForgotPassword";
	});
	
		jQuery("#ForgotPasswordMain").click(function(){
		//centering with css
		try{
		document.getElementById("MyAccountSignIn").style.display = "none";
		}catch(err){}
		centerPopup("#MyAccountForgotPassword");
		//load popup
		popupStatus = 0;
		loadPopup("#MyAccountForgotPassword");
		currentEnableDiv = "#MyAccountForgotPassword";
	});
		jQuery("#signUp").click(function(){
		//centering with css
		try{
		document.getElementById("MyAccountSignIn").style.display = "none";
		}catch(err){}
		centerPopup("#MyAccountSignUp");
		//load popup
		popupStatus = 0;
		loadPopup("#MyAccountSignUp");
		currentEnableDiv = "#MyAccountSignUp";
	});
	
		jQuery("#signUpMain").click(function(){
		//centering with css
		try{
		document.getElementById("MyAccountSignIn").style.display = "none";
		}catch(err){}
		centerPopup("#MyAccountSignUp");
		//load popup
		popupStatus = 0;
		loadPopup("#MyAccountSignUp");
		currentEnableDiv = "#MyAccountSignUp";
	});
	
	
	
	//CLOSING POPUP
	//Click the x event!
	jQuery("#MyAccountSignInClose").click(function(){
		if(document.getElementById("MyAccountSignIn").style.display == "block")
		{
		    disablePopup("#MyAccountSignIn");
		    currentEnableDiv = "";
		}
	});
	jQuery("#MyAccountForgotPasswordClose").click(function(){
		if(document.getElementById("MyAccountForgotPassword").style.display == "block")
		{
		    disablePopup("#MyAccountForgotPassword");
		    currentEnableDiv = "";
		}
	});
	jQuery("#MyAccountSignUpClose").click(function(){
		if(document.getElementById("MyAccountSignUp").style.display == "block")
		{
		    disablePopup("#MyAccountSignUp");
		    currentEnableDiv = "";
		}
	});
	//Click out event!
	jQuery("#backgroundPopup").click(function(){
		    disablePopup(currentEnableDiv);
	});
	//Press Escape event!
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
		    disablePopup(currentEnableDiv);
		}
	});

});