/***************************/
//@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){
		/*$("#backgroundPopup").css({
			"opacity": "0.7"
		});*/
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").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");    
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var arrayPageSize = getPageSize();
	var windowWidth = screen.width;
	var windowHeight = screen.height;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
	    "position": "absolute",						  
		"width": arrayPageSize[0],					  
		"height": arrayPageSize[1],		
		"-moz-opacity": "0.5",
		"opacity": "0.5"
	});
	
}
	function validateform()
	{
	var str=trim(document.getElementById("email").value);
	var filter=/^.+@.+\..{2,3}$/;
	var rer = /^[0-9]+$/;
	var strr = document.getElementById('phone').value;
	
	var re = /^[A-Z]+$/;
	
	if(trim(document.getElementById('name').value)=="")
	{
		alert("Please enter your name!!!");
		document.getElementById('name').focus();
		return false;
	}
	if(document.getElementById('phone').value=="")
	{
		alert("Please enter your mobile number!!!");
		document.getElementById('phone').focus();
		return false;
	}
	else if(!rer.test(strr))
  	{
	  alert("Please input a valid mobile numbers!");
	  document.getElementById("phone").focus();
	  return false;
  	}
	
	if(trim(document.getElementById('email').value)=="")
	{
		alert("Please Enter Email Id");
		document.getElementById('email').focus();
		return false;
	}
	else if(!filter.test(str))
  	{
	  alert("Please input a valid email address!");
	  document.getElementById("email").focus();
	  return false;
  	}
	
	if(document.getElementById('comments').value=="")
	{
		alert("Please enter your comment!!!");
		document.getElementById('comments').focus();
		return false;
	}
}
	  function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			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
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				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 = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
	
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
		
	
		
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});


});

