function chk_order(field,sortval,querystring,url)
{
	var tempquerystring="";
	if(querystring=="")
	{
		tempquerystring=url+"?field="+field+"&sort="+sortval;
	}
	else
	{
		tempquerystring=url+"?field="+field+"&sort="+sortval+querystring;
	}
	document.location.href=tempquerystring;
	
}
function in_ext_lib_img(str)
{
		var x;
		var flag = 0;
		var myext = new Array();
		myext[0] = ".jpg";
		myext[1] = ".jpeg";
		myext[2] = ".ai";
		myext[3] = ".3dm";
		myext[4] = ".3dmf";
		myext[5] = ".bmp";
		myext[6] = ".drw";
		myext[7] = ".dxf";
		myext[8] = ".eps";
		myext[9] = ".indd";
		myext[10] = ".gif";
		myext[11] = ".mng";
		myext[12] = ".tif";
		myext[13] = ".png";
		myext[14] = ".psd";
		myext[15] = ".pdf";

	for (x in myext)
	{
		if(str.substr(str.lastIndexOf(".",str)).toLowerCase() == myext[x])
		{
			flag = 1;
			break;	
		}
	}
	if(flag == 0)
	{
		alert("Please upload proper image file.");
		return false;
	}
	else
	{
		return true;
	}
}
function valid()
{
	if(document.getElementById("oldpass").value=="")
	{
		alert("Please Enter Old Password");
		document.getElementById("oldpass").focus();
		return false;
	}
	if(document.getElementById("newpass").value=="")
	{
		alert("Please Enter New Password");
		document.getElementById("newpass").focus();
		return false;
	}
	if(document.getElementById("confirmnewpass").value=="")
	{
		alert("Please Confirm New Password");
		document.getElementById("confirmnewpass").focus();
		return false;
	}
	else if(document.getElementById("newpass").value != document.getElementById("confirmnewpass").value)
	{
		alert("Sorry! Your new Password and Confirm password do not match");
		document.getElementById("confirmnewpass").focus();
		return false;
	}
	return true;
}
function funDelete(flag,tid,imagename,imageno)
{
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	self.xmlHttpReq.open('POST',"deleteimage.php?tid="+tid+"&imagename="+imagename+"&flag="+flag+"&imageno="+imageno, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
	self.xmlHttpReq.onreadystatechange = function() 
    {	
		if (self.xmlHttpReq.readyState == 4) {
			//alert(self.xmlHttpReq.responseText);
			update_delete(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(null);
}
function update_delete(str)
{
	var tmpstr=str.split("==");
	if(tmpstr[1]=="ProjImg")
	{
		document.getElementById("filename1").value="";
		document.getElementById("imgProj").style.display="none";
		document.getElementById("hrefDeleteProj").style.display="none";
	}
	
}
// End of Delete Image
function Product_valid()
{
	if(document.addprod.category.value=='')
	{
		alert("Please enter product category");
		document.addprod.category.focus();
		return false;
	}
	if(document.addprod.title.value=='')
	{
		alert("Please enter product title");
		document.addprod.title.focus();
		return false;
	}
	if(document.getElementById("flImage1").value=="" &&  document.getElementById("filename1").value=="")
	{
		alert("Please Upload Product Image.");
		document.getElementById("flImage1").focus();
		return false;
	}
	if(document.getElementById("flImage1").value!="")
	{
		if(!in_ext_lib_img(document.getElementById("flImage1").value))
		{
			return false;
		}
	}
	if(document.addprod.price.value=='')
	{
		alert("Please enter product price");
		document.addprod.price.focus();
		return false;
	}
	if(isNaN(document.addprod.price.value))
	{
		alert("Please enter product price Numeric");
		document.addprod.price.focus();
		return false;
	}

}
function ChangeStatus(pid,val,flag)
{
	//alert(pid + "==>" + val.checked);
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	var status="N";
	if(val.checked==true)
	{
		status="Y";
	}
	self.xmlHttpReq.open('POST', "changestatus.php?pid="+pid+"&status="+status+"&flag="+flag, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
	self.xmlHttpReq.onreadystatechange = function() 
    {	
		if (self.xmlHttpReq.readyState == 4) {
			//alert(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(null);
}
function emailInvalid(s)
{
	if(!(s.match(/^[\w]+([_|\.-][\w]{1,})*@[\w]{2,}([_|\.-][\w]{1,})*\.([a-z]{2,4})$/i) ))
    {
		return false;
	}
	else
	{
		return true;
	}
}
function chkfrm()
{
	if(document.frmonline.online_name.value =="")
	{
		alert("Please Enter Name");
		document.frmonline.online_name.focus();
		return false;
	}
	if(document.frmonline.online_email.value =="")
	{
		alert("Please Enter Email");
		document.frmonline.online_email.focus();
		return false;
	}
	if(!emailInvalid(document.frmonline.online_email.value))
	{	
		alert("Please enter valid email address");
		document.frmonline.online_email.focus();
		return false;
	}
	
	if(document.frmonline.online_company.value =="")
	{
		alert("Please Enter Company");
		document.frmonline.online_company.focus();
		return false;
	}
	if(document.getElementById("online_image").value!="")
	{
		if(!in_ext_lib_img(document.getElementById("online_image").value))
		{
			return false;
		}
	}
	//if(document.frmonline.online_country.value =="" || document.frmonline.online_state.value =="" || document.frmonline.online_phone.value =="")
//	{
//		alert("Please Enter Phone");
//		document.frmonline.online_country.focus();
//		return false;
//	}
	if(isNaN(document.frmonline.online_country.value) || isNaN(document.frmonline.online_state.value) || isNaN(document.frmonline.online_phone.value))
	{
		alert("Please Enter Numeric Value in Phone");
		document.frmonline.online_country.focus();
		return false;
	}
	document.getElementById('subval').value=1;
	document.frmonline.submit();
	return true;
}	