// JavaScript Document
function product_upload_validate()
{
	
// Validation for category
 if(document.product_upload.category.value == 0)
 {
 alert("Select Category ");
 document.product_upload.category.focus();
 return false;
   //document.getElementById("textValue").innerHTML="This is innerHTML text";
 }
 
 // Validation for Product of the comapny
 if(document.product_upload.prodcompany.value == 0)
 {
 alert("Select Product of the comapny ");
 document.product_upload.prodcompany.focus();
 return false;
 }
 
 // Validation for Vehicle company name
  if(document.product_upload.compvehicle.value ==0)
 {
 alert("Select Vehicle company name");
 document.product_upload.compvehicle.focus();
 return false;
 }
 
 // Validation for Model
  if(document.product_upload.modelof.value ==0)
 {
 alert("Select model");
 document.product_upload.modelof.focus();
 return false;
 }
 
 // Validation for Product Name
 if(document.product_upload.productname.value == "")
 {
 alert("Enter product name");
 document.product_upload.productname.focus();
 return false;
 }
 
 // Validation for Part No
 if(document.product_upload.partno.value=="")
 {
 alert("Enter part no");
 document.product_upload.partno.focus();
 return false;
 }
 
 if(document.product_upload.uploadedfile1.value=="")
 {
 alert("Upload small image ");
 document.product_upload.uploadedfile1.focus();
 return false;
 }
 if(document.product_upload.uploadedfile2.value=="")
 {
 alert("Upload large image ");
 document.product_upload.uploadedfile2.focus();
 return false;
 }
 
  // Validation for Methods Part No
 if(document.product_upload.methodspartno.value==false)
 {
 alert("Enter method's part no");
 document.product_upload.methodspartno.focus();
 return false;
 }
 
 // Validation for Price
 if(document.product_upload.price.value == "")
 {
 alert("Enter price");
 document.product_upload.price.focus();
 return false;
 }
 
 // Validation for Prica Numaric
 if(isNaN(document.product_upload.price.value)==true)
 {
 alert("Enter numaric value for price");
 document.product_upload.price.value="";
 document.product_upload.price.focus();
 return false;
 }
 
 // Validation for Short Description
 if(document.product_upload.shortdesc.value== "")
 {
 alert("Enter short description");
 document.product_upload.shortdesc.focus();
 return false;
 }
 
 // Validation for Long Description
 if(document.product_upload.longdesc.value=="")
 {
 alert("Enter long description");
 document.product_upload.longdesc.focus();
 return false;
 }
 
 // Validation for Product Stock
 if(document.product_upload.productstockqty.value=="")
 {
 alert("Enter product stock");
 document.product_upload.productstockqty.focus();
 return false;
 }
 
 // Validation for Product Stock Quantity Numaric
 if(isNaN(document.product_upload.productstockqty.value)==true)
 {
 alert("Enter numaric value for product stock quantity");
 document.product_upload.productstockqty.value="";
 document.product_upload.productstockqty.focus();
 return false;
 }
}

function valid_show_button()
{
	var category=document.product_upload.category.value;
	var prodcompany=document.product_upload.prodcompany.value;
	
	// Validation for category
 if(category == 0 && prodcompany==0)
 {
	 alert("Select at least one criteria");
	 document.product_upload.category.focus();
	 return false;
 }

}

function product_upload2()
	{
		
		var frm;
		frm = document.prod_upload2;
		
		if(frm.category.value == 0)
		{
			alert("Select the Category");
			frm.category.focus();
			return false;
		}
		if(frm.prodcompany.value == 0)
		{
			alert("Select Product of the comapny");
			frm.prodcompany.focus();
			return false;
		}
		if(frm.productname.value == "")
		{
			alert("Enter Product name");
			frm.productname.focus();
			return false;
		}
		if(frm.partno.value == "")
		{
			alert("Enter Part no");
			frm.partno.focus();
			return false;
		}
		/*if(frm.methodspartno.value == "")
		{
			alert("Enter Methods Part no");
			frm.methodspartno.focus();
			return false;
		}*/
		if(frm.uploadedfile1.value == "")
		{
			alert("Upload Product small image");
			frm.uploadedfile1.focus();
			return false;
		}
		if(frm.uploadedfile2.value == "")
		{
			alert("Upload Product big image");
			frm.uploadedfile2.focus();
			return false;
		}
		if(frm.price.value == "")
		{
			alert("Enter Price");
			frm.price.focus();
			return false;
		}
		if(isNaN(frm.price.value)==true)
		 {
		 alert("Enter numaric");
		 frm.price.value="";
		 frm.price.focus();
		 return false;
		 }
 
		if(frm.shortdesc.value == "")
		{
			alert("Enter Short description");
			frm.shortdesc.focus();
			return false;
		}
		if(frm.productstockqty.value == "")
		{
			alert("Enter Product Stock Quantity");
			frm.productstockqty.focus();
			return false;
		}
		if(isNaN(frm.productstockqty.value)==true)
		 {
		 alert("Enter numaric");
		 frm.productstockqty.value="";
		 frm.productstockqty.focus();
		 return false;
		 }
		
	}

var xmlhttp

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		 return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	  }
		return null;
}

function AddToWishList(prod_id)
{
	
	xmlhttp = GetXmlHttpObject();
	
	if (xmlhttp == null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  }
	var url="pagecontrols/add_wishlist.php";
	url=url+"?prod_id="+prod_id;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged1;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);  
}

function stateChanged1()
{
	  if (xmlhttp.readyState == 4)
	  {
	 	if(xmlhttp.responseText != "")
			 alert(xmlhttp.responseText);
		//document.getElementById("txtProduct").innerHTML=xmlhttp.responseText;
	  }
}

function DeleteWishlist(p_id)
{
	//alert(cat_id);
	if(confirm("Do you really want to delete"))
	{
		xmlhttp=GetXmlHttpObject();
		  
		  if (xmlhttp==null)
		  {
			  alert ("Your browser does not support AJAX!");
			  return;
	  	  }
	  
	//var url="pagecontrols/header_password_chacker.php";
	url="pagecontrols/add_wishlist.php";
	url=url+"?p_id="+p_id;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=DeletedStatus;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	}
	else
	{
		return false;
	}	
}

function DeletedStatus()
{
	if (xmlhttp.readyState==4)
  {
	location.reload(true);
 	document.getElementById("cartMsg").innerHTML=xmlhttp.responseText;
  }
}
