// JavaScript Document
		function LTrim(str) 
		{
			for (var k=0; k<str.length && str.charAt(k)<=" " ; k++) ;
			return str.substring(k,str.length);
		}
		function RTrim(str) 
		{
			for (var j=str.length-1; j>=0 && str.charAt(j)<=" " ; j--) ;
			return str.substring(0,j+1);
		}
		function Trim(str)
		{
			return LTrim(RTrim(str));
		}
function validate()

{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	/*if(document.getElementById('email').value.length==0)
	
	alert("Enter Email Address");
	
	else if(document.getElementById('pwd').value.length==0)
	
	alert("Enter Password");*/
		
	var lemail=Trim(document.loginform.email.value);
	var fpwd=Trim(document.loginform.pwd.value);
	if(lemail == "")
	{
		alert("Enter Email Address.");		
		document.loginform.email.focus();   	
		return false;		
	}	
	if (!filter.test(lemail)) 	
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com.");
		document.loginform.email.focus();	   			
		return false;
	}
	else if(document.loginform.pwd.value=="")
	{
		alert ("Enter Password");
		document.loginform.pwd.focus();	   			
		return false;	
	}
	
	
	document.loginform.action="page.php";
	//alert(document.loginform.action);
	//document.loginform.submit();
}

function category_validate(type,val)
{
	//alert(type);
		
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(type!="delete")
		{
			var page=document.category.page.value;
			var catname=Trim(document.category.category.value);
			if(catname == "")
			{
				alert("Enter Category Name.");		
				document.category.category.focus();   	
				return false;		
			}	


			var category = document.category.category.value;
			var catid = document.category.catid.value;
			//alert(catid);
							 
				  if(category!="")
				  {
					 
						
							var url = "category1_checkexists.php?category="+category+"&type="+type+"&cid="+catid;
							//alert(url);
							
							if(window.XMLHttpRequest) // Mozilla
							{
									objXMLHTTP = new XMLHttpRequest();
							}
							else if(window.ActiveXObject) // IE
							{
									objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
							}
							objXMLHTTP.open("POST",url,false);
							objXMLHTTP.send("");
							data = objXMLHTTP.responseText;
							
							//alert(data);
							
							if(data != 0)
							{
								  alert ("Category already exists.");
								 // document.clist.catid.focus();
								  return false;
							}
					 }  
			

			document.category.action="category_list.php?type="+type+"&page="+page;
		}

	if(type == "delete")
	{

		catid=val;
							 
				  if(catid!="")
				  {
					 
						
							var url = "category_checkexists.php?cid="+catid;
							//alert(url);
							
							if(window.XMLHttpRequest) // Mozilla
							{
									objXMLHTTP = new XMLHttpRequest();
							}
							else if(window.ActiveXObject) // IE
							{
									objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
							}
							objXMLHTTP.open("POST",url,false);
							objXMLHTTP.send("");
							data = objXMLHTTP.responseText;
							
							//alert(data);
							
							if(data != 0)
							{
								  alert ("Category is in use. And it cannot be deleted.");
								 // document.clist.catid.focus();
								  return false;
							}
					 }  
		
		var con = confirm("Are you sure you want to delete the category ?");
			
		//alert(con);
		  if(con==true)
		  {	
			var page=document.clist.page.value;	 
			//document.clist.action="../admin/index.php?type=course_delete&ed="+val+"&province="+pid+"&city="+cid+"&stype="+stype;
			document.clist.action="category_list.php?type=delete&cid="+val+"&page="+page;	
			document.clist.submit();
			
		  }
	    else
	   {
		return false;
	   }
	}
}

function product_validate(type,val)
{
		//alert("enters");
	
		
		if(type!="delete")
		{
			//alert("enters");
			var page=document.product.page.value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var catname=Trim(document.product.product_sel.value);
			var prodno=Trim(document.product.style_no.value);
			//var prodname=Trim(document.product.prodname.value);
			var prodimg=Trim(document.product.upload_img.value);
			//alert ("enters");
			
			if(catname == "" || catname==0) 	
			{
				alert("Select Category Name.");		
				document.product.product_sel.focus();   	
				return false;	
			}
			if (prodno == "")
			{
				alert("Enter Style No.");		
				document.product.style_no.focus();   	
				return false;		
			}


		var sku = document.product.style_no.value;
			var prodid = document.product.prodid.value;
			//alert(prodid);
							 
				  if(sku!="")
				  {
					 
						
							var url = "sku_checkexists.php?sku="+sku+"&type="+type+"&pid="+prodid;
							//alert(url);
							
							if(window.XMLHttpRequest) // Mozilla
							{
									objXMLHTTP = new XMLHttpRequest();
							}
							else if(window.ActiveXObject) // IE
							{
									objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
							}
							objXMLHTTP.open("POST",url,false);
							objXMLHTTP.send("");
							data = objXMLHTTP.responseText;
							
							//alert(data);
							
							if(data != 0)
							{
								  alert ("Product exists with this style number.");
								 // document.clist.catid.focus();
								  return false;
							}
					 }  
			

		
			/*if (prodname == "") 	
			{
				alert("Enter Product Name.");		
				document.product.prodname.focus();   	
				return false;	
			}	*/	
			if(type != 'edit')
			{
			
			if (prodimg == "") 	
			{
				alert("Upload an image.");		
				document.product.upload_img.focus();   	
				return false;	
			}
			}
			
			
			document.product.action="product_list.php?type="+type+"&page="+page;
		}
		if(type == "delete")
		{
			var con = confirm("Are you sure you want to delete the product ?");
			
			//alert(con);
		   if(con==true)
		   {	
			var page=document.plist.page.value;	 
			//document.clist.action="../admin/index.php?type=course_delete&ed="+val+"&province="+pid+"&city="+cid+"&stype="+stype;
			document.plist.action="product_list.php?type=delete&pid="+val+"&page="+page;	
			document.plist.submit();
			
		   }
		   else
		   {
			return false;
		   }
		}
}
		
		
		
		function user_pass_validate()
		{	
				
			
					if(document.chanagepswd.opass.value=="")
					{
						alert("Please enter Old Password.");
						document.chanagepswd.opass.focus();
						return false;
					}
					
						
			
				opasswd=document.chanagepswd.opass.value;
							 
				  if(opasswd!="")
				  {
						
							var url = "pass_checkexists.php?opass="+opasswd;
							
							//alert(url);
							if(window.XMLHttpRequest) // Mozilla
							{
									objXMLHTTP = new XMLHttpRequest();
							}
							else if(window.ActiveXObject) // IE
							{
									objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
							}
							objXMLHTTP.open("POST",url,false);
							objXMLHTTP.send("");
							data = objXMLHTTP.responseText;
							
							//alert(data);
							
							if(data == 0)
							{
								  alert ("Enter the correct Old Password");
								  document.chanagepswd.opass.focus();
								  return false;
							}
					 }  
						if(document.chanagepswd.newpswd.value=="")
							{
								alert("Enter New Password.");
								document.chanagepswd.newpswd.focus();
								return false;
							}
					 
					 document.chanagepswd.action="pswd.php";
}
		function checkAll() 
		{
		   var page=document.plist.page.value;
		   /*document.plist.action="product_list.php?type=status";*/
		   document.plist.action="product_list.php?type=status&page="+page
		   document.plist.submit();
		}
function best_product()
{
	var page=document.plist.page.value;
	/*document.plist.action="product_list.php?type=bestprod";*/
	document.plist.action="product_list.php?type=bestprod&page="+page;
	document.plist.submit();
}
function news_validate(type,val)
{
	//alert(type);
	//alert(val);
	
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(type!="delete")
	{
		var page=document.news.page.value;
		var newsname=Trim(document.news.news_title.value);
		var newsdesc=Trim(document.news.news_desc.value);
		if(newsname == "")
		{
			alert("Enter News Title.");		
			document.news.news_title.focus();   	
			return false;		
		}
		if(newsdesc == "")
		{
			alert("Enter News Description.");		
			document.news.news_desc.focus();   	
			return false;		
		}
		document.news.action="news_list.php?type="+type+"&page="+page;
	}
		
		if(type == "delete")
		{
			var con = confirm("Are you sure you want to delete the news ?");
			
			//alert(con);
		   if(con==true)
		   {
			var page=document.nlist.page.value;	
			
			var page=document.nlist.page.value;	 
			//document.clist.action="../admin/index.php?type=course_delete&ed="+val+"&province="+pid+"&city="+cid+"&stype="+stype;
			document.nlist.action="news_list.php?type=delete&news_id="+val+"&page="+page;	
			document.nlist.submit();
			
		   }
		   else
		   {
			return false;
		   }
		}

		
}
 
