

//      Admin panel

// validation for login

function loginValidation(){

var doc=document.loginF;

if(trim(doc.username.value)==""){
alert("Please enter the user name.");
doc.username.focus();
return false;
}

if(trim(doc.password.value)==""){
alert("Please enter the password.");
doc.password.focus();
return false;
}

}

// validation for changePassword

function changePass(){

var doc=document.changepassword;

if(trim(doc.newpassword.value)==""){
alert("Please enter the new password.");
doc.newpassword.focus();
return false;
}

if(trim(doc.confirmpassword.value)==""){
alert("Please re-enter the new password.");
doc.confirmpassword.focus();
return false;
}

if(trim(doc.newpassword.value)!=trim(doc.confirmpassword.value)){
alert("Passwords do not match in both cases.");
doc.confirmpassword.focus();
return false;
}

}


function checkUploadFile(){
	
var doc=document.form1;	

    if(trim(doc.name.value)==""){
	alert("Please enter the category name.");
	doc.name.focus();
	return false;
	}	
	
	
	if(trim(doc.file.value)=="" && trim(doc.oldFile.value)==""){
	alert("Please select a file to upload.");
	doc.file.focus();
	return false;
	}
	
	if(trim(doc.file.value)!=""){
	document.getElementById("uploadImage").style.display="block";
	}
	
}


// update to new price

// Enlarge Image

function OpenNewPopUp(PageName, Width, Height, ResizableOption ){ 
	window.open(PageName,"win1","toolbar=no,directories=no,resize="+ResizableOption+",menubar=no,location=no,scrollbars=yes,width="+Width+",height="+Height+",maximize=null,top=70,left=80");

 }


function checkContent(){
	
var doc=document.form1;	

    if(trim(doc.name.value)==""){
	alert("Please enter the page name.");
	doc.name.focus();
	return false;
	}
			
	if(trim(doc.file.value)=="" && trim(doc.oldFile.value)==""){
	alert("Please select a file to upload.");
	doc.file.focus();
	return false;
	}
	
	
	if(trim(doc.description.value)==""){
	alert("Please enter the page Description.");
	doc.description.focus();
	return false;
	}
	
	if(trim(doc.file.value)!=""){
	document.getElementById("uploadImage").style.display="block";
	}
}
 
 


function checkProduct(){
	
var doc=document.form1;	

    if(trim(doc.categoryId.value)==""){
	alert("Please select the product category.");
	doc.categoryId.focus();
	return false;
	}
	
    if(trim(doc.name.value)==""){
	alert("Please enter the product name.");
	doc.name.focus();
	return false;
	}
	
/*	if(trim(doc.code.value)==""){
	alert("Please enter the product code.");
	doc.code.focus();
	return false;
	}*/
			
	if(trim(doc.file.value)=="" && trim(doc.oldFile.value)==""){
	alert("Please select a file to upload.");
	doc.file.focus();
	return false;
	}
	
/*	if(trim(doc.description.value)==""){
	alert("Please enter the product description.");
	doc.description.focus();
	return false;
	}*/
	
/*	if(trim(doc.price.value)==""){
	alert("Please enter the product price.");
	doc.price.focus();
	return false;
	}*/
	
	
	
	if(trim(doc.file.value)!=""){
	document.getElementById("uploadImage").style.display="block";
	}
}

function disp_text()
   {
   var w = document.form1.categoryId.selectedIndex;
   document.form1.name.value = document.form1.categoryId.options[w].text;
   
   }

function checkContact(){
	
var doc=document.cartF;		
	
	if(trim(doc.firstName.value)==""){
		alert("Please enter first name.");
		doc.firstName.focus();
		return false;
		}
		
		if(trim(doc.lastName.value)==""){
		alert("Please enter last name.");
		doc.lastName.focus();
		return false;
		}
		
		if(trim(doc.phone.value)==""){
		alert("Please enter the phone number.");
		doc.phone.focus();
		return false;
		}else if (checkInternationalPhone(doc.phone.value)==false){
		alert("Invalid phone number")
		doc.phone.value=""
		doc.phone.focus()
		return false
	}
		
		if(trim(doc.email.value)==""){
		alert("Please enter an email address.");
		doc.email.focus();
		return false;
		}else{
		
		   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   var address = doc.email.value;
		   if(reg.test(address) == false) {
			  alert('Invalid Email Address');
			  doc.email.focus();
			  return false;
		   }
		
		}
					
		
		
		if(trim(doc.message.value)==""){
		alert("Please enter your message.");
		doc.message.focus();
		return false;
		}
		
		
		
}




function checkQuery(){
	
var doc=document.form1;		
	
	
	
	if(trim(doc.subject.value)==""){
		alert("Please enter the subject.");
		doc.subject.focus();
		return false;
		}
		
		if(trim(doc.firstName.value)==""){
		alert("Please enter first name.");
		doc.firstName.focus();
		return false;
		}
		
		if(trim(doc.lastName.value)==""){
		alert("Please enter last name.");
		doc.lastName.focus();
		return false;
		}
		
		
		
		if(trim(doc.email.value)==""){
		alert("Please enter an email-address.");
		doc.email.focus();
		return false;
		}else{
		
		   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   var address = doc.email.value;
		   if(reg.test(address) == false) {
			  alert('Invalid Email Address');
			  doc.email.focus();
			  return false;
		   }
		
		}
					
		if(trim(doc.phone.value)==""){
		alert("Please enter a phone number.");
		doc.phone.focus();
		return false;
		}else if (checkInternationalPhone(doc.phone.value)==false){
		alert("Invalid phone number")
		doc.phone.value=""
		doc.phone.focus()
		return false
	}
	
		if(trim(doc.city.value)==""){
		alert("Please enter the city name.");
		doc.city.focus();
		return false;
		}
		
		if(trim(doc.state.value)==""){
		alert("Please enter the state name.");
		doc.state.focus();
		return false;
		}
		
		if(trim(doc.country.value)==""){
		alert("Please select a country.");
		doc.country.focus();
		return false;
		}
		
		if(trim(doc.message.value)==""){
		alert("Please enter your message.");
		doc.message.focus();
		return false;
		}
		
		
		
}





//###### For trim function

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//###### For float function

function floats(stringToTrim) {
	return stringToTrim.replace(/^[0-9]+([\.]?[0-9]+){0,1}$/,"");
}

function integers(stringToTrim) {
	return stringToTrim.replace(/^[0-9]+$/,"");
}










/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


