﻿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 validate_category_form(nform){
	if(!nform.catname.value){
		alert("Category name required");
		nform.catname.focus();
		return false;
	}
	if(nform.parentcat.value < 0){
		alert("Parent category required");
		nform.catname.focus();
		return false;
	}
	return true;
}

function modify_order(id,oldorder){
	var newsort=prompt("Enter new Order",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<1){
		alert("The order should start from 1 and higher");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&sort="+newsort;
}
function validate_delete(){
	return confirm("Continue delete!");
}
function showhide_cat(id,subcount){
	var target = document.getElementById("sub"+id);
	for(i=1;i<subcount;i++){
		var target_sub = document.getElementById("sub"+i);
		target_sub.style.display="none";
	}
	target.style.display="";
	return false;
}
function display_ShowHide(id,type) {
var target = document.getElementById(id);
var all = document.getElementsByTagName(type);
if (target.style.display == '') {
	target.style.display = 'none';          
  	return false;
}
for (var i = 0; i < all.length; i++) { 
	all[i].style.display = "none";
} 
if (target.style.display == "none") {
	target.style.display = '';          
}
return false;
}	

function validate_qty_form(nform){
	if(!nform.qtyname.value){
		alert("Quantity name required");
		nform.catname.focus();
		return false;
	}
	return true;
}

function getpage(){
	var sPath = window.location.pathname;
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}
function doPreview_product(file) {
    var src = file;
  //  if (document.myForm.the_file.value.charAt(1)==":") src = "../" + src;
  if(src=='spacer.gif')
  	document.all.previmg.src="images/"+src;
  else
    document.all.previmg.src="../photos/thumb/"+src;
}

function validate_product_form(nform){
	
}

function showhide2ids(id1,id2){
	
	var target1 = document.getElementById(id1);
	var target2 = document.getElementById(id2);
	target1.style.display = 'none'; 
	target2.style.display = ''; 
	return false;
}



function validate_register(nform){
	if(!nform.username.value){
		alert("User name required!");
		nform.username.focus();
		return false;
	}
	if(!nform.pass1.value){
		alert("Password required!");
		nform.pass1.focus();
		return false;
	}
	if(!nform.pass2.value){
		alert("Confirm password required1");
		nform.pass2.focus();
		return false;
	}
	if(nform.pass1.value!=nform.pass2.value){
		alert("Password's confirmation didn't match!");
		nform.pass2.focus();
		return false;
	}
	if(!nform.fname.value){
		alert("First name required!");
		nform.fname.focus();
		return false;
	}

	if(!nform.country.value){
		alert("Country required!");
		nform.country.focus();
		return false;
	}
	if(!nform.tel.value){
		alert("Telephone required!");
		nform.tel.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	return true;
}
function validate_login_form(nform){
	if(!nform.username.value){
		alert("User name required");
		nform.username.focus();
		return false;
	}
	if(!nform.pass.value){
		alert("Password required");
		nform.pass.focus();
		return false;
	}
	return true;
}
function changeSty(classpassed,id){
	document.getElementById(id).className=classpassed;
}
function onclicktd(urlset){
	window.location=urlset;
}
function handler(e){
	var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if (key == 110)
		return false;
	if ((key > 36 && key < 41) || key == 9 || key == 8 || key == 13 || key == 46 || (key > 47 && key < 58) || (key > 95 && key < 106) || (key==109) || (key==189))
		return true; 
	else
		return false;
}

function openforgotpass(){
	var OpenWindow=window.open("forgotpassword.php","logwindow",'left=350,top=250,height=190,width=450,toolbar=0,resizable=0,addressbar=0');
	return false;
}
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 validate_cartform(nform){
	if(!nform.size.value){
		alert("Please Select a size!");
		return false;
	}	
	if(!nform.qty.value){
		alert("Please enter the quantity requested!");
		nform.qty.focus();
		return false;
	}	
	return true;
}
function validate_update(nform){
	if(!nform.fname.value){
		alert("First name required!");
		nform.fname.focus();
		return false;
	}

	if(!nform.country.value){
		alert("Country required!");
		nform.country.focus();
		return false;
	}
	if(!nform.tel.value){
		alert("Telephone required!");
		nform.tel.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	return true;
}

function openchangepass(){
	var OpenWindow=window.open("changepass.php","logwindow",'left=350,top=250,height=190,width=450,toolbar=0,resizable=0,addressbar=0');
	return false;
}

function validatechangepass(nform){
	if(!nform.pass.value){
		alert("Old password required!");
		nform.pass.focus();
		return false;
	}
	if(!nform.pass1.value){
		alert("Password required!");
		nform.pass1.focus();
		return false;
	}
	if(!nform.pass2.value){
		alert("Confirm password required1");
		nform.pass2.focus();
		return false;
	}
	if(nform.pass1.value!=nform.pass2.value){
		alert("Password's confirmation didn't match!");
		nform.pass2.focus();
		return false;
	}
	return true;

}

function modify_status(id,oldorder){
	var newsort=prompt("Enter new Status",oldorder)
	var spage=getpage();
	if(newsort==null)
	{
		return false;
	}
	if(newsort<0)
	{
		alert("The Status should 0 or 1 .");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&status="+newsort;
}
function modify_paymenttype(id,oldorder){
	var newsort=prompt("Enter new Payment type",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<0){
		alert("The Payment type should 0=cash on delivery or 1=by credit card .");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&paytype="+newsort;
}
function modify_userstatus(id,oldorder){
	var newsort=prompt("Enter new Status",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<0){
		alert("The Status should 0 or 1 .");
		return false;
	}
	window.location=spage+"?do=ustatus&id="+id+"&status="+newsort;
}
function OpenOrder(id){
	var OpenWindow=window.open("openorders.php?id="+id,"logwindow",'left=150,top=100,height=500,width=700,toolbar=0,resizable=0,addressbar=0');
	OpenWindow.focus();
	return false;
}
function Openproductdetails(id){
	var OpenWindow=window.open("productdetails.php?id="+id,"logwindow",'left=250,top=100,height=550,width=600,toolbar=0,resizable=1,scrollbars=1,addressbar=0');
	OpenWindow.focus();
	return false;
}
function validate_contactus(nform){
	if(!nform.fullname.value){
		alert("Full name required!");
		nform.fullname.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.subject.value){
		alert("Subject required!");
		nform.subject.focus();
		return false;
	}

	if(!nform.body.value){
		alert("Details required!");
		nform.body.focus();
		return false;
	}
	return true;
}
function validatecontct(nform){
	if(!nform.fullname.value){
		alert("Full name is a required field!");
		nform.fullname.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.country.value){
		alert("Country is a required field!");
		nform.country.focus();
		return false;
	}

	if(!nform.subject.value){
		alert("Subject is a required field!");
		nform.subject.focus();
		return false;
	}
	if(!nform.message.value){
		alert("Comment is a required field!");
		nform.message.focus();
		return false;
	}
	return true;
}
function modify_price(id,oldorder,pid){
	var newsort=prompt("Enter new price",oldorder)
	var spage=getpage();
	if(newsort==null){
	return false;
	}
	if(newsort<0){
		alert("Price Should be able more than zero");
		return false;
	}
	window.location=spage+"?do=update&id="+id+"&price="+newsort+"&pid="+pid;
}
function Productsizes(spage){
	var OpenWindow=window.open(spage,"logwindow",'left=150,top=250,width=800,height=250,toolbar=0,resizable=1,addressbar=0');
	return false;
}

function DeleteSizesSelectd(){
	var x=validate_delete();
	if(x==false){
			return false;
	}
	form1.action=form1.action+"?do=delsize";
	return true;
}
function UpdateSizesSelected(){
	form1.action=form1.action+"?do=updatesize";
	return true;
}

function validate_newsletterreg(nform){
	if(!nform.fullname.value){
		alert("Full Name required!");
		nform.fullname.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.tel.value){
		alert("Telephone required!");
		nform.tel.focus();
		return false;
	}
	return true;
}

function validate_shiipingform(nform){
	if(!nform.fname.value){
		alert("Full Name required!");
		nform.fname.focus();
		return false;
	}
	if(!IsValidEmail(nform)){
		nform.email.focus();
		return false;
	}
	if(!nform.add.value){
		alert("Address required!");
		nform.add.focus();
		return false;
	}
	if(!nform.city.value){
		alert("City required!");
		nform.city.focus();
		return false;
	}
	if(!nform.country.value){
		alert("Country required!");
		nform.country.focus();
		return false;
	}
	if(!nform.tel.value){
		alert("Telephone required!");
		nform.tel.focus();
		return false;
	}
	return true;
}

/*disable right click*/

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
//alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")

// --> 
function doPreview_product1(file) {
    var src = file;
  //  if (document.myForm.the_file.value.charAt(1)==":") src = "../" + src;
  if(src=='spacer.gif')
  	document.all.previmg1.src="images/"+src;
  else
    document.all.previmg1.src="../photos/thumb/"+src;
}