
var letters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var name_letters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\'';
var address_letters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var numbers='1234567890';
var address_letters_a = '.,-#';
var address_letters_b = '-#';
var signs_1='.,';
var signs_2='-_#$';
var signs_3='@.-_';
var signs_4='#$&!@.-_';
var email_chars='@_.-';
var choose_username_chars='_.-';
var phone_char='-';

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters; //+ "+";
var minDigitsInIPhoneNumber = 10;
var validEmailChars = "_.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVQXYZ1234567890@-";
//var account_name1="TEST";
//CHANGE these variables with actual one.
//var account_id = '3434asdf343';
//var account_firstname = 'TEST';

function ltrim(stringToTrim) {
        return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
        return stringToTrim.replace(/\s+$/,"");
}

function printpage() {
window.print();
}

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 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 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 <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		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 (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 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 n_customMsg(message, elementname) {

if(elementname) 
	document.getElementById(elementname).innerHTML=message;
else
	document.getElementById("error_string").innerHTML = message;

document.getElementById("error_message").style.display = 'block'; 

//return false;

}

 function getScreenCenterY() {
 var y = 0;

 y = getScrollOffset()+(getInnerHeight()/2);

 return(y);
 }

 function getScreenCenterX() {
 return(document.body.clientWidth/2);
 }

 function getInnerHeight() {
 var y;
 if (self.innerHeight) // all except Explorer
 {
 y = self.innerHeight;
 }
 else if (document.documentElement && document.documentElement.clientHeight)
 // Explorer 6 Strict Mode
 {
 y = document.documentElement.clientHeight;
 }
 else if (document.body) // other Explorers
 {
 y = document.body.clientHeight;
 }
 return(y);
 }

 function getScrollOffset() {
 var y;
 if (self.pageYOffset) // all except Explorer
 {
 y = self.pageYOffset;
 }
 else if (document.documentElement && document.documentElement.scrollTop)
 // Explorer 6 Strict
 {
 y = document.documentElement.scrollTop;
 }
 else if (document.body) // all other Explorers
 {
 y = document.body.scrollTop;
 }
 return(y);
 }

function alpha(e,allow) {
        var k;
        if(e.which==8) return true;
        if(e.which==13) return true;
        if(e.which==0) return true;
        if(e.which==37) return true;
        if(e.which==38) return true;
        if(e.which==39) return true;
        if(e.which==40) return true;
        if(e.which==46) return true;
        k=document.all?parseInt(e.keyCode): parseInt(e.which);
        return (allow.indexOf(String.fromCharCode(k))!=-1);
}

function extjs_alpha(e,allow) {
        var k;
        if(e.getKey()==8) return true;
        if(e.getKey()==13) return true;
        if(e.getKey()==0) return true;
        if(e.getKey()==37) return true;
        if(e.getKey()==38) return true;
        if(e.getKey()==39) return true;
        if(e.getKey()==40) return true;
        if(e.getKey()==46) return true;

        k=document.all?parseInt(e.getCharCode()): parseInt(e.getKey());
        return (allow.indexOf(String.fromCharCode(k))!=-1);
}

function extjs_control(e) {
        if(e.getKey()==8) return true;
        if(e.getKey()==13) return true;
        if(e.getKey()==0) return true;
        if(e.getKey()==37) return true;
        if(e.getKey()==38) return true;
        if(e.getKey()==39) return true;
        if(e.getKey()==40) return true;

	return false;
}


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){
                   n_customMsg("Invalid Email Address")
                   return false
                }

                if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
                   n_customMsg("Invalid Email Address")
                   return false
                }

                if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
                    n_customMsg("Invalid Email Address")
                    return false
                }

                 if (str.indexOf(at,(lat+1))!=-1){
                    n_customMsg("Invalid Email Address")
                    return false
                 }

                 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
                    n_customMsg("Invalid Email Address")
                    return false
                 }

                 if (str.indexOf(dot,(lat+2))==-1){
                    n_customMsg("Invalid Email Address")
                    return false
                 }

                 if (str.indexOf(" ")!=-1){
                    n_customMsg("Invalid Email Address")
                    return false
                 }

                 return true
}

function show_footer_window(title, filename) {

	return false;
}

function validate_email_str(email, 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 < email.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = email.charAt(i);
        if (bag.indexOf(c) == -1)
                return false;
    }
    return true;
}


function validateZIP(field) {
        var valid = "0123456789";
        var hyphencount = 0;

/*      if (field.length!=5 && field.length!=10) {
                customMsg("Please enter your 5 digit or 5 digit+4 zip code.");
                return false;
        }
*/
      if (field.length!=5) {
                n_customMsg("Please enter your 5 digit zip code.");
                return false;
        }

        for (var i=0; i < field.length; i++) {
                temp = "" + field.substring(i, i+1);
                if (temp == "-") hyphencount++;
                if (valid.indexOf(temp) == "-1") {
                        n_customMsg("Invalid characters in your zip code.  Please try again.");
                        return false;
                }
                if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
                        n_customMsg("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again.");
                        return false;
                }
        }
        return true;
}

function set_style(elementname, stylename) {
        document.getElementById(elementname).setAttribute('class', stylename);
        document.getElementById(elementname).setAttribute('className', stylename);


}

