	
var MONTH_NAMES = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

function isDigit(num) {
	var string="1234567890";
	if (string.indexOf(num) != -1) {
		return true;
		}
	return false;
	}

function isNumeric(val) {
	var dp = false;	
	for (var i=0; i < val.length; i++) {
		if (!isDigit(val.charAt(i))) {
 			if (val.charAt(i) == '.') {
				if (dp == true) { return false; }

 // already saw a decimal point
				else { dp = true; }
				}
			else {
				return false;
 				}
			}
		}
	return true;
	}
	
	
function isInteger(val) {
	for (var i=0; i < val.length; i++) {
		if (!isDigit(val.charAt(i))) {
 return false; }
		}
	return true;
	}


function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token = str.substring(i,i+x);
		if (token.length < minlength) {
			return null;
			}
		if (isInteger(token)) {
 			return token;
			}
		}
	return null;
	}

function isEmail(Obj)
{
	var x;
	var y;
	var str = Obj.value;
	var msg;
	var InvalidChars='@';
	var invChars='';
	var a=0;
	/*Iterate over the target and source strings to check if the source string is present in 				the target. If an invalid character from target string is present in the source string, 	add the character to the invChars variable.*/

	for (x=0; x<=(str.length-1); x++)
	{
		for (y=0; y<=(InvalidChars.length-1); y++)
		{
			if (str.charCodeAt(x)==InvalidChars.charCodeAt(y))
			{
				a=a+1;
			}
		}
	}
	
	if(Obj.value!='')
	if (a < 1)
	{
		alert("Not a valid EmailAddress");
		Obj.focus();
		return false;
	}
	//return true;
}	

function getDateFromFormat(val,format)
{
	val = val+"";	
	format = format+"";
	var i_val = 0;
	var i_format = 0;
	var c = "";
	var token = "";
	var token2= "";
	var x,y;
	var now   = new Date();

	var year  = now.getYear();
	var month = now.getMonth()+1;

	var date  = now.getDate();
	var hh    = now.getHours();
	var mm    = now.getMinutes();
	var ss    = now.getSeconds();
	var ampm  = "";
	while (i_format < format.length) {
		// Get next token from format string
		c = format.charAt(i_format);

		token = "";
		while ((format.charAt(i_format) == c) && (i_format < format.length)) {
			token += format.charAt(i_format);
			i_format++;
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }     // 4-digit year
			if (token=="yy")   { x=2;y=2; }     // 2-digit year
			if (token=="y")    { x=2;y=4; }     // 2-or-4-digit year

			year = _getInt(val,i_val,x,y);
			if (year == null) { return 0; }
			i_val += year.length;
			if (year.length == 2) {
				if (year > 70) {
					year = 1900+(year-0);
					}
				else {
					year = 2000+(year-0);
					}
				}
			}
		else if (token=="MMM"){    // Month name
			month = 0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name = MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase() == month_name.toLowerCase()) {
					month = i+1;
					if (month>12) { month -= 12; }
					i_val += month_name.length;
					break;
					}
				}
			if (month == 0) { return 0; }
			if ((month < 1) || (month>12)) { return 0; }
			// TODO: Process Month Name
			}
		else if (token=="MM" || token=="M") {
			x=token.length; y=2;
			month = _getInt(val,i_val,x,y);
			if (month == null) { return 0; }
			if ((month < 1) || (month > 12)) { return 0; }
			i_val += month.length;
			}
		else if (token=="dd" || token=="d") {
			x=token.length; y=2;
			date = _getInt(val,i_val,x,y);
			if (date == null) { return 0; }
			if ((date < 1) || (date>31)) { return 0; }
			i_val += date.length;
			}
		else if (token=="hh" || token=="h") {
			x=token.length; y=2;
			hh = _getInt(val,i_val,x,y);
			if (hh == null) { return 0; }
			if ((hh < 1) || (hh > 12)) { return 0; }
			i_val += hh.length;
			hh--;
			}
		else if (token=="HH" || token=="H") {
			x=token.length; y=2;
			hh = _getInt(val,i_val,x,y);
			if (hh == null) { return 0; }
			if ((hh < 0) || (hh > 23)) { return 0; }
			i_val += hh.length;
			}
		else if (token=="KK" || token=="K") {
			x=token.length; y=2;
			hh = _getInt(val,i_val,x,y);
			if (hh == null) { return 0; }
			if ((hh < 0) || (hh > 11)) { return 0; }
			i_val += hh.length;
			}
		else if (token=="kk" || token=="k") {
			x=token.length; y=2;
			hh = _getInt(val,i_val,x,y);
			if (hh == null) { return 0; }
			if ((hh < 1) || (hh > 24)) { return 0; }
			i_val += hh.length;
			h--;
			}
		else if (token=="mm" || token=="m") {
			x=token.length; y=2;
			mm = _getInt(val,i_val,x,y);
			if (mm == null) { return 0; }
			if ((mm < 0) || (mm > 59)) { return 0; }
			i_val += mm.length;
			}
		else if (token=="ss" || token=="s") {
			x=token.length; y=2;
			ss = _getInt(val,i_val,x,y);
			if (ss == null) { return 0; }
			if ((ss < 0) || (ss > 59)) { return 0; }
			i_val += ss.length;
			}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase() == "am") {
				ampm = "AM";
				}
			else if (val.substring(i_val,i_val+2).toLowerCase() == "pm") {
				ampm = "PM";
				}
			else {
				return 0;
				}
			}
		else {
			if (val.substring(i_val,i_val+token.length) != token) {
				return 0;
				}	
		else {
			i_val += token.length;
				}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) {
		return 0;
		}

	// Is date valid for month?
	if (month == 2) {
		// Check for leap year
		if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) { // leap year
			if (date > 29){ return false; }
			}
		else {
			if (date > 28) { return false; }
			}
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return false; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") {
		hh+=12;
		}
	else if (hh>11 && ampm=="AM") {
		hh-=12;
		}
	var newdate = new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
}



function isDate(DateField)
{	
	var val = DateField.value;
	var vdate = getDateFromFormat(val,"d/M/yyyy");
	if (vdate == 0) 
	{
		alert("Invalid date in d/M/yyyy format!");
		DateField.focus();
		return false;
	}
	return true;
}

function isNull(val)
{
	if (val == null) {
 return true; }
	for (var i=0; i < val.length; i++) {
		if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n")) {
 return false; }
		}
	return true;
}

function RTrim(str)
// str - the string we want to RTrim
{
    // We don't want to trim JUST spaces, but also tabs,
    // line feeds, etc.  Add anything else you want to
    // "trim" here in Whitespace

    var whitespace = new String(" \t\n\r");

    var s = new String(str);

    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
       {

        // We have a string with trailing blank(s)...

        var i = s.length - 1;       // Get length of string

        // Iterate from the far right of string until we
        // don't have any more whitespace...

        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
            i--;

        // Get the substring from the front of the string to
        // where the last non-whitespace character is...

        s = s.substring(0, i+1);
    }
    return s;
}


// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
//LTrim(string) : Returns a copy of a string without leading spaces.
//==================================================================
function LTrim(str)
/***
	str         : the string we want to LTrim
	RETURN VALUE: An LTrimmed string!
***/
{
    // We don't want to trip JUST spaces, but also tabs,
    // line feeds, etc.  Add anything else you want to
    // "trim" here in Whitespace
    var whitespace = new String(" \t\n\r");

    var s = new String(str);

    if (whitespace.indexOf(s.charAt(0)) != -1) {
        // We have a string with leading blank(s)...

        var i = 0;       // Get length of string

        // Iterate from the left of string until we
        // don't have any more whitespace...
        while (i <= s.length && whitespace.indexOf(s.charAt(i)) != -1)
            i++;

        // Get the substring from the front of the string to
        // where the last non-whitespace character is...
        s = s.substring(i, s.length);
    }

    return s;
}

function Trim(str) {
	return LTrim(RTrim(str));
	}

function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
		
		if (charCode==45) {
			return true;
		}
		else {	
    	if (charCode > 31 && (charCode < 48 || charCode > 57 )  ) {
        return false;
    	}else {
	   		return true;
			}
		}	
}

function chkMandatoryFields(form) {
	var count;
	count=form.elements.length;
	//alert(count);
	for(i=1;i<=count-3;i++) {
		//alert(form.elements[i].name);
			if (form.elements[i].value=="") {
				errmsg.innerText="! Fields marked with * are mandatory";
				return false;
				break;  
			}	
	}
	var pass=form.txtPass.value;
	var cpass=form.txtconfirmPass.value;
	if(pass!=cpass) {
		errmsg.innerText="Confirm password doesnt match";
				return false;
	}
}	

	 function copy()
	{                   
		//alert(document.customer.cboCountry_b.value);
		               
		                 document.customer.txtFname_s.value=document.customer.txtFname_b.value;
		                 document.customer.txtLname_s.value=document.customer.txtLname_b.value;
             		     document.customer.txtAdd1_s.value=document.customer.txtAdd1_b.value;
             		     document.customer.txtAdd2_s.value=document.customer.txtAdd2_b.value;
             		     document.customer.txtCity_s.value=document.customer.txtCity_b.value;
             		     document.customer.txtState_s.value=document.customer.txtState_b.value;
             		     document.customer.cboCountry_s.value=document.customer.cboCountry_b.value;
             		     document.customer.txtPin_s.value=document.customer.txtPin_b.value;
             		     document.customer.txtPhone_s.value=document.customer.txtPhone_b.value;
             		     document.customer.txtMobile_s.value=document.customer.txtMobile_b.value;
             		     document.customer.txtEmail_s.value=document.customer.txtEmail_b.value;         		   
     
		
	}
	 function copyAdmin()
	{                   
		//alert(document.customer.cboCountry_b.value);
		               
		                 document.frmOrderstatusadd.txSfname.value=document.frmOrderstatusadd.txBfname.value;
		                 document.frmOrderstatusadd.txtSlname.value=document.frmOrderstatusadd.txtBlname.value;
             		     document.frmOrderstatusadd.txtSadd1.value=document.frmOrderstatusadd.txtBadd1.value;
             		     document.frmOrderstatusadd.txtSadd2.value=document.frmOrderstatusadd.txtBadd2.value;
             		     document.frmOrderstatusadd.txtScity.value=document.frmOrderstatusadd.txtBcity.value;
             		     document.frmOrderstatusadd.txtSstate.value=document.frmOrderstatusadd.txtBstate.value;
             		     document.frmOrderstatusadd.txtScountry.value=document.frmOrderstatusadd.txtBcountry.value;
             		     document.frmOrderstatusadd.txtSpincode.value=document.frmOrderstatusadd.txtBpincode.value;
             		     document.frmOrderstatusadd.txtSphone.value=document.frmOrderstatusadd.txtBphone.value;
             		     document.frmOrderstatusadd.txtSmobileno.value=document.frmOrderstatusadd.txtBmobileno.value;
             		     document.frmOrderstatusadd.txtSemail.value=document.frmOrderstatusadd.txtBemail.value;         		   
     
		
	}
	 function copyAdminEdit()
	{                   
		//alert(document.customer.cboCountry_b.value);
		               
		                 document.frmOrderstatusEdit.txSfname.value=document.frmOrderstatusEdit.txBfname.value;
		                 document.frmOrderstatusEdit.txtSlname.value=document.frmOrderstatusEdit.txtBlname.value;
             		     document.frmOrderstatusEdit.txtSadd1.value=document.frmOrderstatusEdit.txtBadd1.value;
             		     document.frmOrderstatusEdit.txtSadd2.value=document.frmOrderstatusEdit.txtBadd2.value;
             		     document.frmOrderstatusEdit.txtScity.value=document.frmOrderstatusEdit.txtBcity.value;
             		     document.frmOrderstatusEdit.txtSstate.value=document.frmOrderstatusEdit.txtBstate.value;
             		     document.frmOrderstatusEdit.txtScountry.value=document.frmOrderstatusEdit.txtBcountry.value;
             		     document.frmOrderstatusEdit.txtSpincode.value=document.frmOrderstatusEdit.txtBpincode.value;
             		     document.frmOrderstatusEdit.txtSphone.value=document.frmOrderstatusEdit.txtBphone.value;
             		     document.frmOrderstatusEdit.txtSmobileno.value=document.frmOrderstatusEdit.txtBmobileno.value;
             		     document.frmOrderstatusEdit.txtSemail.value=document.frmOrderstatusEdit.txtBemail.value;         		   
     
		
	}
	
	
	
	
	function cat_filter(cid) {
		//alert('books.php?c_id='+cid);
		location.reload('books.php?c_id='+cid);
	}	
	
	
	
	var xmlHttp;
	function display_div(name,brwzby,lettr) {
		//sdocument.getElementById("img_div").visible=false;
		img_div.style.visibility="";
		/*xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		}
		var url="book_list.php"
		url=url+"?cid="+name
		url=url+"&browseby="+brwzby
		url=url+"&letter="+lettr
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)*/

		alert(name);
	}
	
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
	//	alert(this.bklist.innerText);
	document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
	//document.getElementById("txtHint").innerHTML=this.bklist.innerText
	//document.getElementById("tst").innerText=this.tst.innerHTML  
	//document.reload(xmlHttp.responseText );
		} 
	} 

	function GetXmlHttpObject()
	{ 
		var objXMLHttp=null
		if (window.XMLHttpRequest)
		{
			objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject)
		{
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		return objXMLHttp
	}
	
	function change_Pass() {
		location.reload('change_pass.php');
		
	}
	function chkPass(dbpass,oldpass) {
		var txtPass=document.getElementById('txtPass');
		var txtconfirm=document.getElementById('txtconfirmPass');
		//alert(oldpass);
		if(oldpass!="") {
			if(dbpass!=oldpass) {
				errmsg.innerText="The Old password does not match";
				//alert("err");
				return false;
			}
			else {
				txtPass.disabled=false;
				txtconfirm.disabled=false;
			}
		}
		else {
			errmsg.innerText="The Old password does not match";
			return false;
		}
	}
	
		function check_pay()
{
	var pay_info=document.paymentform.pay_info.value; 
	if((pay_info == "") ||(pay_info == null))
 {
  alert("Payment Details Field is blank , please try again.");
  return false;
 
 }
 else
 {
  return true;
 }
 return false;
	
}