
var W3CDOM=(document.getElementsByTagName&&document.createElement);var fldsarr;var msgsarr;var msgtype;var errors;function DomValidate(flds,msgs)
{this.fldsarr=flds;this.msgsarr=msgs;this.txtClass="";this.validateForm=validateForm;this.validatetype=validatetype;this.writeError=writeError;this.removeError=removeError;this.name=name_str;this.trim=trim;this.nsname=nsname;this.phno=phno;this.required=required;this.errors=errors;this.msgtype=msgtype;this.writeErrors=writeErrors;this.email=email;this.usphone=usphone;this.url=url;this.ip=ip;this.mobile=mobile;this.postcode=postcode;this.number=number;this.namelen=namelen;this.ccv_3=ccv_3;this.visa_num=visa_num;this.master_num=master_num;}
function validateForm(frmname)
{var status;validForm=true;firstError=null;errorstring='';this.errors='';status=true;for(var i=0;i<this.fldsarr.length;i++)
{var x=eval("document."+frmname).elements[this.fldsarr[i][0]];this.fldsarr[i][2]=Array();x.statusArr=Array();for(var k=0;k<this.fldsarr[i][1].length;k++)
{if(this.validatetype(x,this.fldsarr[i][1][k],this.msgsarr[i][1][k]))
{this.fldsarr[i][2][k]='t';if(!inArray(this.fldsarr[i][2],'f')){this.removeError(x);}}
else
{status=false;this.fldsarr[i][2][k]='f';}
x.statusArr=this.fldsarr[i][2];}}
if(this.msgtype=='all')
{this.writeErrors(this.errors);}
return status;}
function validatetype(obj,type,msg)
{switch(type)
{case'comments':return this.comments(obj,msg);break;case'required':return this.required(obj,msg);break;case'email':return this.email(obj,msg);break;case'phno':return this.phno(obj,msg);break;case'name':return this.name(obj,msg);break;case'trim':return this.trim(obj,msg);break;case'nsname':return this.nsname(obj,msg);break;case'usphone':return this.usphone(obj,msg);break;case'url':return this.url(obj,msg);break;case'ip':return this.ip(obj,msg);break;case'mobile':return this.mobile(obj,msg);break;case'postcode':return this.postcode(obj,msg);break;case'number':return this.number(obj,msg);break;case'checkfile':return this.checkfile(obj,msg);break;case'namelen':return this.namelen(obj,msg);break;case'ccv_3':return this.ccv_3(obj,msg);break;case'visa_num':return this.visa_num(obj,msg);break;case'master_num':return this.master_num(obj,msg);break;}}
function required(obj,msg)
{switch(obj.type)
{case'checkbox':return check_boxes(obj,msg);break;case'radio':return check_boxes(obj,msg);break;case'select':if(obj.selected==false)
{if(!msg)
{this.writeError(obj,'This field is required');}else{this.writeError(obj,msg);}
return false;}
break;case'select-multiple':var isSelected=false;for(var j=0;j<obj.options.length;j++)
{if(obj.options[j].selected)
{isSelected=true;}}
if(!isSelected){if(!msg)
{this.writeError(obj,'This field is required');}else{this.writeError(obj,msg);}
return isSelected;}
break;default:if(!obj.value)
{if(!msg)
{this.writeError(obj,'This field is required');}else{this.writeError(obj,msg);}
return false;}}
return true;}
function check_boxes(obj,msg)
{if(!isArray(obj))
{if(obj.checked==false)
{if(!msg)
{this.writeError(obj,'This field is required');}else{this.writeError(obj,msg);}
return false;}}else{for(var i=0;i<=obj.length;i++)
{if(obj[i].checked==false)
{if(!msg)
{this.writeError(obj[i],'This field is required');}else{this.writeError(obj[i],msg);}
return false;}}}
return true;}
function writeError(obj,message)
{validForm=false;if(W3CDOM)
{obj.style.border="1px solid #FF0000";obj.title=message;obj.alt=message;obj.setAttribute('alt',message);obj.setAttribute('title',message);if(obj.hasError)
{if(!inArray(obj.statusArr,'f')){this.errors+=message+"<br />";}
return false;}else{if(!inArray(obj.statusArr,'f')){this.errors+=message+"<br />";}}
if(obj.type=="checkbox"||obj.type=="radio")
{if(document.getElementById(obj.name+'_'+obj.type+'_span'))
{var sp=document.getElementById(obj.name+'_'+obj.type+'_span');}else{var sp=document.createElement('span');}
sp.id=obj.name+'_'+obj.type+'_span';sp.className='error';sp.innerHTML="&laquo;";obj.parentNode.appendChild(sp);}
obj.hasError=sp;}else{errorstring+=obj.name+': '+message+'\n';obj.hasError=true;}}
function writeErrors(message)
{var oElement;if(document.getElementById("showallerrors")){oElement=document.getElementById("showallerrors");oElement.style.display="block";oElement.innerHTML=message;}else{alert('Please create a div with "showallerrors" as id');}
var iElement;}
function DOMVALremoveError(obj,clsname)
{}
function removeError(obj)
{obj.style.border=this.txtClass;if(document.getElementById(obj.name+'_'+obj.type+'_span'))
{var k=document.getElementById(obj.name+'_'+obj.type+'_span');k.innerHTML="";}
obj.hasError=false;}
function email(obj,msg)
{if(obj.value)
{if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value))
{return true;}else{if(!msg)
this.writeError(obj,'Please enter a valid email address');else this.writeError(obj,msg);return false;}}
return true;}
function phno(obj,msg)
{if(obj.value)
{var stripped=obj.value.replace(/[\(\)\[\]\.\-\+\ ]/g,'');if(isNaN(parseInt(stripped)))
{if(!msg)
this.writeError(obj,'Please enter a valid Phone Number');else this.writeError(obj,msg);return false;}
if(stripped.length<8)
{if(!msg)
this.writeError(obj,'Please enter a valid Phone Number');else this.writeError(obj,msg);return false;}}
return true;}
function name_str(obj,msg)
{if(obj.value)
{if(/^(([A-Za-z]+\s?\'?[A-Za-z]*)\s?)+[\d]{0,10}$/.test(obj.value))
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid name');else this.writeError(obj,msg);return false;}}
return true;}
function namelen(obj,msg)
{var lenval=trimAll(obj.value);if(lenval)
{if(lenval.length>2)
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid name');else this.writeError(obj,msg);return false;}}
else
{if(!msg)
this.writeError(obj,'Please enter a valid name');else this.writeError(obj,msg);return false;}
return true;}
function nsname(obj,msg)
{if(obj.value)
{if(/^[a-z\']+$/i.test(obj.value))
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid name');else this.writeError(obj,msg);return false;}}
return true;}
function usphone(obj,msg)
{if(obj.value)
{if(/^(\+?\d{2}\s?)?\([1-9]\d{2}\)\s?\d{3}\-?\d{4}$/.test(obj.value))
{return true;}
else
{if(/^(\+?\d{2}\s?)?\[[1-9]\d{2}\]\s?\d{3}\-?\d{4}$/.test(obj.value))
{return true;}
else
{if(/^(\+?\d{2}\s?)?[1-9]\d{2}\s?\d{3}\-?\d{4}$/.test(obj.value))
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid US Phone Number');else this.writeError(obj,msg);return false;}}}}
return true;}
function url(obj,msg)
{if(obj.value)
{if(/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/.test(obj.value))
{return true;}else
{if(!msg)
this.writeError(obj,'Please enter a valid URL');else this.writeError(obj,msg);return false;}}
return true;}
function ip(obj,msg)
{if(obj.value)
{if((obj.value!="0.0.0.0")&&(obj.value!="255.255.255.255"))
{if(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.test(obj.value))
{return true;}
else
{if(!msg)
{this.writeError(obj,'Please enter a valid IP Address');}
else
{this.writeError(obj,msg);}
return false;}}
else
{if(!msg)
this.writeError(obj,'Please enter a valid IP Address');else this.writeError(obj,msg);return false;}}
return true;}
function mobile(obj,msg)
{if(obj.value)
{if(!(isNaN(obj.value))&&(obj.value.length>9))
{return true;}else
{if(!msg)
this.writeError(obj,'Please enter a valid mobile number');else this.writeError(obj,msg);return false;}}
return true;}
function is_int(val)
{var str=new String(val);arr=str.split(".");if(arr.length>1)
{return false;}
else
{return true;}}
function ccv_3(obj,msg)
{if(!isNaN(obj.value)&&is_int(obj.value)&&obj.value.length==3)
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid ccv number');else this.writeError(obj,msg);return false;}}
function visa_num(obj,msg)
{if(!isNaN(obj.value)&&is_int(obj.value)&&((obj.value.length==13)||(obj.value.length==16))&&(get_initial_digit(obj.value)=="4"))
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid credit card number');else this.writeError(obj,msg);return false;}}
function master_num(obj,msg)
{if(!isNaN(obj.value)&&is_int(obj.value)&&((obj.value.length==16))&&(get_initial_digit(obj.value)=="5"))
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid credit card number');else this.writeError(obj,msg);return false;}}
function get_initial_digit(val)
{var str=new String(val);return str.substring(0,1)}
function postcode(obj,msg)
{if(obj.value)
{if(!isNaN(obj.value)&&obj.value.length>3)
{return true;}else
{if(!msg)
this.writeError(obj,'Please enter a valid postcode');else this.writeError(obj,msg);return false;}}
return true;}
function number(obj,msg)
{if(obj.value)
{if(!isNaN(obj.value))
{return true;}else
{if(!msg)
this.writeError(obj,'Please enter a valid Number');else this.writeError(obj,msg);return false;}}
return true;}
function checkfile(obj,msg)
{if(obj.value)
{if(/^[\w+\s*]+.[pdf|doc|txt|jpg|gif]+/i.test(obj.value))
{return true;}else
{if(!msg)
this.writeError(obj,'Invalid File Extension');else this.writeError(obj,msg);return false;}}
return true;}
function trimAll(sString)
{while(sString.substring(0,1)==' ')
{sString=sString.substring(1,sString.length);}
while(sString.substring(sString.length-1,sString.length)==' ')
{sString=sString.substring(0,sString.length-1);}
return sString;}
function trim(obj,msg)
{if(obj.value)
{if(trimAll(obj.value)!="")
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter your name');else this.writeError(obj,msg);return false;}}
return true;}
if(window.attachEvent)
window.attachEvent("onload",setListeners);function setListeners(){if(document.getElementById("showallerrors"))
{oElement=document.getElementById("showallerrors");oElement.style.display="none";}
inputList=document.getElementsByTagName("INPUT");for(i=0;i<inputList.length;i++){inputList[i].attachEvent("onpropertychange",restoreStyles);inputList[i].style.backgroundColor="";}
selectList=document.getElementsByTagName("SELECT");for(i=0;i<selectList.length;i++){selectList[i].attachEvent("onpropertychange",restoreStyles);selectList[i].style.backgroundColor="";}}
function restoreStyles(){if(event.srcElement.style.backgroundColor!="")
event.srcElement.style.backgroundColor="";}
function isArray(obj)
{if(obj.constructor.toString().indexOf("Array")==-1)
return false;else
return true;}
function inArray(arr,pstr)
{var str;str="  "+arr.toString();if(str.indexOf(pstr)>0)
return true;else
return false;}
function comments(obj,msg)
{if(obj.value)
{if(/^(([A-Za-z]+\s?\'?[A-Za-z]*)\s?)+[\d]{0,10}$/.test(obj.value))
{return true;}
else
{if(!msg)
this.writeError(obj,'Please enter a valid comments');else this.writeError(obj,msg);return false;}}
return true;}
