
function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
}

function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)")
			return false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		//alert("The username doesn't seem to be valid in Email Address.")
				   			return false;
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid in Email!")
										return false;
			}
		}
		return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid in Email Address.")
								return false;
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>4) {
		//alert("The address must end in a three-letter domain, or two letter country in Email.")
				   			return false;
	}
	if (len<2) {
		var errStr="This address is missing a hostname! in Email Address"
		//alert(errStr);
			   			return false;
	}
	return true;
}

function numbersonly(e) 
{ 
// alphabet with blankspace
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8)
{
if (unicode>47 && unicode<58)//numbers
{return true;}
if (unicode==13 || unicode==9 || unicode==37 || unicode==39) //carriage return, tab, arrow keys
{return true;}

unicode=0;
return false;
}
}

function decimalonly(e)
{
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8)
{
if (unicode>47 && unicode<58)//numbers
{return true;}
if (unicode==13 || unicode==9 || unicode==46 || unicode==37 || unicode==39) //carriage return, tab, dot
{return true;}

unicode=0;
return false;
}
}

function alphabetsonly(e) 
{ 
// alphabet with blankspace
var unicode=e.charCode? e.charCode : e.keyCode

if (unicode!=8)
{
if (unicode>96 && unicode<123)//smal
{return true;}
if (unicode>64 && unicode<91) //cabs
{return true;}
if (unicode==32 || unicode==13 || unicode==9 || unicode==37 || unicode==39) //blankspace, carriage return, tab
{return true;}

unicode=0;
return false;
}
}

function alphanumbersonly(e) 
{ 
// alphabet with blankspace
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8)
{
if (unicode>47 && unicode<58)//numbers
{return true;}
if (unicode>96 && unicode<123)//smal
{return true;}
if (unicode>64 && unicode<91) //cabs
{return true;}
if (unicode==32 || unicode==13 || unicode==9 || unicode==37 || unicode==39) //blankspace, carriage return, tab
{return true;}

unicode=0;
return false;
}
}

function alphanumericspecialcharsonly(e) 
{ 
// alphabet with blankspace
var unicode=e.charCode? e.charCode : e.keyCode

if (unicode!=8)
{
if (unicode>39 && unicode<59)//numbers and special characters
{return true;}
if (unicode>96 && unicode<123)//smal
{return true;}
if (unicode>62 && unicode<91) //cabs
{return true;}
if (unicode==63 || unicode== 35) //#, ?
{return true;}
if (unicode==32 || unicode==13 || unicode==9 || unicode==37 || unicode==39 || unicode==60 || unicode==61) //blankspace, carriage return, tab
{return true;}

unicode=0;
return false;
}
}

function emailonly(e) 
{ 
// alphabet with blankspace
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8)
{
if (unicode>47 && unicode<58)//numbers
{return true;}
if (unicode>96 && unicode<123)//smal
{return true;}
if (unicode>64 && unicode<91) //cabs
{return true;}
if (unicode==13 || unicode==9  || unicode==45  || unicode==46 || unicode==64 || unicode==95 || unicode==37 || unicode==39) //carriage return, tab, @, _, ., -
{return true;}

unicode=0;
return false;
}
}

function limitlength(obj, length){
var maxlength=length
if (obj.value.length>maxlength)
obj.value=obj.value.substring(0, maxlength)
}


function jm_phonemask(t)
    {
        var patt1 = /(\d{3}).*(\d{3}).*(\d{4})/;
        var patt2 = /^\((\d{3})\).(\d{3})-(\d{4})$/;
        var str = t.value;
        var result;
        if (str != '')
        {
            if (!str.match(patt2))
            {   
                result = str.match(patt1);
                if (result!= null)
                {
                    t.value = t.value.replace(/[^\d]/gi,'');
                    //str = '(' + result[1] + ') ' + result[2] + '-' + result[3];
                    str = result[1] + '-' + result[2] + '-' + result[3];
                    t.value = str;
                }
                else
                {
                    if (t.value.match(/[^\d]/gi))
                    t.value = t.value.replace(/[^\d]/gi,'');
                }
            }
        }
    }

function phonecheck(zipcode)
{
	var checkOK = "0123456789";
	var checkStr; 
	var allValid = true;
	var allNum = "";
	checkStr = zipcode;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
	allValid = false;
	break;
	}
	if (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
	return (false);
	}
}

function namecheckuname(name)
{
	 var string="";
	  var str=name;
  for(var i=0;i < str.length;i++)
      {
	  ch = str.substring(i,i+1);
      for(var j=0;j< string.length;j++)
		 {
	 if(ch==string.substring(j,j+1))
			 {
		 return false;
		 }
		 }
     	 }
		 return true;
}

function namecheck(name)
{
	var string="0123456789*!#^()|?<>-+@_$&=%";	
	  var str=name;
  for(var i=0;i < str.length;i++)
      {
	  ch = str.substring(i,i+1);
      for(var j=0;j< string.length;j++)
		 {
	 if(ch==string.substring(j,j+1))
			 {
		 return false;
		 }
		 }
     	 }
		 return true;
}
function zipcodecheck(name)
{
	 var string="*!#^()|?<>-+@_$&=%";
	  var str=name;
  for(var i=0;i < str.length;i++)
      {
	  ch = str.substring(i,i+1);
      for(var j=0;j< string.length;j++)
		 {
	 if(ch==string.substring(j,j+1))
			 {
		 return false;
		 }
		 }
     	 }
		 return true;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 DecimalCheck(strVal) 
    {
        var txttext=strVal;
        var regex=/^[-+]?\d{0,10}(\.\d{1,2})?$/;
        return regex.test(txttext);
    }
    
    function IntegerCheck(strVal) 
    {
        var txttext=strVal;
        var regex=/^\d{0,10}$/;
        return regex.test(txttext);
    }
    
    function getDateObject(dateString,dateSeperator)
    {
	    var curValue=dateString;
	    var sepChar=dateSeperator;
	    var curPos=0;
	    var cDate,cMonth,cYear;

	    curPos=dateString.indexOf(sepChar);
	    cMonth=dateString.substring(0,curPos);
    	
	    endPos=dateString.indexOf(sepChar,curPos+1);			
	    cDate=dateString.substring(curPos+1,endPos);

	    curPos=endPos;
	    endPos=curPos+5;			
	    cYear=curValue.substring(curPos+1,endPos);
    	
	    dtObject=new Date(cYear,cMonth,cDate);	
	    return dtObject;
    }
    
    function getPrint(print_area)
    {
        //Creating new page
        var pp = window.open();
        //Adding HTML opening tag with <HEAD> … </HEAD> portion 
        pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
        pp.document.writeln('<LINK href=Styles.css type="text/css" rel="stylesheet">')
        pp.document.writeln('<LINK href=PrintStyle.css ' + 
                            'type="text/css" rel="stylesheet" media="print">')
        pp.document.writeln('<base target="_self"></HEAD>')

        //Adding Body Tag
        pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
        pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
        //Adding form Tag
        pp.document.writeln('<form method="post">');

        //Creating two buttons Print and Close within a HTML table
        pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
        pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');
        pp.document.writeln('onclick="javascript:location.reload(true);window.print();">');
        pp.document.writeln('<INPUT ID="CLOSE" type="button" ' + 
                            'value="Close" onclick="window.close();">');
        pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');

        //Writing print area of the calling page
        pp.document.writeln(document.getElementById(print_area).innerHTML);
        //Ending Tag of </form>, </body> and </HTML>
        pp.document.writeln('</form></body></HTML>'); 
    }

