//Anurag: 6-Aug-08:  the function will redirect the page to specific location
function redirectToPage(pagePath) {
	window.location.href = pagePath;
}

function isEmpty(str) {
	textvalue = str.replace(/\s/g,"");
	if(textvalue.length>0){
		return false;
	} else {
		return true;
	}
}
function isAlpha(str){
	if(str.search(/^([a-zA-Z ]+)?$/)){
		return true;
	} else {
		return false;
	}
}
function textCounterDesc(field,maxlimit) {
	if (field.value.length > maxlimit) {// if too long...trim it!
		 field.value= field.value.substring(0, maxlimit);
	}
	
}
function LTrim(VALUE){
		var w_space = String.fromCharCode(32);
		if(v_length < 1){
		return"";
		}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;

		while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(iTemp,v_length);
		break;
		}
		iTemp = iTemp + 1;
		} //End While
		return strTemp;
} //End Function

function RTrim(VALUE){
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0){
		return"";
		}
		var iTemp = v_length -1;

		while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(0,iTemp +1);
		break;
		}
		iTemp = iTemp-1;

		} //End While
		return strTemp;

} //End Function


function CheckEmpty(formField){
	if(formField.value=="" || formField.value==null || formField.value==0){
		return true;
	}
	else{
		return false;
	}
}

function Trim(TRIM_VALUE){
		if(TRIM_VALUE.length < 1){
			return "";
		}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		
		if(TRIM_VALUE==""){
			return "";
		}
		else{
			return TRIM_VALUE;
		}
}

function checkEmailID(emailID){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailID)){
	return (true)
	}
	
	return (false)
}

function hasSpecialChar(string){
  var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

	  for (var i = 0; i < string.length; i++) {
		if (iChars.indexOf(string.charAt(i)) != -1) {

		   return false;
		}
	  }
	  return true;
}

function validateValue( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Validates that a string a matches
  a valid regular expression value.
    
PARAMETERS:
   strValue - String to be tested for validity
   strMatchPattern - String containing a valid
      regular expression match pattern.
      
RETURNS:
   True if valid, otherwise false.
*************************************************/
var objRegExp = new RegExp( strMatchPattern);
 
 //check if string matches pattern
 return objRegExp.test(strValue);
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}




function isValidURL(url){ 
		var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki','.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg', '.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt', '.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng', '.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf', '.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py', '.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg', '.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv', '.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn', '.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um', '.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws', '.wf','.ye','.yt','.yu','.za','.zm','.zw');  
		var mai = url; 
		var val = true;  
		var dot = mai.lastIndexOf("."); 
		var dname = mai.substring(0,dot); 
		var ext = mai.substring(dot,mai.length);
		if(dot>=0) {  
			for(var i=0; i<arr.length; i++)  {    
				if(ext == arr[i])    {    
					val = true;   break;    
				}else{
					val = false;    
				}  
			}  
			if(val == false){      
				return false;  
			}else {   
		        return true; 
	  		}
	  }else{
			return false;
	  }
} 

function isValidURL2(url){ 
    var urlRegxp = /^(http:\/\/www.|https:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
    if (urlRegxp.test(url)){
		//alert("valid");
		return true;
	} else {
		//alert("invalid website");
		return false;
   }
    
} 

function isValidURLWithHttp(url){ 
    var urlRegxp = /^(http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}/;
    if (urlRegxp.test(url)){
		//alert("valid");
		return true;
	} else {
		//alert("invalid website");
		return false;
   }
    
} 

function isValidDomain(url){ 
    var urlRegxp = /^(www.){1}([\w]+)(.[\w]+){1,2}$/;
    if (urlRegxp.test(url)){
		//alert("valid");
		return true;
	} else {
		//alert("invalid website");
		return false;
   }
    
} 

function checkDomain(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 alert("Your domain extension "+ext+" is not correct");
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 //alert("Domain name should not begin are end with '-'");
			      return false;
		 	 }
		  }
		else{
		  	 //alert("Your domain name should not have special characters");
			 return false;
		  }
		}
	}
}else{
 //alert("Your Domain name is too short/long");
 return false;
}	
	return true;
}

function isCharsInBag (s, bag)
{
    var i;
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.
 
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return false;
    }
    return true;
}



function isZIP(s)
{
    if (isCharsInBag (s, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") == false)
    {
        return false;
    }
    return true;
}


function isPhone(s)
{
	if(s.length < 5 || s.length > 16)
		return false;
	if (isCharsInBag (s, "- +()0123456789") == false)
    {
        return false;
    }
	if(s.indexOf('+') > 0)
	{
		return false;
	}
    return true;
}
function CheckFieldLength(field,charcount,cntfield,maxlimit) {
	if (field.value.length > maxlimit){ // if too long...trim it!
		field.value        = field.value.substring(0, maxlimit);	
	}
	
	document.getElementById(cntfield).innerHTML = maxlimit - field.value.length;
}


function setCounter(field,cntfield,maxlimit) {
	document.getElementById(cntfield).innerHTML = maxlimit - field.value.length;
}

function isEmail(s)
{
  if (isCharsInBag (s, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-@") == false)
    {
        return false;
    }
 if(s.charAt(0) == '@' || s.charAt(0) == '.')
 {
  return false;
 }
 else if(s.charAt(s.length-1) == '@' || s.charAt(s.length-1) == '.')
 {
  return false;
 }
 else if(s.indexOf('@.') != -1 || s.indexOf('.@') != -1 || s.indexOf('..') != -1)
 {
  return false;
 }
 
 var i;
 var found1=false;
 var found2=false;
 var count1=0;
 for (i = 0; i < s.length; i++)
 {   
  // Check that current character isn't whitespace.
  if(s.charAt(i)== ' ') {found1=true;found2=true;count1=2;}
  if(s.charAt(i)== '@') {found1=true;count1++;}
  if(s.charAt(i)== '.') {found2=true;}
 }
 if(found1==true && found2==true)
 { 
  if(count1 > 1)
   return false;
  else
      return true;
 }
 else
 {
  return false;
 }
 return true;
}
function validation()
{
	if(document.getElementById('question_text').value=="")
	{
		alert("Please specify the question text.");
		return false;
	}
	if(document.getElementById('answer_text').value=="")
	{
		alert("Please specify the answer text.");
		return false;
	}
}

function numberonly(e,dvalue){
	var checkdot=dvalue.indexOf(".");
	var unicode; //=e.charCode? e.charCode : e.keyCode
			
	if( !e ) {
		if( window.event ) {
			e = window.event;
		}else {}
	}
  
	if(e.keyCode) {
		unicode = e.keyCode;
	} else if(e.which) {
		unicode = e.which;
	} else if(e.charCode) {
		unicode = e.charCode;
	} else {}
	
	if(unicode == 46 && checkdot >0){
       return false;
    }



	if(unicode!=46){
		if(unicode!=8 && unicode!=13 && unicode!=9){
			if(unicode < 48 || unicode > 57)
	           return false;
		}
	}
 }
 
 function numberWithoutDecimal(e,dvalue){
	
	var unicode; //=e.charCode? e.charCode : e.keyCode
			
	if( !e ) {
		if( window.event ) {
			e = window.event;
		}else {}
	}
  
	if(e.keyCode) {
		unicode = e.keyCode;
	} else if(e.which) {
		unicode = e.which;
	} else if(e.charCode) {
		unicode = e.charCode;
	} else {}
	
	if(unicode!=8 && unicode!=13 && unicode!=9){

			if(unicode < 48 || unicode > 57){
	           return false;}
	}
	
 }
function tr_onmouserover(Obj,act)
{
		
		trBgColor	= Obj.style.backgroundColor;
		Obj.style.backgroundColor	= "#B5B49F";
		
		
}

function UserTr_onmouserover(Obj,act)
{
		
		trBgColor	= Obj.style.backgroundColor;
		Obj.style.backgroundColor	= "#E8F3FF";
		
		
}
function UserTr_onmouserout(Obj,act)
{
		
		
		Obj.style.backgroundColor	= '#ffffff';
		
	
}

function tr_onmouserout(Obj,act) {
	Obj.style.backgroundColor = trBgColor;
}
function validateEmail(email)
{
        
        if (email == ""){
                return false;
        }
        badStuff = ";:/,' \"\\";
        for (i=0; i<badStuff.length; i++){
                badCheck = badStuff.charAt(i)
                if (email.indexOf(badCheck,0) != -1){
                        return false;
                }
        }
        posOfAtSign = email.indexOf("@",1)
        if (posOfAtSign == -1){
                return false;
        }
        if (email.indexOf("@",posOfAtSign+1) != -1){
                return false;
        }
        posOfPeriod = email.indexOf(".", posOfAtSign)
        if (posOfPeriod == -1){
                return false;
        }
        if (posOfPeriod+2 > email.length){
                return false;
        }
        return true
}

function getordercostwhilejobconfimationmail(codeKnife, urgentCost, customJob, widthKnife, heightKnife)
{
		if(document.getElementById('is_urgent_E').checked == false) {
			urgentCost = 0;
		}
		
			
		if(customJob == 'C')
			isCustom = 'Yes'
		else
			isCustom = 'No'
				
		/*if(knifeCost != 0)
			isCustom = 'Yes'
		else
			isCustom = 'No'*/
			
		if (isEmpty(document.getElementById('JobdetailQuantity').value)) {
			alert('Please enter quantity.');
			document.getElementById('JobdetailQuantity').focus();
			return false;
		}
		
		if(isNaN(document.getElementById('JobdetailQuantity').value) || (document.getElementById('JobdetailQuantity').value < 0)) {
			alert("Please enter the valid value for quantity.");
			document.getElementById('JobdetailQuantity').focus();
			return false;
		}
		
		new Ajax.Updater('order_cost_div','/knifecalculators/getknifetotalcost/'+codeKnife+'/'+document.getElementById('JobdetailQuantity').value+'/'+urgentCost+'/'+isCustom+'/'+widthKnife+'/'+heightKnife, {asynchronous:true, evalScripts:true});
	}

	function validate_knifecalculator() {
		if (document.getElementById('colour_Spot').checked) {
			if (isEmpty(document.getElementById('KnifecalculatorNocolour').value)) {
				alert('Please enter the number of colors required.');
				document.getElementById('KnifecalculatorNocolour').focus();
				return false;
			}
			if (isNaN(document.getElementById('KnifecalculatorNocolour').value) || document.getElementById('KnifecalculatorNocolour').value < 0) {
				alert('Please enter valid value for number of colors required.');
				document.getElementById('KnifecalculatorNocolour').focus();
				return false;
			}
		}

		if (isEmpty(document.getElementById('KnifecalculatorWidth').value) && isEmpty(document.getElementById('KnifecalculatorHeight').value)) {
			alert("Please select a size or enter a custom size.");
			document.getElementById('KnifecalculatorWidth').focus();
			return false;
		}
		
		if (isEmpty(document.getElementById('KnifecalculatorWidth').value)) {
			alert("Please enter the required width.");
			document.getElementById('KnifecalculatorWidth').focus();
			return false;
		}
		
		if(isNaN(document.getElementById('KnifecalculatorWidth').value) || (document.getElementById('KnifecalculatorWidth').value <= 0)) {
			alert("Please enter the valid value for required width");
			document.getElementById('KnifecalculatorWidth').focus();
			return false;
		}

		if (isEmpty(document.getElementById('KnifecalculatorHeight').value)) {
			alert("Please enter the required height.");
			document.getElementById('KnifecalculatorHeight').focus();
			return false;
		}

		if(isNaN(document.getElementById('KnifecalculatorHeight').value) || (document.getElementById('KnifecalculatorHeight').value <= 0)) {
			alert("Please enter the valid value for required height");
			document.getElementById('KnifecalculatorHeight').focus();
			return false;
		}
		
		if (isEmpty(document.getElementById('KnifecalculatorQuantity1').value) && isEmpty(document.getElementById('KnifecalculatorQuantity2').value) && isEmpty(document.getElementById('KnifecalculatorQuantity3').value) && isEmpty(document.getElementById('KnifecalculatorQuantity4').value)) {
			alert('Please enter atleast one quantity.');
			document.getElementById('KnifecalculatorQuantity1').focus();
			return false;
		}


		if (!isEmpty(document.getElementById('KnifecalculatorQuantity1').value)){
			if(isNaN(document.getElementById('KnifecalculatorQuantity1').value) || (document.getElementById('KnifecalculatorQuantity1').value < 50)) {
				alert("Please enter the valid quantity. Minimum quantity allowed is 50.");
				document.getElementById('KnifecalculatorQuantity1').focus();
				return false;
			}
		}

		if (!isEmpty(document.getElementById('KnifecalculatorQuantity2').value)){
			if(isNaN(document.getElementById('KnifecalculatorQuantity2').value) || (document.getElementById('KnifecalculatorQuantity2').value < 50)) {
				alert("Please enter the valid quantity. Minimum quantity allowed is 50.");
				document.getElementById('KnifecalculatorQuantity2').focus();
				return false;
			}
		}

		if (!isEmpty(document.getElementById('KnifecalculatorQuantity3').value)){
			if(isNaN(document.getElementById('KnifecalculatorQuantity3').value) || (document.getElementById('KnifecalculatorQuantity3').value < 50)) {
				alert("Please enter the valid quantity. Minimum quantity allowed is 50.");
				document.getElementById('KnifecalculatorQuantity3').focus();
				return false;
			}
		}

		if (!isEmpty(document.getElementById('KnifecalculatorQuantity4').value)){
			if(isNaN(document.getElementById('KnifecalculatorQuantity4').value) || (document.getElementById('KnifecalculatorQuantity4').value < 50)) {
				alert("Please enter the valid quantity. Minimum quantity allowed is 50.");
				document.getElementById('KnifecalculatorQuantity4').focus();
				return false;
			}
		}

		return true;
}