// JavaScript Document
var xmlhttp;
function AjaxUserRegister(url) 
{ 
document.getElementById('spError').innerHTML ="<img src='http://www.tomasha.com/images/loading.gif' title='Working' />";
	//if there is already a live request, cancel it
	if (xmlhttp!=null)
	{
		if (xmlhttp.readyState != 0)
			xmlhttp.abort();
		xmlhttp = null;
	}
	//alert(url);
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange=AjaxResponse;
		xmlhttp.open("GET",url,false);
		
		xmlhttp.send(null);
	}
	//code for IE
	else if (window.ActiveXObject)
	{
		try
		{
		  xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){}
		}
	
		if(xmlhttp)
		{
			try
			{
			//xmlhttp.onreadystatechange=Find;
			xmlhttp.open("GET",url,false);
			xmlhttp.send();
			}
			catch(e){}
		}
	}
	// Create a function that will receive data sent from the server
	//document.getElementById('spError').innerHTML ="Please Wait...";
	xmlhttp.onreadystatechange =AjaxResponse;
	//document.getElementById('spError').innerHTML ="";
	//document.getElementById('spError').innerHTML ="<img src='http://www.tomasha.com/images/loading.gif' title='Working' />";
	
	
	
}
function AjaxResponse()
{
	
	if(xmlhttp.readyState == 4)
	{
		//alert(xmlhttp.readyState);
		if(xmlhttp.responseText=="true")
		{
			document.getElementById('spError').innerHTML = "";
			$(document).ready(function(){	
				$(".thank").colorbox({
				width:"600px",
				inline:true, 
				href:"#form_2",
				opacity:.40,
				transition:"none",
				height:"462px",
				overlayClose:false,
				open:true,
				onComplete:function(){ 
				setTimeout($.fn.colorbox.close,3000); 
			
				 },
				onClosed:function(){ location.reload(true); } 
				});
			});	
		}
		else
		{
			//alert(xmlhttp.responseText);
			document.getElementById('spError').innerHTML =  xmlhttp.responseText;
		}
	}
}
function validateForm_popup()
{
	var Flag=true;
	var Err="There are following issues in form input:<br/>";
	  
	if (document.forms["login"]["txtemail"].value==null || document.forms["login"]["txtemail"].value=="")
	{
		Err	+="-> Please Provide Email.<br/>";
		Flag=false;
	}
	else
	{
		if(EmailValidate(document.forms["login"]["txtemail"].value)==false)
		{
			Err	+="-> Please Provide Valid Email.<br/>";
			Flag=false;
		}
	}
	if (document.forms["login"]["txtpassword"].value==null || document.forms["login"]["txtpassword"].value=="")
	{
		Err	+="-> Please Provide Password <br/>";
		Flag=false;
	}
	if (document.forms["login"]["txtfname"].value==null || document.forms["login"]["txtfname"].value=="")
	{
		Err	+="-> Please Provide First Name <br/>";
		Flag=false;
	}
	if (document.forms["login"]["txtlname"].value==null || document.forms["login"]["txtlname"].value=="")
	{
		Err	+="-> Please Provide Last Name <br/>";
		Flag=false;
	}
	var index=document.forms["login"]["txtdobday"].selectedIndex;
	if(document.forms["login"]["txtdobday"].options[index].value=="Select")
	{
		Err	+="-> Select Valid Birth Day <br/>";
		Flag=false;
	}
	var index=document.forms["login"]["txtdobmonth"].selectedIndex;
	if(document.forms["login"]["txtdobmonth"].options[index].value=="Select")
	{
		Err	+="-> Select Valid Birth Month <br/>";
		Flag=false;
	}
	var index=document.forms["login"]["txtdobyear"].selectedIndex;
	if(document.forms["login"]["txtdobyear"].options[index].value=="Select")
	{
		Err	+="-> Select Valid Birth Year <br/>";
		Flag=false;
	}
	var index=document.forms["login"]["txtgender"].selectedIndex;
	if(document.forms["login"]["txtgender"].options[index].value=="Select")
	{
		Err	+="-> Select Valid Gender <br/>";
		Flag=false;
	}
	if(Flag==false)
	{
		
		document.getElementById('spError').innerHTML = Err;
	}
	else
	{
		document.getElementById('spError').innerHTML = "";
		var url="http://www.tomasha.com/AjaxUserRegister.php?";
		 	url+="txtemail="+document.forms["login"]["txtemail"].value + "&" ;
			url+="txtpassword="+document.forms["login"]["txtpassword"].value + "&" ;
			url+="txtfname="+document.forms["login"]["txtfname"].value + "&" ;
			url+="txtlname="+document.forms["login"]["txtlname"].value + "&" ;
			url+="txtdobday="+document.forms["login"]["txtdobday"].value  + "&" ;
			url+="txtdobmonth="+document.forms["login"]["txtdobmonth"].value  + "&" ;
			url+="txtdobyear="+document.forms["login"]["txtdobyear"].value + "&" ;
			url+="txtgender="+document.forms["login"]["txtgender"].value + "&" ;
			//alert(url);
		AjaxUserRegister(url);
	}
	
	return Flag;
}
function EmailValidate(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
 //  var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      //alert('Invalid Email Address');
      return false;
   }
   else
   {
   	return true;
   }
}
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function loopSelected(name,val)
{
	var selObj = document.forms["login"][name];
	var i=0;
	for (i=0; i<selObj.options.length; i++) 
	{
		if (selObj.options[i].value==val) 
		{
			selObj.options[i].selected=true;
		}
	}
}
