var login="Member ID";
var spass="Password";
var sre="Confirm-Password";
var nam="Name";
var mail="E-Mail";
var add="Address";
var cit="City";
var stat="State";
var coun="Country";
var ref="Reference";
var mod="Mode Of Payment";
var frid="Friend User ID";
var ddn="Demand Draft Number";
var dodd="Demand Draft Date";
var bnam="Bank Name";
var bcit="Bank City";
var bcode="Bank Code";
var delid="Dealer ID";
var delpass="Dealer Password"
var sque="Question";
var sans="Answer";
var xmlRequest;
var allcolors="";
var allsize="";
var im=new Image();

function getdom(objid) {
	return (document.getElementById(objid));
}


function isEmpty(s) {
        return ((s == null) || (s.length == 0));
}
function isWhitespace (s) {
        var i;
      if (isEmpty(s)) return true;
      for (i = 0; i < s.length; i++){
                var c = s.charAt(i);
            if (c == " ") return true;
        }
        return false;
}
function isSame(fir,sec){
        var j,k;
      var lnt;
      if(fir.length > sec.length){
                lnt=fir.length;
                        }
        else{
                lnt=sec.length;
        }
                for (j = 0; j < lnt; j++)
                {
                      if(fir.charAt(j) !=sec.charAt(j))
                          return true;}
                                return false;}
function warnEmpty (theField, s)
        {   theField.focus()
                alert( s+" can not be empty and White spaces are not allowed in   "+ s + " field. ")
                return false}
     <!--### PASSWORD  VALIDATION ###-->
function checkPassuserSame(fir,sec){
if(isSame(fir.value,sec.value))
{	
return true;
}
else{
alert("Password should not  be same as User ID");
                        return false;}
}
function checkSamePass(Pas,theFields, si)
        {          
			var ll=theFields.value.length;
    //           if (isWhitespace(theFields.value))
      //             return warnEmpty (theFields, si);
            if(isSame(Pas.value,theFields.value)) {
            	alert("The Password and Confirm Password do not match. Please try again.");
            	theFields.focus();
            	return false;
            }else return true;
        }
function checkPassLen (theField, s){ 
       var l=theField.value.length;
	  var fieldValue1 = theField.value;
          if (isEmpty(theField.value)) { 
          	alert(s + " can not be empty."); 
         	theField.focus();
         	return false;
          }
           if (isWhitespace(theField.value)){
                  return warnEmpty (theField, s);
}               if(l < 5) { 
                	alert("The length of "+s+" should minimum of 5 characters.");
                      theField.focus();
                      return false;
                    }
                 if(l > 15) {
  	              alert("The length of "+s +" should not more than 15 characters");
  	               theField.focus();
  	              return false;}
                        return true;     }

function checkCorrect3(theField, s){ 
   
	  //var fieldValue1 = theField.value;
          if (isEmpty(theField.value)) { 
          	alert(s + " ne peut \352tre vide"); 
          	theField.focus();
          	return false;
          }
        return true;     
    }

function checkEmpty(theField, s){ 
   
	  //var fieldValue1 = theField.value;
          if (isEmpty(theField.value)) { 
          	alert("Please enter "+s); 
          	theField.focus();
          	return false;
          }
        return true;     
    }


<!--### E MAil Validaation ###-->

function checkpass(theField,s)
{	
	if(isEmpty(theField.value))
	{
	alert(s+" can not be empty.");
	theField.focus();
	return false;
	}
}
function checkEmail(theField,s)
{

var l=theField.value.length;
var fieldvalue=theField.value;

          if (isEmpty(theField.value)) { 
          	alert(s  + " ne peut rester vide"); 
          	theField.focus();
          	return false;
          }
    	for(i=0;i<l;i++)
	{
		
		if(fieldvalue.charAt(i)=='@')
		{
		
			for(j=i;j<l;j++)
			{
				if(fieldvalue.charAt(j)=='.')
				{
				
					break;
				}
				
				if((j+1)==l)
				{
				
				alert(s + " est invalide");
				theField.focus();
				return false;
				break;
				}
				
			}
		
		break;
		}
	
		if((i+1)==l)
		{
			
			alert(s + " est invalide");
			theField.focus();
			return false;
			break;
			
		}		
	
	}
		

return true;						
		
}

	
//----------for Numeric validation-----------
function checkNumeric(theField,s,emptycheck)
{	var l=theField.value.length;
	validString = "0123456789.";
	var fieldvalue = theField.value;
	if(emptycheck!=false)
	{
        if(isEmpty(theField.value))
	{
	alert(s+" can not be empty.");
	theField.focus();
	return false;
	}
	}
	 if(theField.value!="")
	{	var j;
		for (j = 0; j < l ; j++)
	        {

			if(validString.indexOf(fieldvalue.charAt(j)) == -1)
			{
				alert ("Please enter 0-9//dot(.) in"+s +" Field");
				theField.focus();
				return false;
			}
         }

	}
return true;

}

function checkNumericWithOutDot(theField,s,checkempty)
{	var l=theField.value.length;
	validString = "0123456789";
	var fieldvalue = theField.value;
	
        if(isEmpty(theField.value)&&checkempty!=false)
	{
	alert(s+" ne peut \352tre vide");
	theField.focus();
	return false;
	}
	else
	{	var j;
		for (j = 0; j < l ; j++)
	        {

			if(validString.indexOf(fieldvalue.charAt(j)) == -1)
			{
				alert (s + " ne peut comporter que des chiffres");
				theField.focus();
				return false;
			}
         }

	}
return true;

}
function checkAlphaNumeric(theField,s,checkempty)
{	var l=theField.value.length;
	validString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.- ,";
	var fieldvalue = theField.value;
        if(isEmpty(theField.value)&&checkempty!=false)
	{
	alert(s+" can not be empty.");
	theField.focus();
	return false;
	}
	else
	{	var j;
		for (j = 0; j < l ; j++)
	        {

			if(validString.indexOf(fieldvalue.charAt(j)) == -1)
			{
				alert ("Please enter 0-9/A-Z/a-z/ in "+ s +" Field");
				theField.focus();
				return false;
			}
         }

	}
return true;

}

<!--### USER ID VALIDATION ###-->
function checkUserID(theField,s)
{	var l=theField.value.length;
	validString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.";
	var fieldvalue = theField.value;
        if(isEmpty(theField.value))
	{
	alert(s+" can not be empty.");
	theField.focus();
	return false;
	}
	else
	{	var j;
		for (j = 0; j < l ; j++)
	        {

			if(validString.indexOf(fieldvalue.charAt(j)) == -1)
			{
				alert ("Please enter 0-9/A-Z/a-z/underscore(_)/dot(.) in User ID Field");
				theField.focus();
				return false;
			}
         }

	}
return true;

}


function checkImage(field,emptyflag,str,format)
{
value=field.value
var divHtml,imgsrc,ss
var divHtml1,imgHt,imgWt,imgSize,name
//imgHt=height //frm.hdnHeight.value
//imgWt=width //frm.hdnWidth.value
//imgsrc=value//frm.imgFile.value
//imgSize=size//frm.hdnSize.value
var str,arrStr,fileName,filen,filearr

	filearr=value.split('.');
	filearr.reverse()
filen=filearr[0];

if(emptyflag==true)
{
	if(value=="")
	{
 alert(str+" cannot be left blank.")
 field.focus()
 return false
	}
}

if(filen.toUpperCase()!="JPEG"&&filen.toUpperCase()!="JPG"&&filen.toUpperCase()!="GIF"&&filen.toUpperCase()!="")
{
alert(str+" should be jpeg/jpg/gif .");
return false;
}

return true
}




function GetFileExtension(val,type,msg)
{
var arr=val.split(".")
if((arr[arr.length-1]).toUpperCase()!=type.toUpperCase())
{
 alert(msg)
 return false
}
}


function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}




//for printing

var div2print;

function printDiv(id) {
  if (document.all && window.print) {
    div2print = document.all[id];
    window.onbeforeprint = hideDivs;
    window.onafterprint = showDivs;
    window.print();
  }
}

function hideDivs () {
	
  var divs = document.all.tags('DIV');
  for (var d = 0; d < divs.length; d++)
    if (divs[d] != div2print)
      divs[d].style.display = 'none';
}

function showDivs () {
  var divs = document.all.tags('DIV');
  for (var d = 0; d < divs.length; d++)
    divs[d].style.display = 'block';
}

function getobject()
{
	if(window.ActiveXObject)
	 {
	 xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	 }
	 else
	 {
	 xmlRequest = new XMLHttpRequest();
	 }
}




function Fillcbo(str,cont)
{
if(str==0)
	{
	var elem=cont.length-1
	for(var j=elem;j>=0;j--)
	cont.remove(j);
	var option = document.createElement("OPTION");
	option.value=0;
	option.innerHTML="--------";
	cont.appendChild(option);
	}
	else
	{
	var str1=str.split("#");
	var elem=cont.length-1
	for(var j=elem;j>=0;j--)
	cont.remove(j);
	for (var i=0;i<=str1.length-2;i++)
		{
		var splitcontent=str1[i].split("^");
		var values = splitcontent[0];
		var option = document.createElement("OPTION");
		option.value = values;
		option.innerHTML = splitcontent[1];
		cont.appendChild(option);
		norecord=false;
		}
	}
}


function addToCart(id,adminid,price,tva,pname,diff,pqty)
{

	var color="";
	var size="";	


if(!document.getElementById("txtcol"))
	{
	color="";
	}
else
	{
	color=document.getElementById("txtcol").value;
	}

if(!document.getElementById("txtsize"))
	{
		size="";	
	}
else
	{
		size=document.getElementById("txtsize").value;
	}


	if(diff==0)
	{
	if(confirm("Le produit \253 "+ pname+" \273 vient d'\352tre ajout\351 \340 votre panier"))
	{
qty=document.getElementById("txtqty"+id).value;
if(qty>pqty)
		{
	alert("Nos stocks sont insuffisants pour satisfaire votre demande");
		}
		else
			{
	var pageUrl = "addtocart.php?pid="+id+"&qty="+qty+"&adminid="+adminid+"&color="+color+"&size="+size+"&price="+price+"&tva="+tva;	
	pageUrl=pageUrl+"&nocache=" + Math.random();
	getobject();
	xmlRequest.open("GET", pageUrl, true);
	
xmlRequest.onreadystatechange=function()
{
if(xmlRequest.readyState==4)
	{
	//alert(xmlRequest.responseText)
	if(xmlRequest.responseText==-1)
		{
		alert("You can not add other shopkeeper's product")
		}
		else if(xmlRequest.responseText==0)
		{
			alert("Vous avez une commande en cours chez un autre artisan. Avant de commander dans cette nouvelle boutique, nous vous invitons \340 valider votre ancienne commande ou \340 la supprimer");
		}
	else
		{
	document.getElementById("cartspan").innerHTML=xmlRequest.responseText;
		}
	}
}
			}
	}
	}
	else
	{
		alert("Vous avez une commande en cours chez un autre artisan. Avant de commander dans cette nouvelle boutique, nous vous invitons \340 valider votre ancienne commande ou \340 la supprimer");
	}
	xmlRequest.send(null);
}

function check_website(thefield) {
     theurl=thefield.value;
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(theurl))
     {
         return true;
     }
     else
     {
         alert("URL invalid. Try again.");
		 thefield.focus();
         return false; 
     }
}

function distroyObject(){
	if(xmlRequest){
		xmlRequest=null
	}
}

function getallcolors(ctrl,file_path)
{
	var pageUrl = file_path+"allcolors.php"
	pageUrl=pageUrl+"?nocache=" + Math.random();
	getobject();
	xmlRequest.open("GET", pageUrl, true);
    xmlRequest.send(null);
	xmlRequest.onreadystatechange=function()
	{
	if(xmlRequest.readyState==4)
		{
		if(xmlRequest.responseText!="")
		ctrl.innerHTML=xmlRequest.responseText;
		}
	}

}
function getallsize(ctrl,catid,file_path)
{
	var pageUrl = file_path+"allsize.php?catid="+catid

	pageUrl=pageUrl+"&nocache=" + Math.random();
	getobject();
	xmlRequest.open("GET", pageUrl, true);
xmlRequest.send(null);
	xmlRequest.onreadystatechange=function()
	{
		
	if(xmlRequest.readyState==4)
		{
		if(xmlRequest.responseText!="")
		ctrl.innerHTML=xmlRequest.responseText;
		}
	}
	
}

function setsizecolor(cart_id)
{
	//color=document.getElementById("txtcolor"+cart_id).value;
	size=document.getElementById("txtsize"+cart_id).value;
	var pageUrl = "setsizecolor.php?id="+cart_id+"&size="+size+"&color=''"
	pageUrl=pageUrl+"&nocache=" + Math.random();
	//alert(pageUrl)
	getobject();
	xmlRequest.open("GET", pageUrl, true);
	xmlRequest.send(null);
	//xmlRequest.onreadystatechange=function()
	//{
		
//	if(xmlRequest.readyState==4)
		//{
		//if(xmlRequest.responseText!=""){
		//	alert(xmlRequest.responseText)
		//ctrl.innerHTML=xmlRequest.responseText;
	//	}
	//	}
	//}
	//alert(xmlRequest.responseText)
}



//--------------------------------For printing ---------------------------
function getPrint(print_area)

{

//Creating new page
window.open("printbons.php?id="+print_area,"","width=250px,height=250px");
//var pp = window.open("","","width=250px,height=250px");

//pp.width=210;
//pp.height=200;
//Adding HTML opening tag with <HEAD> … </HEAD> portion

//pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')

//pp.document.writeln('<LINK href=css/lbc.css type="text/css" rel="stylesheet">')

//pp.document.writeln('<base target="_self"></HEAD>')

//Adding Body Tag

//pp.document.writeln('<body bottomMargin="0" ');

//pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0" >');

//Adding form Tag

//pp.document.writeln('<form method="post">');

//Creating two buttons Print and Close within a HTML table

//pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');

//pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');



//pp.document.writeln('<INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();">');

//pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');

//Writing print area of the calling page

//pp.document.writeln(document.getElementById(print_area).innerHTML);

//Ending Tag of </form>, </body> and </HTML>

//pp.document.writeln('</form></body></HTML>');
//window.print(); 

}



function checkComment(isUser){
//if(isUser==0)
//{
//	alert("You must login to send any comment")
//	return false;
//}
//else{
	if(document.getElementById("comment_text").value==""){
		alert("Please enter Comments");
		document.getElementById("comment_text").focus();
		return false;
	}
	
return true;
//}
}

function textCounter(field, countfield, maxlimit,isUser) {
//if(isUser==0)
//{
//	alert("You must login to send any comment")
//	field.value="";
//	return false;
//}
//else{
   if (field.value.length > maxlimit){ // if too long...trim it!
   alert("You can not enter more then 300 character")
   field.value = field.value.substring(0, maxlimit);
   }
   // otherwise, update 'characters left' counter
   else 
   countfield.innerHTML = maxlimit - field.value.length;
//}
}

function setrank(ty,field,isUser){
//if(isUser==0)
//{
//	alert("You must login to send any comment")
//	return false;
//}
//else{
	document.getElementById("hdnrank").value=ty;
	for(i=1;i<=5;i++){
		if(i<=ty)
		document.getElementById("star"+i).src="./images/star3.gif";
		else
		document.getElementById("star"+i).src="./images/star2.gif";
	}
//}
}
function check_Email(address) 
{
	alert(address);
if ((address.indexOf ('http://www.')!= -1))
	{
      return true;
	}
  return false;
}
