
var isIE = document.all?true:false; //start  from this strat to end this works for mozilla

 

function anyMask(event, sMask) {
	//var sMask = "**?##?####";
	var KeyTyped = String.fromCharCode(getKeyCode(event));
	var targ = getTarget(event);
	
	keyCount = targ.value.length;
	//alert(sMask.charAt(keyCount));
	
	if (sMask.charAt(keyCount) == '*')
 	   	return true;
 
	if (sMask.charAt(keyCount) == KeyTyped)
    	{
		return true;
	}
	
	if ((sMask.charAt(keyCount) == '#') && isNumeric(KeyTyped)) 
	   return true; 
	
	if ((sMask.charAt(keyCount) == 'A') && isAlpha(KeyTyped))
         return true; 
    
      if ((sMask.charAt(keyCount) == '?') && isPunct(KeyTyped))
         return true; 
	if (KeyTyped.charCodeAt(0) < 32) return true;
    
    return false;	   
   
	
}

 function getTarget(e) {
  // IE5
   if (e.srcElement) {
   	return e.srcElement;
   }
    if (e.target) {
   	return e.target;
   }	
 }

  function getKeyCode(e) {
 //IE5
 if (e.srcElement) {
 	return e.keyCode
 }
  // NC5
  if (e.target) {
   return e.which
  }
 }

 function isNumeric(c)
{
	var sNumbers = "01234567890";
	if (sNumbers.indexOf(c) == -1)
		return false;
	else return true;
	
}  

function isAlpha(c)
{
	var lCode = c.charCodeAt(0);
	if (lCode >= 65 && lCode <= 122 )
 	  {	
		return true;
         }
	else 
	return false;
}  

function isPunct(c)
{
	var lCode = c.charCodeAt(0);
	if (lCode >= 32 && lCode <= 47 )
 	  {	
		return true;
         }
	else 
	return false;

}


function phoneMask(event)
  {
	var sMask = "01234567890";
	var KeyTyped = String.fromCharCode(getKeyCode(event));
	// IE only version var KeyTyped = String.fromCharCode(window.event.keyCode);
	// ** IE only var srcObject = window.event.srcElement;
	var targ = getTarget(event);
	//alert(window.event.keyCode);
	keyCount = targ.value.length;
	if (getKeyCode(event) < 15) /* del, backspace and other movement characters are okay */ {
	 	return true;		
  	} else if (sMask.indexOf(KeyTyped.toString()) == -1) {
				return false;
	}
	
    var tmpStr = "(";
    
    keyEntered = KeyTyped;
    keyCount++;
    switch (keyCount)
    {
    case 2: 
      tmpStr += targ.value;
      targ.value = tmpStr;
      break;
    case 5:
      targ.value += ")";
      break;
    case 9:
      targ.value += "-";
      break;
      }
    //return true;
 }
  

//  End -->











// Validation functions.
function Password_Check() {
	if (this.value != document.forms[0].Password.value){
	(this.value =""); return(this.xerror());
	}
return true;
}

function Email_Check() {
	if (this.value != document.forms[0].Email.value){
	(this.value =""); return(this.xerror());
	}
return true;
}

function checkForm() {
	getPopUp=0;
	if (validate_form()) {
	redo = true;
	setTimeout('submitForm()',300);
	}
}

function submitForm() {
document.forms[0].submit();
}

function showError(msgpat) {
	if (typeof(this.xerrmsg1) == "string") {
	this.xerrmsg = this.xerrmsg1 + this.value + this.xerrmsg2;
	}
alert(this.xerrmsg);
this.focus();
return false;
}

function isString() {
if (!this.value && this.xmin > 0) return(this.xerror());
	if (this.xmin > 0) {
	str = trimString(this.value);
		if (str.length < this.xmin) return(this.xerror());
	}
	if (this.value.length < this.xmin) return(this.xerror());
	if (this.value.length > this.maxLength) return(this.xerror());
return true;
}

function isNumStr() {
var str;
	if (!this.value && this.xmin > 0) return(this.xerror());
	if (this.value.match(/\D/)) return(this.xerror());
	if (this.value.length < this.xmin) return(this.xerror());
	if (this.value.length > this.maxlength) return(this.xerror());
return true;
}

function isPostal() {
code = this.value.replace(/\D/g, "");
	if (!code) return(this.xerror());
	if (code.length < this.xmin) return(this.xerror());
	if (code.length > this.xeditmax) return(this.xerror());
return true;
}








function isPhone() {
var phone;
var prefix;
var exchange;
var bad_no;
var msg;

	if (!this.value) return(this.xerror());

phone = this.value.replace(/\D/g, "");
prefix = phone.slice(0,3);
exchange = phone.slice(3,6);
bad_no = phone.slice(3,4);
msg = "The Phone Number you entered is invalid.  Please enter your evening Phone Number.";

	if (prefix == 000) return(alert(msg));this.focus();
	if (prefix == 555) return(alert(msg));this.focus();
	if (prefix == 700) return(alert(msg));this.focus();
	if (prefix == 800) return(alert(msg));this.focus();
	if (prefix == 888) return(alert(msg));this.focus();
	if (prefix == 900) return(alert(msg));this.focus();
	if (exchange == 555) return(alert(msg));this.focus();
	if (exchange == 000) return(alert(msg));this.focus();
	if (exchange == 976) return(alert(msg));this.focus();
	if (bad_no == 0) return(alert(msg));this.focus();
	if (phone.length < this.xmin) return(this.xerror());
	if (phone.length > this.xeditmax) return(this.xerror());

this.value = phone.replace(/^(\d\d\d)(\d\d\d)(\d\d\d\d)$/, "($1) $2-$3");
return true;
}

function editPostal(evt) {
IE = document.all;

	if (IE) {
	var keycode = window.event.keyCode;
	var shift   = window.event.shiftKey;
	var ctrl    = window.event.ctrlKey;
	var alt     = window.event.altKey;
	var pos     = this.value.length + 1;
	var upper   = (shift && !ctrl && !alt && keycode >= 65 && keycode <= 90);
	var lower   = (!shift && !ctrl && !alt && keycode >= 97 && keycode <= 122);
	var space   = (!shift && !ctrl && !alt && keycode == 32);
	var digit   = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);
		if (pos <= 5 && digit) return true;
		if (keycode == 13) checkForm(); return false;
	} else {
	keycode = evt.which;
	var bs = String.fromCharCode(evt.which);
		if (keycode == 13) checkForm();
		if (keycode >= 48 && keycode <= 57) return true;
		if (keycode == 0) return true;
		if (bs == "\b") return true;
	}
return false;
}

function editPhone(evt) {
IE = document.all;

        if (IE) {
        var keycode = window.event.keyCode;
        var shift   = window.event.shiftKey;
        var ctrl    = window.event.ctrlKey;
        var alt     = window.event.altKey;
        var pos     = this.value.length + 1;
        var lparen  = (shift  && !ctrl && !alt && keycode == 40);
        var rparen  = (shift  && !ctrl && !alt && keycode == 41);
        var space   = (!shift && !ctrl && !alt && keycode == 32);
        var dash    = (!shift && !ctrl && !alt && keycode == 45);
        var slash   = (!shift && !ctrl && !alt && keycode == 47);
        var digit   = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);

		if (keycode == 13) checkForm();
                if (!lparen && !rparen && !space && !dash && !digit) return false;
                if (pos == 1  && lparen) return true;
                if (pos == 1  && digit) { this.value = '('; return true; }
                if (pos == 2  && digit) return true;
                if (pos == 3  && digit) return true;
                if (pos == 4  && digit) return true;
                if (pos == 5  && rparen) { this.value += ') '; return false; }
                if (pos == 5  && dash)   { this.value += ') '; return false; }
                if (pos == 5  && slash)  { this.value += ') '; return false; }
                if (pos == 5  && space)  { this.value += ') '; return false; }
                if (pos == 5  && digit)  { this.value += ') '; return true; }
                if (pos == 6  && space) return true;
                if (pos == 6  && digit) { this.value += ' '; return true; }
                if (pos == 7  && digit) return true;
                if (pos == 8  && digit) return true;
                if (pos == 9  && digit) return true;
                if (pos == 10 && dash) return true;
                if (pos == 10 && space) { this.value += '-'; return false; }
                if (pos == 10 && digit) { this.value += '-'; return true; }
                if (pos == 11 && digit) return true;
                if (pos == 12 && digit) return true;
                if (pos == 13 && digit) return true;
                if (pos == 14 && digit) return true;
        } else {
        keycode = evt.which;
        var bs = String.fromCharCode(evt.which);
                if (keycode >= 48 && keycode <= 57) return true;
                if (keycode == 0) return true;
                if ((keycode == 32) || (keycode >= 40 && keycode <= 41) || (keycode >= 45 && keycode <= 46)) return true;
                if (bs == "\b") return true;
		if (keycode == 13) checkForm(); return false;
        }
return false;
}

function editEmail(evt) {
IE = document.all;

	if (IE) {
	var keycode = window.event.keyCode;
	var shift   = window.event.shiftKey;
	var ctrl    = window.event.ctrlKey;
	var alt     = window.event.altKey;
	var pos     = this.value.length + 1;
	var upper   = (shift && !ctrl && !alt && keycode >= 65 && keycode <= 90);
	var capsupper = (!shift && !ctrl && !alt && keycode == 39 && keycode >= 65 && keycode <= 90);
	var dash	= (!shift && !ctrl && !alt && keycode == 45);
	var underscore	= (shift && !ctrl && !alt && keycode == 95);
	var lower   = (!shift && !ctrl && !alt && keycode >= 97 && keycode <= 122);
	var digit   = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);
	var atsign  = (shift && !ctrl && !alt && keycode == 64);
	var dot  	= (!shift && !ctrl && !alt && keycode == 46);
		if (pos <= 50 && digit) return true;
		if (pos <= 50 && lower) return true;
		if (pos <= 50 && upper) return true;
		if (pos <= 50 && dot) return true;
		if (pos <= 50 && atsign) return true;
		if (pos <= 50 && underscore) return true;
		if (pos <= 50 && dash) return true;
		//if (pos <= 50 && capsupper) return true;
		
		if (keycode == 190) return true;
		if (keycode == 13) checkForm(); return false;
	} else {
	keycode = evt.which;
	var bs = String.fromCharCode(evt.which);
		if (keycode == 13) checkForm();
		if (keycode >= 48 && keycode <= 57) return true;
		if (keycode >= 97 && keycode <= 122) return true; //added this line to have it work with mozilla 1.4
		if (keycode == 64) return true; //added this line to have it work with mozilla 1.5
		if (!shift && !ctrl && !alt && keycode == 46) return true; //added this line to have it work with mozilla 1.5
		if (keycode == 0) return true;
		if (bs == "\b") return true;
	}
return false;
}







function hitReturn(evt) {
IE = document.all;
	if (IE) {
	keycode = window.event.keyCode;
	} else {
	keycode = evt.which;
	}
	if (keycode == 13) {
	checkForm(); return false;
	}
return;
}







function isEmail() {
code = this.value.replace(/\D/g, "");
	//if (this.value == "") return true;

var pattern =/.+@.+\..+/;

	if (this.value.match(pattern)) {
	return true;
	} else {
	return this.xerror();
	}
}



function isEmail2() {
code = this.value.replace(/\D/g, "");
	//if (this.value == "") return true;

var pattern =/.+@.+\..+/;

	if (this.value.match(pattern)) {
	return true;
	} else {
	return this.xerror();
	}
}





function trimString (str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function trimString (str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}





function wr4_isEmail(email) {
	if(email.indexOf('@') > -1 && email.indexOf('.') > -1) return true
	alert('Please specify a valid email address.'); return false ;
}




function wr4_isNull (str,tchar) {
	if (str.length == 0) {
	alert(friendlyName + ' can not be left blank.');return false;
	}
	while (str.indexOf(tchar) == 0 && str.length > 0) {
	str = str.substring(tchar.length);
	}
	while (str.lastIndexOf(tchar) == (str.length - (tchar.length)) && str.length > 0) {
	str = str.substring(0,(str.length - (tchar.length)));
	}
	if(str=="") {
	alert(friendlyName + ' can not be left blank.'); return false;
	}
return true;
}



function validate_form() {
	var elm, i;
	form = document.forms[0];
	for (i = 0; i < form.elements.length; i++) {
		elm = form.elements[i];
		if (elm.type == "hidden") continue;
		if (typeof(elm.xvalidate) == "function" && !elm.xvalidate()) return false;
	}

return true;
}
