String.prototype.trim=function(){a=this.replace(/^\s+/,'');return a.replace(/\s+$/,'');};function ltrim(s){return s.replace(/^\s*/,"")}
function rtrim(s){return s.replace(/\s*$/,"");}
function trim(s){return rtrim(ltrim(s));}
function validateEmailv2(email)
{if(email.length<=0)
{return true;}
var splitted=email.match("^(.+)@(.+)$");if(splitted==null)return false;if(splitted[1]!=null)
{var regexp_user=/^\"?[\w-_\.]*\"?$/;if(splitted[1].match(regexp_user)==null)return false;}
if(splitted[2]!=null)
{var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;if(splitted[2].match(regexp_domain)==null)
{var regexp_ip=/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;if(splitted[2].match(regexp_ip)==null)return false;}
return true;}
return false;}
function addValidation(strValidateStr,fieldID,strError)
{var epos=strValidateStr.search("=");var command="";var cmdvalue="";var theForm;if(epos>=0)
{command=strValidateStr.substring(0,epos);cmdvalue=strValidateStr.substr(epos+1);}
else
{command=strValidateStr;}
objValue=document.getElementById(fieldID);switch(command)
{case"req":case"required":{if(eval(objValue.value.trim().length)==0)
{if(!strError||strError.length==0)
{strError=objValue.name+" : Required Field";}
return strError+"\n";}
break;}
case"selectradio":{var sel=new Array();sel=document.getElementsByName(fieldID);var flagCheck=0;for(i=0;i<sel.length;i++)
{if(sel[i].checked==true)
flagCheck=1;}
if(flagCheck==0)
{return strError+"\n";}
break;}
case"maxlength":case"maxlen":{if(eval(objValue.value.length)>eval(cmdvalue))
{if(!strError||strError.length==0)
{strError=objValue.name+" : "+cmdvalue+" characters maximum ";}
return strError+"\n";}
break;}
case"fixlen":case"fixlength":{if(eval(objValue.value.length)!=eval(cmdvalue))
{if(!strError||strError.length==0)
{strError=objValue.name+" : "+cmdvalue+" characters maximum ";}
return strError+"\n";}
break;}
case"minlength":case"minlen":{if(eval(objValue.value.length)<eval(cmdvalue))
{if(!strError||strError.length==0)
{strError=objValue.name+" : "+cmdvalue+" characters minimum  ";}
return strError+"\n";}
break;}
case"alnum":case"alphanumeric":{var charpos=objValue.value.search("[^A-Z a-z 0-9]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": Only alpha-numeric characters allowed ";}
return strError+"\n";}
break;}
case"num":case"numeric":{var charpos=objValue.value.search("[^0-9\.]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": Only digits allowed ";}
return strError+"\n";}
break;}
case"cc":{if(!objValue.value.match(/^\d{1,20}$|^\*{8,15}\d{4,4}$/))
{return strError+"\n";}
break;}
case"dec":case"decimal":{if(!objValue.value.match(/^\d{1,10}$|^\d+\.\d{1,2}?$/))
{return strError+"\n";}
break;}
case"mobile":{if(objValue.value!='')
{var stripped=objValue.value.replace(/[\(\)\.\-\+\ ]/g,'');if(isNaN(parseInt(stripped))){if(!strError||strError.length==0)
{strError=objValue.name+": Only digits allowed ";}
return strError+"\n";}
break;}
break;}
case"alphabetic":case"alpha":{var charpos=objValue.value.search("[^A-Za-z]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": Only alphabetic characters allowed ";}
return strError+"\n";}
break;}
case"alphaspace":{var charpos=objValue.value.search("[^A-Za-z \ ]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": Only alphabetic characters allowed ";}
return strError+"\n";}
break;}
case"alnumhyphen":{var charpos=objValue.value.search("[^A-Za-z0-9\-_\.]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";}
return strError+"\n";}
break;}
case"timeValidate":{var charpos=objValue.value.search("[^0-9{2}\:\0-9{2}$]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";}
return strError+"\n";}
break;}
case"alnumhyphenONLY":{var charpos=objValue.value.search("[^A-Za-z0-9\-]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9 and -";}
return strError+"\n";}
break;}
case"alnumhyphenCAPSONLY":{var charpos=objValue.value.match("^[A-Z]{3}\-[0-9]{3}$");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": not a valid input";}
return strError+"\n";}
break;}
case"valid_name":{if(objValue.value!='')
{var stripped=objValue.value.replace(/[\ ]/g,'');var charpos=stripped.search("[^A-Za-z\-\'\.]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9,- and '";}
return strError+"\n";}
break;}
break;}
case"user_name":{if(objValue.value!='')
{var stripped=objValue.value.replace(/[\ ]/g,'');var charpos=stripped.search("[^A-Za-z0-9\-\.\_]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9,- and '";}
return strError+"\n";}
break;}
break;}
case"valid_subdomain":{if(objValue.value!='')
{var stripped=objValue.value;var charpos=stripped.search("[^A-Za-z0-9\-]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9,- and '";}
return strError+"\n";}
break;}
break;}
case"space":{var vlen=objValue.value.length;var stripped=objValue.value.replace(/[\ ]/g,'');if(vlen!=stripped.length)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9,- and '";}
return strError+"\n";}
break;}
case"valid_date":{alert(objValue.value);if(objValue.value!='mm/dd/yyyy')
{var charpos=objValue.value.search("[^0-9\/]");if((objValue.value.length>0&&charpos>=0)||(objValue.value.length>0&&objValue.value.length!=10))
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are 0-9 and /";}
return strError+"\n";}
break;}
break;}
case"alphahyphen":{var charpos=objValue.value.search("[^A-Za-z\-_]");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";}
return strError+"\n";}
break;}
case"alphaquote":{var charpos=objValue.value.search("[^A-Za-z\']");if(objValue.value.length>0&&charpos>=0)
{if(!strError||strError.length==0)
{strError=objValue.name+": characters allowed are A-Z,a-z and ' ";}
return strError+"\n";}
break;}
case"email":{if(!validateEmailv2(objValue.value))
{if(!strError||strError.length==0)
{strError=objValue.name+": Enter a valid Email address ";}
return strError+"\n";}
break;}
case"emails":{str=objValue.value;values=str.split(",");for(var i=0;i<values.length;i++)
{var email=trim(values[i]);if(!validateEmailv2(email))
{if(!strError||strError.length==0)
{strError="Enter a valid Email addresses ";}
return strError+"\n";break;}else
{continue;}}
break;}
case"max_emails":{str=objValue.value;values=str.split(",");if(values.length>eval(cmdvalue))
{strError="Enter maximum "+cmdvalue+" Email Address.";return strError+"\n";}
break;}
case"lt":case"lessthan":{if(isNaN(objValue.value))
{if(!strError||strError.length==0)
{strError=objValue.name+": Should be a number ";}
return strError+"\n";}
else if(eval(objValue.value)>=eval(cmdvalue))
{if(!strError||strError.length==0)
{strError=objValue.name+" : value should be less than "+cmdvalue;}
return strError+"\n";}
break;}
case"gt":case"greaterthan":{if(isNaN(objValue.value))
{if(!strError||strError.length==0)
{strError=objValue.name+": Should be a number ";}
return strError+"\n";}
else if(eval(objValue.value)<=eval(cmdvalue))
{if(!strError||strError.length==0)
{strError=objValue.name+" : value should be greater than "+cmdvalue;}
return strError+"\n";}
break;}
case"regexp":{if(objValue.value.length>0)
{if(!objValue.value.match(cmdvalue))
{if(!strError||strError.length==0)
{strError=objValue.name+": Invalid characters found ";}
return strError+"\n";}}
break;}
case"dontselect":{if(objValue.selectedIndex==null)
{return"BUG: dontselect command for non-select Item";}
if(objValue.selectedIndex==eval(cmdvalue))
{if(!strError||strError.length==0)
{strError=objValue.name+": Please Select one option ";}
return strError+"\n";}
break;}
case"match":{if(objValue.value!=document.getElementById(cmdvalue).value)
{if(!strError||strError.length==0)
{strError=objValue.name+": Must be same";}
return strError+"\n";}
break;}
case"today_dt_chk":{var myDate=new Date;var today=new Date;tMonth=today.getMonth()+1;tYear=today.getFullYear();myDate.setMonth(document.getElementById(cmdvalue).value);myDate.setFullYear(objValue.value);eMonth=myDate.getMonth();eYear=myDate.getFullYear();if(((tMonth>eMonth)&&(tYear==eYear))||(tYear>eYear))
{strError="Please select valid expiration date.";return strError+"\n";}
break;}
case"notmatch":{valueOne=objValue.value.toUpperCase();;valueTwo=document.getElementById(cmdvalue).value.toUpperCase();;if(valueOne==valueTwo)
{if(!strError||strError.length==0)
{strError=objValue.name+": Must be same";}
return strError+"\n";}
break;}
case"validTime":{var timeT=objValue.value;var status=checkTime(timeT)
if(!status)
{if(!strError||strError.length==0)
{strError='Please enter valid Accessibility Details';}
return strError+"\n";}
break;}
case"compairValue":{if(objValue.value<=document.getElementById(cmdvalue).value)
{if(!strError||strError.length==0)
{strError="From time should be less than to time ";}
return strError+"\n";}
break;}
case"compareDate":{str_fromdate=objValue.value
str_todate=document.getElementById(cmdvalue).value;strError=CompareDates(str_fromdate,str_todate);if(strError.length!=0)
{return strError+"\n";}
break;}
case"compareDate12":{str_fromdate=objValue.value
str_todate=document.getElementById(cmdvalue).value;strError=CompareDates12(str_fromdate,str_todate);if(strError.length!=0)
{return strError+"\n";}
break;}
case"valid_url":{if(!/^(http:\/\/)(?:[\w-]+\.)+[a-z]{2,6}$/.test(objValue.value))
{if(!strError||strError.length==0)
{strError="Invalid Url";}
return strError+"\n";}
break;}
case"valid_url_without_http":{if(!/^(?:[\w-]+\.)+([a-z]{2,6})([\- \/ \.]*[\w])*$/.test(objValue.value))
{if(!strError||strError.length==0)
{strError="Invalid Url";}
return strError+"\n";}
break;}
case"optional_name":{if(eval(objValue.value.trim().length)!=0)
{return eval(objValue.value.trim().length);}
else return 0;break;}
case"is_date":if(isDate(fieldID)!=true)
return strError+"\n";default:break;}
return'';}
function CheckUncheckAll(fmobj,tabid1,tabid2){var TotalBoxes=0;var TotalOn=0;for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name!='checkall')&&(e.type=='checkbox')){TotalBoxes++;if(e.checked){TotalOn++;}}}
if(TotalBoxes>TotalOn)
{for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name!='checkall')&&(e.type=='checkbox')&&(!e.disabled)){e.checked=true;}}}
else
{for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name!='checkall')&&(e.type=='checkbox')&&(!e.disabled)){e.checked=false;}}}}
function CheckUncheckAllc(fmobj){var TotalBoxes=0;var TotalOn=0;for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name!='checkall')&&(e.type=='checkbox')){TotalBoxes++;if(e.checked){TotalOn++;}}}
if(TotalBoxes>TotalOn+1)
{for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name!='checkall')&&(e.type=='checkbox')&&(!e.disabled)){e.checked=true;}}}
else
{for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name!='checkall')&&(e.type=='checkbox')&&(!e.disabled)){e.checked=false;}}}}
function CheckUncheckAllcheckbox(fmobj,checkboxname,topcheckbox){var TotalBoxes=0;var TotalOn=0;for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name==checkboxname)&&(e.type=='checkbox')){TotalBoxes++;if(e.checked){TotalOn++;}}}
if(TotalBoxes>TotalOn)
{for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name==checkboxname)&&(e.type=='checkbox')&&(!e.disabled)){e.checked=true;}}}
else
{for(var i=0;i<fmobj.elements.length;i++){var e=fmobj.elements[i];if((e.name==checkboxname||e.name==topcheckbox)&&(e.type=='checkbox')&&(!e.disabled)){e.checked=false;}}}}
function CheckUncheckAllcheckbox(theForm,checkbox,checkbox_all)
{var set=document.getElementsByName(checkbox_all);checkboxes=document.getElementsByName(checkbox);for(var i=0;i<checkboxes.length;i++)
{if(checkboxes[i].disabled==false)
checkboxes[i].checked=set[0].checked;}}
function focused(elementId)
{re=/fieldbg/gi;elementId.className+=' fieldbg';}
function nonfocused(elementId)
{re=/fieldbg/gi;elementId.className=elementId.className.replace(re,'');}
function delete_single(strval)
{if(confirm("Are you sure you want to delete selected record?"))
{window.location=strval;}
else
{return false;}}
function checkTime(s){if(s==null)return false;if(s.indexOf(":")==-1)return false;var spl=s.split(":");if(parseInt(spl[0],10)==24&&parseInt(spl[1],10)==00)
{return true;}
else
{return parseInt(spl[0],10)<24&&parseInt(spl[1],10)<60;}}
function CompareDates(str_fromdate,str_todate)
{var str="";var fromDate=(str_fromdate).split("/");var toDate=(str_todate).split("/");var date1=new Date(fromDate[2],fromDate[0],fromDate[1]);var date2=new Date(toDate[2],toDate[0],toDate[1]);if((Date.parse(date2)-Date.parse(date1))>0)
{str="To date cannot be greater than from date";}
return str;}
function CompareDates12(str_fromdate,str_todate)
{var str="";var fromDate=(str_fromdate).split("/");var toDate=(str_todate).split("/");var date1=new Date(fromDate[2],fromDate[0],fromDate[1]);var date2=new Date(toDate[2],toDate[0],toDate[1]);var diff=(Date.parse(date1)-Date.parse(date2));diff=Math.floor(diff/1000/60/60/24/30);if(diff>12)
{str="Date range should not be greater than to 12 months";}
else if((fromDate[0]==toDate[0])&&(fromDate[2]!=toDate[2]))
{str="Date range should not be greater than to 12 months";}
return str;}
function checkImageType(imagePath){var pathLength=imagePath.length;var lastDot=imagePath.lastIndexOf(".");var fileType=imagePath.substring(lastDot,pathLength);if((fileType==".gif")||(fileType==".jpg")||(fileType==".png")||(fileType==".GIF")||(fileType==".JPG")||(fileType==".PNG")){return false;}else{return true;}}
function checkDocType(docPath){var pathLength=docPath.length;var lastDot=docPath.lastIndexOf(".");var fileType=docPath.substring(lastDot,pathLength);if((fileType==".doc")||(fileType==".docx")||(fileType==".rtf")||(fileType==".pdf")||(fileType==".txt")||(fileType==".DOC")||(fileType==".DOCX")||(fileType==".RTF")||(fileType==".PDF")||(fileType==".TXT")){return false;}else{return true;}}
function datediff(sStartDate,sEndDate){var arrTmpED=sStartDate.split("-");var arrTmpEXD=sEndDate.split("-");sStartDate=arrTmpED[0]+"/"+arrTmpED[1]+"/"+arrTmpED[2];sEndDate=arrTmpEXD[0]+"/"+arrTmpEXD[1]+"/"+arrTmpEXD[2];dtStartDate=new Date(sStartDate);dtEndDate=new Date(sEndDate);var bReturn=true;if(dtStartDate>=dtEndDate){bReturn=false;}
else{bReturn=true;}
return bReturn;}
var dtCh="/";var minYear=1900;var maxYear=2100;function isInteger(s){var i;for(i=0;i<s.length;i++){var c=s.charAt(i);if(((c<"0")||(c>"9")))return false;}
return true;}
function stripCharsInBag(s,bag){var i;var 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){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){return false}
if(strMonth.length<1||month<1||month>12){return false}
if(strDay.length<1||day<1||day>31||(month==2&&day>daysInFebruary(year))||day>daysInMonth[month]){return false}
if(strYear.length!=4||year==0||year<minYear||year>maxYear){return false}
if(dtStr.indexOf(dtCh,pos2+1)!=-1||isInteger(stripCharsInBag(dtStr,dtCh))==false){return false}
return true}