String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");

 }


 String.prototype.padL = function (nLength, sChar) {
  var sreturn = this;
  while (sreturn.length < nLength) {
   sreturn = String(sChar) + sreturn;
  }
  return sreturn;

 }
 

 function isblank(s)
 {
   for(i = 0; i < s.length; i++) {
     c = s.charAt(i);
     if ((c != '\n') && (c != '\t')) return false;
   }
   return true;
 }

 function validAreaCode(aCode)
 	{
return true;   //Disabled due to Mellisa Data Phone validation tool
 //var codes=new Array();
 var codes=[205,206,207,208,209, 251,252,253,254,255, 256, 334, 659, 907,480, 520, 602, 623, 928,479,
            501,502,503,504,505,506,507, 870,209, 213, 310, 323, 341,
            369, 408, 415, 424, 442, 510, 530, 559, 562, 619, 626, 627, 628, 650, 657, 661, 669, 707, 
            714, 747, 760, 764, 805, 818, 831, 858, 909, 916, 925, 935, 949, 951 ,303, 719, 720, 970 
            ,203, 475, 860, 959,302, 202, 239,305,321,352,386,407,561,689,727,754,772,786,813,850,863,904
            ,941,954,229,404,470,478,678,706,762,770,912,808,208,217,224,309,312,331,447,459,464,618,630
            ,708,730,773,779,815,847,872,219,260,317,574,765,812,319,515,563,641,712,316,620,785,913,270
            ,364,502,606,859,225,318,337,504,985,207,227,240,301,410,443,667,339,351,413,508,617,774,781
            ,857,978,231,248,269,313,517,586,616,679,734,810,906,947,989,218,320,507,612,651,763,952,228
            ,601,662,769,314,417,557,573,636,660,816,975,406,308,402,702,775,603,201,551,609,732,848,856
            ,862,908,973,505,575,212,315,347,516,518,585,607,631,646,716,718,845,914,917,252,336,704,828
            ,910,919,980,984,701,216,234,283,330,380,419,440,513,567,614,740,937,405,580,918,503,541,971
            ,215,267,412,445,484,570,610,717,724,814,835,878,401,803,843,864,605,423,615,731,865,901,931
            ,210,214,254,281,325,361,409,430,432,469,512,682,713,737,806,817,830,832,903,915,936,940,956
            ,972,979,385,435,801,802,276,434,540,571,703,757,804,206,253,360,425,509,564,304,681,262,414
            ,608,715,920,307,403, 587, 780, 825, 236, 250, 604, 778,204,506,507,508,509,510,511,512,513,515
            ,709, 902,226, 289, 343,514,516, 
            416, 519, 613, 647, 705, 807, 905,418, 438, 450, 514, 581, 819,306,867, 787, 939, 340, 684
            , 671, 670, 242, 700, 777, 800, 900, 866, 877, 888, 976];

 for(index=0;index<codes.length;index++)
 		{
// 	alert(' Codes' +codes[index] + '   aCode '+aCode)
 	if(aCode==codes[index])return true;

 		}

 return false;
 	}

 function isValidData(fieldName, fieldData)
 {
	 var valid = true;
	 var numTest = /[0-9@#$%\^&\*\(\)]/;		// checks if string contains digits or certain symbols
	 valid = isValidDataGeneral(fieldData);
	 
	 if (valid) {
		 if (fieldName == 'first' || fieldName == 'last' || fieldName == 'city')
		 {
			 valid = fieldData.length > 1 && !numTest.test(fieldData);
		 }
		 else if (fieldName == 'address')
		 {
			 valid = fieldData.search("[0-9]") > -1;			// must contain at least 1 digit
			 if (valid){
				 valid = fieldData.search("[a-zA-Z]") > -1;	// must contain one or more characters	
			 }
		 }
	 }
	 return valid;
 }
 function isValidDataGeneral(fieldData)
 {
 	if (fieldData == null)
 		return false;
 	if (isBlank(fieldData))
 		return false;
 	fieldData = fieldData.trim().toLowerCase();
 	if (fieldData.length < 2 || fieldData.substring(0, 3) == "asd")
 		return false;
 	if (fieldData.search("\btest\b") > -1)		// check for word test by itself (allowed within a word)
 		return false;
 	var repTest = /([a-zA-Z])\1\1/;
 	if (repTest.test(fieldData))					// check for the same character repeating 3 or more times
 		return false;
 	
 	
 	return true;
 }
 
 function isNum(value) {
     for(var i = 0;i<value.length;i++) {
       if((parseInt(value.substring(i,i+1))+"") == "NaN")
       return false;
     }
     return true;
}

 /*
  * validType has following values
  * char - alpha + punctuation
  * number = numbers only
  */
function validKeyPress(e, validType)
{
	var evt=(e)?e:(window.event)?window.event:null; 
	if (evt){
		var charCode = (evt.charCode) ? evt.charCode :
            ((evt.keyCode) ? evt.keyCode :
            ((evt.which) ? evt.which : 0));
        
		var numcheck = /\d/; 

		keychar = String.fromCharCode(charCode);	
		var isNum = numcheck.test(keychar);
		if (validType == 'char') {
			valid = !isNum
		} else if (validType == 'number') {
			valid = (isNum || !printChar(keychar));
		}
		return valid;
	}
}
function printChar(keychar)
{	
	var spckeys = /[a-zA-Z,.;:"/]/;
	
	return spckeys.test(keychar);
}

function isValidPhone(phoneN)
{
	var valid = true;
	if (phoneN) {
		if (phoneN == "6305150170" || phoneN == "8005569393")
			valid = false;
	}
	return valid; 
}