var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
}

function ValidateUsername(user,id)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=UsernameValidation&name=" + user + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  document.getElementById(id).innerHTML = http.responseText;
	  }
  }
  http.send(null);
}
function ValidatePassword(pass,id)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=PasswordValidation&password=" + pass + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  document.getElementById(id).innerHTML = http.responseText;
	  }
  }
  http.send(null);
}
function ValidateEmail(email,id,fieldid)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=NewsletterValidation&email=" + email + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="No")
		  {
				document.getElementById(id).innerHTML = "You already subscribed.";
				alert("You already subscribed.");
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
	  }
  }
  http.send(null);
}
function InsertNesletterEmail(email,id,fieldid)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=Add_Newsletter&email=" + email + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="Added")
		  {
				document.getElementById(id).innerHTML = "Thank you for subscribing.";
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
	  }
  }
  http.send(null);
}
function AddProduct(allfield,id,fieldid)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=Add_Product&email=" + allfield + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="Added")
		  {
				document.getElementById(id).innerHTML = "Thank you for subscribing.";
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
	  }
  }
  http.send(null);
}
/////////////////ADD TO CART PRODUCT/////////////
function AddtocartProduct(productid,quantity,id,fieldid,OrderImageId)
{
	//alert(id);
  http.abort();
  http.open("GET", "ajax_validation.php?Type=Addtocart_Product&productid=" + productid + "&quantity=" + quantity + "&id=" + id, true);
  document.getElementById(id).innerHTML = "<img src='images/loading_small.gif' border='0' align='center' />";
  document.getElementById(OrderImageId).innerHTML = "<img src='images/loading_small.gif' border='0' align='center' />";
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
			document.getElementById(id).innerHTML = http.responseText;
	  }
  }
  http.send(null);
}
/////////////////END ADD TO CART PRODUCT/////////////
function FrmCheckAddtoCart(Productid,CartDisplayId,OrderImageId)
{
	AddtocartProduct(Productid,1,CartDisplayId,'newsletteremail',OrderImageId);
	document.getElementById(OrderImageId).innerHTML="<span class=\"red_20\"><img src=\"images/added.jpg\" alt=\"Added\" width=\"94\" height=\"31\" border=\"0\" align=\"middle\"/></span>";
	return true;
}
///Check top login detail
function CheckTopLoginDetail(email,password,id,chkmem)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=TopLoginValidation&email=" + email + "&password=" + password + "&chkmem=" + chkmem +  "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  if(http.responseText=="Yes")
		  {
		  		window.location.href='myaccount.php';
		  }
		  else
		  {
				document.getElementById(id).innerHTML = "Invalid login detail.";
		  }
	  }
  }
  http.send(null);
}
function CheckTopLoginDetail_Support(email,password,id)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=TopLoginValidation&email=" + email + "&password=" + password + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  if(http.responseText=="Yes")
		  {
		  		window.location.href='supportnen.php';
		  }
		  else
		  {
				document.getElementById(id).innerHTML = "Invalid login detail.";
		  }
	  }
  }
  http.send(null);
}
///End of Check top login detail

///////Registration Process email address exist checking
function ValidateEmail_Register(email,id,fieldid)
{
  http.abort();
  
  http.open("GET", "ajax_validation.php?Type=ValidateEmail_Register&email=" + email + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		
		  if(http.responseText=="No")
		  {
				document.getElementById(id).innerHTML = "Email address already exists.";
				//alert("Email address already exists.");
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
	  }
  }
  http.send(null);
}
function ValidateUserName_Register(email,id,fieldid)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=ValidateUserName_Register&email=" + email + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="No")
		  {
				
				document.getElementById(id).innerHTML = "Username already exists.";
				//alert("Email address already exists.");
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
	  }
  }
  http.send(null);
}

function ValidatePuburl_Register(puburl,id,fieldid)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=ValidatePuburl_Register&puburl=" + puburl + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="No")
		  {
				
				document.getElementById(id).innerHTML = "Public URL already exists.";
				//alert("Email address already exists.");
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
	  }
  }
  http.send(null);
}
///////Registration Process email address exist checking
function ValidateEmail_Register_Edit(email,id,fieldid,Editid)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=ValidateEmail_Register_Edit&email=" + email + "&Editid=" + Editid + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="No")
		  {
				document.getElementById(id).innerHTML = "Email address already exists.";
				//alert("Email address already exists.");
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
		  else
		  {
			  document.getElementById(id).innerHTML = "&nbsp;";
		  }
	  }
  }
  http.send(null);
}
///////Registration Process email address exist checking

///////Registration Detail adding
function InsertRegistrationDetail(username,password,contact_name,billing_name,email,billing_address1,billing_address2,billing_city,billing_country,billing_state,billing_zip,phone1,phone2,fax,id)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=InsertRegistrationDetail&username=" + username + "&password=" + password + "&contact_name=" + contact_name + "&billing_name=" + billing_name + "&email=" + email + "&billing_address1=" + billing_address1 + "&billing_address2=" + billing_address2 + "&billing_city=" + billing_city + "&billing_country=" + billing_country + "&billing_state=" + billing_state + "&billing_zip=" + billing_zip + "&phone1=" + phone1 + "&phone2=" + phone2 + "&fax=" + fax + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="Added")
		  {
				document.getElementById(id).innerHTML = "Thankyou for subscribing.";
				document.FrmRegister.reset();
		  }
	  }
  }
  http.send(null);
}

/////////Check Forgot pass email
function Forgotpassemail_check(email,id,fieldid)
{
  http.abort();
  http.open("GET", "ajax_validation.php?Type=Forgotpassemail_check&email=" + email + "&id=" + id, true);
  http.onreadystatechange=function()
  {
	  if(http.readyState == 4)
	  {
		  //document.getElementById(id).innerHTML = http.responseText;
		  if(http.responseText=="No")
		  {
				document.getElementById(id).innerHTML = "Email address does not exists.";
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
		  if(http.responseText=="Yes")
		  {
				document.getElementById(id).innerHTML = "Password has been sent at your email address.<br>Please check your mail.";
				document.getElementById(fieldid).value="";
				document.getElementById(fieldid).focus();
		  }
	  }
  }
  http.send(null);
}
///////Registration Process email address exist checking