// JavaScript Document




/*########### #############  Function for creating Global Object  #############  #############*/

function GetXmlHttpObject()
{

var xmlHttp;
	try	 // Firefox, Opera 8.0+, Safari
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)   // Internet Explorer
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return(xmlHttp);
}



function login()
{
	var email = document.getElementById("email").value;
	var password = document.getElementById("password").value;
	var msg = "";
	if((email == "")||(password == ""))
	{
		if(email == "")
		{
			msg = "Email ";
		}
		if(password == "")
		{
			if(msg!="")
			{
				msg += " & ";
			}
			msg += "Password";
		}
		document.getElementById("err").innerHTML= "&nbsp;" + msg + " required.";
		return false;
	}
	return true;
}



function isEmailAddr(uemail)
{ 

	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
	if (!filter.test(uemail))
	{
		
	return false;
	}
	
return true;
	/*var result = false;
    var theStr = new String(uemail);
    var index = theStr.indexOf("@");
    if (index > 0)
    {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
 return result;*/
}


function valid()
{  
	var uname = document.getElementById("name").value;
	var email = document.getElementById("emailid").value;
	var msg= "!! Please Confirm !!<br>";
	validity = true;  
	if(uname == "")
	{
		validity = false;
		msg += "<BR>" + "Empty Name.";
	}
	if(email == "")
	{
		validity = false;
		msg += "<BR>" + "Empty Email Id.";
		
	}	
	else if(!isEmailAddr(email))
	{
		validity = false;
		msg += "<BR>" + "Please enter email address as: <B>yourname@yourdomain.com</B>";
	}
		document.getElementById("abc").innerHTML= msg;
		return validity;
}

function reg_valid()
{  
	var name = document.getElementById("name").value;
	var password = document.getElementById("password").value;
	var c_password = document.getElementById("confirm").value;
	var email = document.getElementById("email").value;
	var msg= "";
	validity = true;  
	if(name == "")
	{
		validity = false;
		msg += "<BR>" + "Empty Name.";
	}
	if(password == "")
	{
		validity = false;
		msg += "<BR>" + "Empty Password.";
	}
	else if(password.length < 6)
	{
		validity = false;
		msg += "<BR>" + "Password must be greater than 6 char.";
	}
	if(c_password == "")
	{
		validity = false;
		msg += "<BR>" + "Empty Confirm Password.";
	}
	else if(password != c_password)
	{
		validity = false;
		msg += "<BR>" + "Please confirm password";			
	}
	if(email == "")
	{
		validity = false;
		msg += "<BR>" + "Empty Email Id.";
		
	}	
	else if(!isEmailAddr(email))
	{
		validity = false;
		msg += "<BR>" + "Please enter email address as: <B>yourname@yourdomain.com</B>";
	}
		document.getElementById("err").innerHTML= msg;
		return validity;
}

function checkemail()
{
	var email = document.getElementById("email").value;
	var msg= "";
	validity = true; 
	if(email == "")
	{
		validity = false;
		msg += "<BR>" + "Please enter email Id.";
	}
	else if(!isEmailAddr(email))
	{
		validity = false;
		msg += "<BR>" + "Please enter email address as: <B>yourname@yourdomain.com</B>";
	}
		document.getElementById("err").innerHTML= msg;
		return validity;
}


function image_display(a)
{
	
	document.getElementById("main_image").innerHTML='<img src="'+a+ '?>" width="126" height="169">';
	
}

function valid_game()
{
	var name = document.getElementById("name").value;
	var desc = document.getElementById("desc").value;
	var email = document.getElementById("alt_email").value;
	var msg= "";
	validity = true; 
	if(name == "")
	{
		validity = false;
		msg += "<BR>" + "Please enter name of the Game.";
		//alert(msg);
	}
	if(desc == "")
	{
		validity = false;
		msg += "<BR>" + "Please enter description.";
		//alert(msg);
	}
	if(email == "")
	{
		validity = true;
	}
	else if(email)
	{
		if(!isEmailAddr(email))
		{
		validity = false;
		msg += "<BR>" + "Please enter email address as: <B>yourname@yourdomain.com</B>";
		//alert(msg);
		}
	}
		document.getElementById("err").innerHTML= msg;
		return validity;

}

function hits(action,product_id,file)
{
	//alert("hits");
	id=product_id;
	url= "./redirect.php?act=" + action + "&product_id=" + product_id;
	//alert(url);
	perform(url,file);
}

function perform(url,file)
{	//alert("perform");
	xmlHttp=GetXmlHttpObject();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange =function()
	{ //alert(xmlHttp.readyState);
		if (xmlHttp.readyState == 4)
		{
			var response = xmlHttp.responseText;			
			//alert("response = "+response);
			//document.getElementById("1").innerHTML= response;
			window.location = file;
			//alert(page);
		}
	}
	xmlHttp.send(null);	
	
}


