﻿//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 windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	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({
		"height": windowHeight
	});
	
}

function submit_click(action){
  //alert(action);

  if(document.getElementById('txtname').value == '')
  {
	  alert("Please enter name.");
	  document.getElementById('txtname').focus();
	  return false;
  }
	
 // if(document.getElementById('txtemail').value == '')
//  {
//	  alert("Please enter email.");
//	  document.getElementById('txtemail').focus();
//	  return false;
//  }
//  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('txtemail').value)))
//  {
//	  alert("Please enter valid email address.")
//	  document.getElementById('txtemail').focus();
//	  return (false)
//  }

  if(document.getElementById('txtphone').value == '')
  {
	  alert("Please enter phone.");
	  document.getElementById('txtphone').focus();
	  return false;
  }
  else if (ChkNumeric(document.getElementById('txtphone').value) == false) 
  {
      alert("Please enter valid phone number");
	  document.getElementById('txtphone').focus();
	  return false;
  }
  else
  {
		if(document.getElementById('txtphone').value.length < 10)
	   {
		  alert("Please enter atleast 10 digits for phone number.");
		  document.getElementById('txtphone').focus();
		  return false;
	   }
  }
  if(document.getElementById('txtcity').value == '')
  {
	  alert("Please enter city.");
	  document.getElementById('txtcity').focus();
	  return false;
  }
  if(document.getElementById('country').value == 0)
  {
	  alert("Please select country.");
	  document.getElementById('country').focus();
	  return false;
  }
	

  $.post(action, { name: $('#txtname').val(), email: $('#txtemail').val(), phone: $('#txtphone').val(), country: $('#country').val(), city: $('#txtcity').val() }, function(data){
  //alert("Data Loaded: " + data);
});
  disablePopup();
}

//====================================================================================================
//	Function Name	:	IsNumeric(event)
//----------------------------------------------------------------------------------------------------
function IsNumeric(event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	return ((keyCode == 8) // backspace
		//|| (keyCode == 43) // +
		|| (keyCode == 45) // -
        || (keyCode == 37) // left arrow
        || (keyCode == 39) // right arrow
        || (keyCode == 46) // delete
		|| (keyCode == 9)  // tab
        || ((keyCode > 47) && (keyCode < 58)) // 0 - 9
   );
}

function ChkNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

