﻿function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
		  if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
			  theForm[z].checked = theElement.checked;
		  }
	}
}


function modify_rank(id,oldorder){
	var newsort=prompt("Enter new rank",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<1){
		alert("The rank should start from 1 and higher");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&rank="+newsort;
}
function modify_rank1(id,oldorder,pid){
	var newsort=prompt("Enter new rank",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<1){
		alert("The rank should start from 1 and higher");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&rank="+newsort+"&pid="+pid;
}
function validate_delete(){
	return confirm("Continue delete!");
}

function getpage(){
	var sPath = window.location.pathname;
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}



function IsValidEmail(NForm){
        NForm.email.focus();
        var str = NForm.email.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
                return true; 
        }else{ 
                alert("Enter a valid Email Address");
                return false; 
        } 
}


function modify_status(id,oldorder,pid){
	var newsort=prompt("Enter new number",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<0){
		alert("The number should 0 for No  or 1 for Yes .");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&status="+newsort+"&pid="+pid;
}
function validate_contactus(nform){
	if(!nform.name.value){
		alert("Please enter your name");
		nform.name.focus();
		return false; 
	}
	if(!nform.company.value){
		alert("Please enter your company name");
		nform.company.focus();
		return false; 
	}
	if(!nform.address.value){
		alert("Please enter your address");
		nform.address.focus();
		return false; 
	}
	if(!nform.phone.value){
		alert("Please enter your phone number");
		nform.phone.focus();
		return false; 
	}
	if(!nform.country.value){
		alert("Please enter your country");
		nform.country.focus();
		return false; 
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.message.value){
		alert("Please enter your message");
		nform.message.focus();
		return false; 
	}
	return true; 
}
function Open_url(spage,swidth,sHeight,scrolls,leftpx,toppx,resize){
	var OpenWindow=window.open(spage,"logwindow",'left='+leftpx+',top='+toppx+',height='+sHeight+',width='+swidth+',scrollbars='+scrolls+',toolbar=0,resizable='+resize+',addressbar=0');
	return false;
}

function validate_brand(nform){
	if(!nform.bname.value){
		alert("Brand name required!");
		return false;
	}
	return true;
}
function changeSty(classpassed,id){
	document.getElementById(id).className=classpassed;
}
function onclicktd(urlset){
	window.location=urlset;
}

function validate_mobile(nform){
	if(nform.brandid.value==0){
		alert("Brand name required!");
		nform.bid.focus();
		return false;
	}
	if(!nform.model.value){
		alert("Mode Required!");
		nform.model.focus();
		return false;
	}
	if(!nform.bphoto.value && !nform.sphoto.value){
		alert("you must enter at least 1 photo!");
		nform.bphoto.focus();
		return false;
	}
	
	return true;
}
function validate_product(nform){
	if(nform.catid.value==0){
		alert("Type required!");
		nform.catid.focus();
		return false;
	}
	if(!nform.ptitle.value){
		alert("Title required!");
		nform.ptitle.focus();
		return false;
	}
	if(!nform.img.value){
		alert("Photo required!");
		nform.img.focus();
		return false;
	}
	return true;
}