var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

// Checks the first occurance of spaces and removes them
function trimSpaces(stringValue) {
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}


function Trim(TXT){
	return TXT.replace(/(^\s+)|(\s+$)/g,"");
}

//function to open in custom window
function openWindow(url,window_name,winWidth,winHeight,fscroll,resize,features) {
	if(features == '' || features == undefined)
		features = "toolbar=0,menubar=0,status=0,scrollbars=" + fscroll + ",resizable="+resize ;
	
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	if(fscroll == '') {fscroll = 0}
	if(resize == '') {resize = 'no'}
	
	window.open(url,window_name,"width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + features);
}

function numberFormat(nStr,prefix){    
	var prefix = prefix || '';    
	nStr += '';   
	x = nStr.split('.');    
	x1 = x[0];    
	x2 = x.length > 1 ? '.' + x[1] : '';    
	var rgx = /(\d+)(\d{3})/;  
	
	while (rgx.test(x1))        
		x1 = x1.replace(rgx, '$1' + ',' + '$2');  
		
	return prefix + x1 + x2;
}

function printHTML(head,content,path,cssFile) {
	var sWidth = screen.availWidth;
	var sHeight = screen.availHeight;
	var winWidth = 750 ;
	var winHeight = 500 ;
	var sLeft = (sWidth - winWidth) / 2;
	var sTop = (sHeight - winHeight) / 2;

	winId = window.open('','Preview','width=' + winWidth + ',height=' + winHeight + ', top=' + sTop + ', left=' + sLeft + ', menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes' );
	with (winId.document) {
		write('<html><head><title>Print Preview</title><style>.normal {font-family: Arial,Verdana,Helvetica,sans-serif;color:#000000;font-size: 10pt;}.normal A{font-family: Arial,Verdana,Helvetica,sans-serif;font-size: 10pt;color:#000000;text-decoration:none}.normal A:hover{text-decoration:underline}</style>');
		if(typeof(cssFile) != 'undefined' && cssFile != '') {
			write('<link rel="stylesheet" href="'+cssFile+'" type="text/css"  />');
		}
		write('</head>');
		write('<body onLoad="window.focus();" bgcolor="#FFFFFF">');
		write('<div id="options" align="right"><table cellpadding="2" cellspacing="0" border="0" ><tr>');
		write('<td class="normal">[<a href="#" onClick="options.style.display='+String.fromCharCode(39,78,111,110,101,39)+';window.print();return false;"><font color="#999999"><b>Print</b></font></a>]</td>');
		write('<td class="normal"><img src="'+path+'images/spacer.gif" width="1"></td>');
		write('<td class="normal">[<a href="#" onClick="window.close();"><font color="#999999"><b>Close</b></font></a>]</td>');
		write('</tr></table></div>');
		write('<table width="100%" cellpadding="2" cellspacing="0" border="0" align="center"><tr>')
		write('<td class="normal" style="BORDER-BOTTOM: #000000 1px dotted;"><b>'+head+'</b></td>');
		write('</tr></table>');
		write('<table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">');
		write('<tr><td class="normal" height="10" colspan="2"></td></tr>');
		write('<tr><td class="normal" colspan="2">'+content+'</td></tr>');
		write('</table>');
		write('</body></html>');
		close();
	}
}

function bookMarkSite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function printPage(){  
	var NS = (navigator.appName == "Netscape");
	var VERSION = parseInt(navigator.appVersion);
	if (VERSION > 3) {
		if (window.print) {
			window.print() ;  
		} 
		else {
			var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
			document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
			WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
		}
	}
	else {
		alert("Sorry, browser don't support print function. Try updating your browser.");
	}

}


function checkCreditCard (cardnumber, cardname) {
     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
	cards [0] = {name: "VISA", 
			   length: "13,16", 
			   prefixes: "4",
			   checkdigit: true};
			   
	cards [1] = {name: "VISA Delta", 
			   length: "13,16", 
			   prefixes: "4",
			   checkdigit: true};
			   
	cards [2] = {name: "VISA Electron", 
			   length: "16", 
			   prefixes: "417500,4917,4913",
			   checkdigit: true};

	cards [3] = {name: "MasterCard", 
			   length: "16", 
			   prefixes: "51,52,53,54,55",
			   checkdigit: true};
	
	cards [4] = {name: "Maestro", 
			   length: "16,18", 
			   prefixes: "5020,6",
			   checkdigit: true};
			   
	cards [5] = {name: "American Express", 
			   length: "15", 
			   prefixes: "34,37",
			   checkdigit: true};
			   
	cards [6] = {name: "JCB", 
			   length: "15,16", 
			   prefixes: "3,1800,2131",
			   checkdigit: true};
			   
	cards [7] = {name: "Solo", 
			   length: "16,18,19", 
			   prefixes: "6334, 6767",
			   checkdigit: true};
			   
	cards [8] = {name: "Switch", 
			   length: "16,18,19", 
			   prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
			   checkdigit: true};
			   
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardnumber = cardnumber.replace (/\s/g, "");
  
  // Check that the number is numeric
  var cardNo = cardnumber
  var cardexp = /^[0-9]{13,19}$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}


/*==============================================================================
  if (checkPostCode (myPostCode)) {
    alert ("Postcode has a valid format")
  } 
  else {alert ("Postcode has invalid format")};
                    
------------------------------------------------------------------------------*/

function checkPostCode(toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}


/*Date Functions */
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

//function to compare dates
/*
	0 - date1 less than date2
	1 - date1 greater than date2
	2 - date1 =  date2
	-1 - not valid dates
*/
function compare2Dates(date1,date2){
	// assumes that dates are in the format YYYY-MM-DD
	varDate = date1.split("-");
	day = trimSpaces(varDate[2]); 
	month = trimSpaces(varDate[1]); 
	year = trimSpaces(varDate[0]); 
	d1 = new Date(year,month-1,day).getTime();

	varDate = date2.split("-");
	day = trimSpaces(varDate[2]); 
	month = trimSpaces(varDate[1]); 
	year = trimSpaces(varDate[0]);
	d2 = new Date(year,month-1,day).getTime();
	 
	if (d1==0 || d2==0)	{
		return -1;
	}
	else if (d1 > d2) 	{
		return 1;
	}
	else if (d1 == d2)	{
		return 2;
	}
	return 0;
}

function lastDay(month,year) {
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return m[month - 1];
	if (year%4 != 0) return m[1];
	if (year%100 == 0 && year%400 != 0) return m[1];
	return m[1] + 1;
} 

function checkValidDate(dtStr){ // dd/mm/yyyy
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay = dtStr.substring(0,pos1)
	var strMonth = dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	
	var error = '';
	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 2; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	var month=parseInt(strMonth)
	var day=parseInt(strDay)
	var year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		error = "The date format should be : dd/mm/yyyy" ;
		return error;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		error = "Please enter a valid day" ;
		return error;
	}
	if (strMonth.length<1 || month<1 || month>12){
		error = "Please enter a valid month";
		return error;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		error = "Please enter a valid 2 digit year between "+minYear+" and "+maxYear ;
		return error;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		error = "Please enter a valid date" ;
		return error;
	}
	
	return error;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
//
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)

	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 2; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	var month=parseInt(strMonth)
	var day=parseInt(strDay)
	var year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yy")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 2 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	return true
}

/*-------------*/

//function limitText used to limit text in a textarea
function limitText(field,maxlimit,remark) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		if(remark) {
			remark.value = maxlimit - field.value.length;
		}
	}	
}

function checkForm(theform){
	cht = 0;
	//var commonMsg = "Please fill out all the field(s) in red before submitting.";
	var commonMsg = "Please correct following errors before submitting.\n\n";
	var showCommonMsg = false;
	var msg = '';
		
	for (x = 0; x < theform.elements.length; x++){
		
		var el = theform.elements[x];
		var valer = 0;
		var chkField = false;
		
		if(el.type) {
			el_type = el.type.toLowerCase();			

			if(document.getElementById('lbl_'+el.name)) {				
				var lblCtrl = document.getElementById('lbl_'+el.name);
				if(document.all){
					 var lblTxt = lblCtrl.innerText ;
				} 
				else{
					var lblTxt = lblCtrl.textContent ;
				}
			}
			else {
				var lblCtrl = false;
				var lblTxt = '' ;
			}
			
			if(document.getElementById('span_'+el.name)) {
				var selectSpan = document.getElementById('span_'+el.name);
			}
			else{	
				var selectSpan = '' ;
			}
			
			var arrChk ;
			
			if(el.lang != '') {					
				var idVal = el.lang;
				arrChk = idVal.split('|');
				
				for(var i = 0; i < arrChk.length; i++) {
					var type = arrChk[i];					
					if(type.indexOf('inrange') != -1) {						
						var p = type.indexOf(':');
						var minVal = type.substring(8,p);
						var maxVal = type.substring(p+1);
						type = 'inrange';
					}
					
					switch (type) {						
						case "required" :
							chkField = true;
							el.value = Trim(el.value)  ;
						
							if(el_type == "text" || el_type == "textarea" || el_type == "select-one" || el_type == "password" || el_type == "file"){	
								if(el.value == ""){
									valer = 1;
									showCommonMsg = true;
									msg +=  "=> Enter the value for '"+lblTxt+"'  \n";
								}
								else{
									valer = 0;
								}
							}// text field val
							else if(el_type == "select-multiple") {
								var flag = 0;
								var ctrlName = el.name;
								ctrlName = ctrlName.substring(0,ctrlName.length - 2);
								if(document.getElementById('lbl_'+ctrlName)) {				
									lblCtrl = document.getElementById('lbl_'+ctrlName);
									if(document.all){
										 lblTxt = lblCtrl.innerText ;
									} 
									else{
										lblTxt = lblCtrl.textContent ;
									}
								}
								
								if(el.options.length > 0) {
									for(var i=0; i < el.options.length; i++){
										if(el.options[i].selected){
											flag = 1;
											break;											
										}
									}
									if(flag == 0){
										valer = 1;
										showCommonMsg = true;
										msg +=  "=> Select atleast one value for '"+lblTxt+"'  \n";
									}
								}
							}
							else if(el_type == "checkbox"){
								if(el.checked == false){
									valer = 1;
									showCommonMsg = true;
									msg +=  "=> Enter the value for '"+lblTxt+"'  \n";
								}
								else{
									valer = 0;
								}
							}
							
							break;
							
						case "isemail" : // email
							chkField = true;
							//var emailFilter=/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/ ;
							var emailFilter=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
						
							if (!(emailFilter.test(el.value))) {
								msg +=  "=> Please enter a valid email address  \n";
								valer = 1;
							}
							
							var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
							if (el.value.match(illegalChars)) {
								msg +=  "=> Email cannot contains illegal characters  \n";
								valer = 1;
							}
							break;
						
						case "nospecialchars" : // No Special Chars
							var objRegExp = /[\s|\,|\"]/ ;
							if(objRegExp.test(el.value) ) {
								msg +=  "=> llegal characters such as space, double quotes etc. are not allowed in "+lblTxt+"  \n" ;	
								valer = 1;
							}
							break;
							
						case "inrange" : // In range
							var num = el.value.length;
							if (num < minVal || maxVal < num) {								
								msg +=  "=> "+lblTxt+' must contain a number between '+minVal+' and '+maxVal+"  \n" ;
								valer = 1;
							}
							break;

						case "isdate" : // Is date							
							if(el.value != ''){								
								retVal = checkValidDate(el.value);
								if(retVal != ''){
									msg +=  "=> "+retVal+"\n" ;
									valer = 1;
								}
							}
							break;

						case "ispostcode" : // In range							
							var validPostCode = checkPostCode(el.value);
							if(!validPostCode){
								msg +=  "=> Please enter a valid postcode\n" ;
								valer = 1;
							}
							else{
								el.value = validPostCode ;
							}
							break;

						default:
							break;
					}
					
					if (valer == 1){	
						if(el.className.indexOf("inputError") == -1) {
							var className = el.className ;
							el.className = className + ' inputError';
						}
						//alert(el.className);
						cht = 1;						
						if(lblCtrl) {
							lblCtrl.className = "errorText";							
						}
						
						if(selectSpan)
							selectSpan.className = "inputError";
							
						break;
					}
					else{
						if(chkField) {
							if(el.className.indexOf("inputError") != -1) {
								var className = el.className ;
								el.className = className.substring(0,className.length - 11);
							}
							
							if(lblCtrl) {
								lblCtrl.className = "normal";
							}
							if(selectSpan)
								selectSpan.className = "";
						}
					}
					
					
				}
				valer = 0;
			}

		}
	} 
	
	if (cht == 1){
		//msg = (showCommonMsg == true ? commonMsg+'\n'+msg : msg);
		msg = commonMsg + msg;
		alert(msg);
		return false;
	}
	else{
		return true;	   
	}               

}


// allows only numeric
function numericOnly(e) {
	if(window.event) {
		key = e.keyCode; // for IE, e.keyCode or window.event.keyCode can be used
	}
	else if(e.which) {
		key = e.which; // netscape
	}
	else {
		return true;// no event, so pass through
	}

	if( ((key>44) && (key<58)) || (key == 8) ) {
		return true; 
	}
	else {
		return false;
	}
	
}

// allows only numeric
function numberOnly(e) {
	if(window.event) {
		key = e.keyCode; // for IE, e.keyCode or window.event.keyCode can be used
	}
	else if(e.which) {
		key = e.which; // netscape
	}
	else {
		return true;// no event, so pass through
	}
	if( ((key>47) && (key<58)) || (key == 8) ) {
		return true; 
	}
	else {
		return false;
	}
	
}

// allows only numeric
function onlyNumeric(e) {
	if(window.event) {
		key = e.keyCode; // for IE, e.keyCode or window.event.keyCode can be used
	}
	else if(e.which) {
		key = e.which; // netscape
	}
	else {
		return true;// no event, so pass through
	}

	if(key == 8){
		return true; 
	}
	else if( ((key>=45) && (key<58)) ) {
		return true; 
	}
	else {
		return false;
	}
}

function checkEmail(strng){
	var error = "";
	var emailFilter=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if (strng == "") {
		error = "You didn't enter an email-address.\n";
	}
	
	else if (!(emailFilter.test(strng))){ 
		error = "Please enter a valid email address.\n";
	}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if (strng.match(illegalChars)){
		error = "The email address contains illegal characters.\n";
	}
	return error;
}

function checkPassword (strng) {
	var error = "";
	var illegalChars = /[\W_]/; 
	if (strng == "") {
		error = "You didn't enter password.\n";
	}
	
	if ((strng.length < 4) || (strng.length > 15))	{
  		error = "The password is of wrong length(valid length 4-15 chars).\n";
	}
	else if (illegalChars.test(strng)) {
		error = "The password contains illegal characters.\n";
	}
	return error;
}

// frame breaker code
if (top.location != location) {
	top.location.href = document.location.href ;
}

