﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.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;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//checking for the cookies
function retrive_cookie(cookie_name)
{
  var results = document.cookie.match ('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

  if (results)
    return (unescape(results[2]));
  else
    return null;
}


//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	
	var uname = retrive_cookie("usrname");
	var pwd = retrive_cookie("pwd");
	
	

	if(uname !=''){
  	 document.getElementById("user_id").innerHTML = uname;
	 document.getElementById("pwd").innerHTML = pwd;
	} else{
	document.getElementById('user_id').value="";
	document.getElementById('pwd').value="";
	document.getElementById('user_id1').value="";
	document.getElementById('pwd1').value="";
	}
	document.getElementById('loginform').style.display="block";
	document.getElementById('login_error_form').style.display="none";
	document.getElementById('forgot').style.display="none";
	document.getElementById('forgot_new').style.display="none";
	document.getElementById('forgot_success').style.display="none";
	
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupContact").height();
	var popupWidth = jQuery("#popupContact").width();
	//centering
	jQuery("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"z-index": "9999999"
	});
	//only need force for IE6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight,
		"z-index": "999999"
	});
	
}

//Generating the popup for the members section
function associatedmember(id)
{
   
   var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#memberpopupContact"+id).height();
	var popupWidth = jQuery("#memberpopupContact"+id).width();
	//centering
	$("#memberpopupContact"+id).css({
		"position": "absolute",
		"display":"block",
		"width":"907px",
		"margin-left":"-263px",
		"float":"left",
		//"margin-left":"23px",
		"top": windowHeight/2-popupHeight/2,
		//"left": windowWidth/2-popupWidth/2,
		"margin-top":"429px",
		"z-index": "99999"
	});
	
		
		
	//only need force for IE6
	
	$("#memberdirPopup"+id).css({
		"height": windowHeight,
		"z-index": "-999999"
	});
   
   
   
}


//disabling popup for the menu section
function disableMemberpopup(id){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#memberdirPopup"+id).fadeOut("slow");
		$("#memberpopupContact"+id).fadeOut("slow");
		popupStatus = 0;
	}
}

//used to load popup for the members section
function memberDetailPopup(id){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#memberdirPopup"+id).css({
			"opacity": "0.7"
		});
		$("#memberdirPopup"+id).fadeIn("slow");
		$("#MemberpopupContact"+id).fadeIn("slow");
		popupStatus = 1;
	}
}





//CONTROLLING EVENTS IN jQuery
jQuery(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	jQuery("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	jQuery("#button1").click(function(){
		//centering with css
	 /* if($("#popupContact :visible"))	
		$(document).keypress(function(e){
			alert("performing");
			 switch(e.which)
			 {
				case 13: UserLoginValid();					
				break;
			 }
			 			 
		});
*/
 
		centerPopup();
		//load popup
		loadPopup();
	});
	jQuery("#button2").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	jQuery("#button3").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	jQuery("#popupContactClose").click(function(){
		disablePopup();
	});
	jQuery("#popupContactClose1").click(function(){
		disablePopup();
	});
	jQuery("#popupContactClose2").click(function(){
		disablePopup();
	});
	jQuery("#popupContactClose3").click(function(){
		disablePopup();
	});
	jQuery("#popupContactClose4").click(function(){
		disablePopup();
	});
	jQuery("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Click out event!
	jQuery("#backgroundPopup").click(function(){
	disablePopup();//none();
	});
	//Press Escape event!
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			return;
		}
		/*Used for the enter keypress event*/
		if(e.keyCode==13 && popupStatus==1){
			if ($("#user_id").is(":visible")) {
				UserLoginValid($("#user_id").val(), $("#pwd").val());
				return;
			}
			
			if ($("#user_id1").is(":visible")) {
				UserLoginValid($("#user_id1").val(), $("#pwd1").val());
				return;
			}
			
			if ($("#user_id1011").is(":visible")) {
				UserLoginValid($("#user_id1011").val(), $("#pwd1011").val());
				return;
			}
		}
	});

});
