function checkValid_Digit_price(events)
{ 	
	val = events.charCode? events.charCode :events.keyCode;
	
	if(val<48 && val!=46 && val != 8 && val != 13 && val != 39 && val != 9) 
	  return false;
	if(val>57)
	  return false;
	return true;
}
function checkValid_Digit_Phone(events)
{ 	
	unicodes = events.charCode? events.charCode :events.keyCode;
 
	if(unicodes == 9 || unicodes == 13 || unicodes == 8 || unicodes == 37 || unicodes == 36 || unicodes == 35 || unicodes == 46)
	 return true;
  if(unicodes > 47 && unicodes < 58 )
	   return true;
	else
		return false;
	
}
function expandTag(objName)
{
  if(document.getElementById(objName).style.display == 'none')
    document.getElementById(objName).style.display = '';
  else
    document.getElementById(objName).style.display = 'none';
}
function checkValid_Digit(events)
{ 	
	val = events.charCode? events.charCode :events.keyCode;
	if(val<48 && val!=46 && val != 8 && val != 9)
	  return false;
	if(val>57)
	  return false;
	return true;
}

function checkAlphanumeric(events)
{ 	
	val = events.charCode? events.charCode :events.keyCode;
	if ((val > 0 && val < 48 && val != 8) || (val > 57 && val < 65) || (val > 90 && val < 97) || (val > 122 && val < 127)) 
	{
		return (false);
	}
	return true;
}
function checkValidAlphanumeric()
{ 	
	//65 to 90 --> (A to Z) 97 to 122 --> (a to z) 48 to 57 --> (0 to 9)
	if ((event.keyCode > 0 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97) || (event.keyCode > 123 && event.keyCode < 127)) 
	{
			event.keyCode = 0;
	}
	return true;
}
function checkValidDigit_modified(events)
{
	var unicodes=events.charCode? events.charCode :events.keyCode;
	if(unicodes > 47 && unicodes < 58)
	   return true;
	else if(unicodes == '8' || unicodes == '9' || unicodes == '13')
		return true;
	else
		return false;
}
function removespace()
{
	val = event.keyCode;
	if(val == "32")
	{
		event.keyCode=0;
	}
	else
	{
		return true;
	}
}
function showhidemenu(menuid){
	var flag = document.getElementById("main_"+menuid).style.display == "none" ? '' :'none';
	var totrow	=	document.getElementById('main_totRow').value;
	document.getElementById("main_"+menuid).style.display = flag;
	for(var i=1;i < totrow;i++)
	{
		if(i != menuid)
			document.getElementById("main_"+i).style.display = "none";
	}
}
function topSearchValid() {
	if(document.frmshopsearch.shop_category.value == 0) {
		alert(alshop_cateogry);	
		document.frmshopsearch.shop_category.focus();
		return false;
	}
}
function setSelectList(list_arr,selval)
{
	for(i=0;i<list_arr.length;i++)
	{
		if(list_arr[i].value == selval)
		{
			list_arr[i].selected=true;
			break;
		}
	}
}	
function checkSearchBox()
{
	if(document.frmsearch.keyword.value.length < 1)
	{
		alert("Enter Any Keyword For Search");
		document.frmsearch.keyword.focus();
		return false;
	}
	if(document.frmsearch.vValue.value.length < 1)
	{
		alert("Enter Any Value For Search");
		document.frmsearch.vValue.focus();
		return false;
	}		
}
function newsletter_onsubmit(f){
	var result = isValidEmail(f.vEmail.value);
	if(!result)
	//alert("Please enter a valid e-mail address to subscribe to the newsletter");
	return result;
}
function Productsearch(f){
	if(f.txtsearch.value == "" || f.txtsearch.value == "Product OR Keyword")
	{
		alert("Please Enter Keyword");
		f.txtsearch.focus();
		return false;
	}
}

function sortPrice()
{
	if(document.frmsortPrice.convcur.value != "")
		document.frmsortPrice.submit();
	else alert("Please Select a currency");
}
function checkValidNumber()
{
	val = event.keyCode;
	if(val<48)
	  event.keyCode=0;
	if(val>57)
	  event.keyCode=0;
	return true;
}

function checkValidQuantity()
{
	val = event.keyCode;
	if(val<48)
	  event.keyCode=0;
	if(val>57)
	  event.keyCode=0;
	return true;
}


function checkValidDigit()
{  
	val = event.keyCode;
	if(val<48 && val!=46)
	{
	  event.keyCode=0;
	}
	if(val>57)
	{
	  event.keyCode=0;
	}
	return true;
}
function alphanum(value,length)
{
	chk1="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_. ";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function phoneformate(value,length)
{
	chk1="1234567890()- ";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function validZip(value,length)
{
	chk1="1234567890";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function Trim(s)
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//******************************************************************************************//
//********************* functions  for email-id validation ****************************//
//******************************************************************************************//
function isValidEmail(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
	   		}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
	   }	
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}	
	return true;
}


function go_to_page(val)
{
	window.location=val;
}



function base64_decode( data ) {

    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'


    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64)      enc += String.fromCharCode(o1);
        else if (h4 == 64) enc += String.fromCharCode(o1, o2);
        else               enc += String.fromCharCode(o1, o2, o3);
    } while (i < data.length);

    return enc;
}

function base64_encode( data ) {
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';

    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        enc += b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);

    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}

function goLink(my_page)
{
	window.open(my_page); 
}
