	function validateLoginPage()		
		{	
			var theform = document.LoginPage;			
			if(checkEmpty(theform.userid,"CIMB Clicks ID")==false) return false;
			if(checkEmpty(theform.password, "CIMB Clicks Password")==false) return false;
			// if(validateLength(theform.password, "CIMB Clicks Password",6,8)==false) return false;
			showSlowMessage();	
			return true;
		}		
				
		function checkEmpty(field,fieldName) {
			if(field.value == null || field.value.length == 0) {
			alert(fieldName + " is Mandatory");
			field.focus();
			return false;
			}
		}	

	function validateChangeOfCardPage()		
		{	
			var theform = document.ecChangeOfCardPage;			
			var fieldNameArray = new Array("New BankCard /Credit Card Number" , "New e-PIN", "Password");
			if(checkEmpty(theform.cardNo,fieldNameArray[0])==false) return false;
			if(checkEmpty(theform.ePin, fieldNameArray[1])==false) return false;
			if(checkEmpty(theform.password, fieldNameArray[2])==false) return false;                  		
			
			if(validateLength(theform.cardNo, fieldNameArray[0],16,16)==false) return false; 
			if(validateLength(theform.ePin, fieldNameArray[1],6,6)==false) return false; 
			if(validateLength(theform.password, fieldNameArray[2],8,8)==false) return false;                  		

			return true;

		}				
            
      // Trim whitespace from left and right sides of s.
	function trim(s) {
  		return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
	}
		
		
	var messageInvalidLength="Invalid Length for ";
	function validateLength(field, fieldName, minLength, maxLength) {            
		if (minLength == '' && maxLength == '')
		  return true
		else if (minLength != '' && maxLength != '') {
		  if (trim(field.value).length < minLength || trim(field.value).length > maxLength) {
			field.focus()			
			alert(messageInvalidLength + fieldName)
			return false
		  } else 
			return true
		}
		else if (minLength != '' && maxLength == '') {
		  if (trim(field.value).length < minLength) {
			field.focus()			
			alert(messageInvalidLength + fieldName)
			return false
		} else
			return true
		}
		else if (minLength == '' && maxLength != '') {
		  if (trim(field.value).length > maxLength) {
			field.focus()			
			alert(messageInvalidLength + fieldName)
			return false			
		 } else
			return true
	     }
	     else
		 return false
	}
     
	/*
 	 * Validate key stroke - allow digit only
       * @handleEvent onkeypress, onblur
       * @return true if the key stroke is digit; false otherwise
       */
	function integerKey(obj) {
  		var event = window.event;
  		key = String.fromCharCode(event.keyCode);
  		if (isNaN(key))
    			return false;
  		else 
    		obj.value = obj.value.replace(/\D/g, "");
	} 

function showSlowMessage() {
		delay = 30;
		
		setTimeout("showModal()", delay*1000);
	}
	
	function showModal() {
		Modalbox.show('<div class=\'bodytext\'><p>We are currently encountering high traffic volumes on CIMB Clicks.</p>  <p>You may experience delayed response when you attempt to log in.  We are rectifying the issue now.  Please try again later.</p><p>Thank you for your patience and we apologise for the inconvenience caused.</p> <input type=\'button\' value=\'Close\' onclick=\'Modalbox.hide()\' /></div>', {title: this.title, width: 400});	
	}


