//-------------------------
//---------------------------
// Core
oWin=window,oDoc=document;
function Cb(a){return Boolean(a)}
function Cn(a){return Number(a)}
function Cs(a){return String(a)}

function Ch(a){return typeof(a)}
function ChS(a){return Ch(a)=='string'}
function ChN(a){return Ch(a)=='number'}
function ChO(a){return Ch(a)=='object'}
function ChF(a){return Ch(a)=='function'}

function O(){var a=arguments,o=new Object(),i;for(i=0;i<a.length;i+=2)o[a[i]]=a[i+1];return o};
b=O('ns4',Cb(oDoc.layers),'ie',Cb(oDoc.all),'dom',Cb(oDoc.getElementById));
b.ns=Cb(b.ns4||(b.dom&&!b.ie)),b.ieDom=Cb(b.ie&&b.dom),b.nsDom=Cb(b.ns&&b.dom);

String.prototype.mask=function(){return this.replace(/\S/g,'*')};

if(!window.aOnLoad){
	window.aOnLoad=[];
	aOnLoad[aOnLoad.length]=window.onload;
	window.onload=function(){
		for(var i=0;i<aOnLoad.length;i++){
			if(aOnLoad[i])aOnLoad[i]();
		}
	}
}


// validate.js


V=O('aV',O(),'aFE',O());
V.FormElm=function(vForm,vFormElm,bReq,sType,errEvt){
	var i,vF=vForm,vE=vFormElm,oF,oFE,sFName,sFEName;
	var oF = document.forms[vForm];
	
	if (vE&&ChO(vE)) {
		oFE=vE;
		sFName=vE.form.name;
		sFEName=vE.name;
	}
	else{
		if(vF&&ChO(vF))oF=vF,sFName=vForm;
		else oF=oDoc.forms[(sFName=vF)];
		if(!oF)return null;
		if(vFormElm&&ChO(vFormElm))oFE=vFormElm,sFEName=oFE.name;
		else sFEName=vFormElm;
		if(oF){
			if(oF.elements)oFE=oF.elements[sFEName];
			else if(oF.length){
				for(i=0;i<oF.length;i++){
					if(oF[i].elements[sFEName]){
						if(!oFE)oFE=[];
						oFE[oFE.length]=oF[i].elements[sFEName]
					}
				}
			}
		}
	}
	if(!oFE)return null;
	this.elm=oFE;
	this.req=Cb(bReq);
	this.routine=(sType)?V.aV[this.type=sType]:null;
	this.evt=errEvt||null;
	V.aFE[sFName+'_'+sFEName]=this
};
V.Type=function(sName,sMsg,RE){
	if(!RE)RE=this.RE;if(!ChS(sMsg))sMsg=this.msg;
	if(!sName||!ChS(sName)||!RE)return;
	this.msg=sMsg||'';
	this.RE=RE;
	this.f=(RE.test)?function(s){return V.aV[this.name].RE.test(s)}:function(s,oE){var o=V.aV[this.name];return o.RE(s,o,oE)};
	V.aV[this.name=sName]=this
};
V.overwriteRule=V.addType=function(sName,sMsg,RE){
	new V.Type(sName,sMsg,RE)
};
V.addFormElm=function(sFrm,sFElm,bReq,sType,errEvt){
	new V.FormElm(sFrm,sFElm,bReq,sType,errEvt)
};

V._validate=function(oFE,oFElm,bChecked){
	var sT=oFElm.type,sVal=(sT!='select-one')?oFElm.value:oFElm.options[oFElm.selectedIndex].value,bReq=oFE.req,sErr;

	if (sT!='select-one') {
		var re = new RegExp("(" + String.fromCharCode(8217) + ")","g");
		oFElm.value = oFElm.value.replace(re,"'");

		re = new RegExp("(" + String.fromCharCode(8211) + ")","g");
		oFElm.value = oFElm.value.replace(re,"-");

		re = new RegExp("(" + String.fromCharCode(8221) + ")","g");
		oFElm.value = oFElm.value.replace(re,'"')
	}


	if(bReq&&(!sVal||(sT=='checkbox'&&!bChecked)))sErr='You must enter data into all of the required fields.\n';
	else if(sVal&&oFE.routine&&!oFE.routine.f(sVal,oFElm)){
		sErr='"'+((sT!='password')?sVal:sVal.mask())+'" is not a valid entry.\n';
		if(sErr&&oFE.routine)sErr+=oFE.routine.msg
	}
	return sErr
};
V.validate=function(frmName){
	
	window.onbeforeunload=null;
	
	if(!frmName||(!ChS(frmName)&&!ChO(frmName))) {
		alert("[" + frmName + "] does not exist");
		return false;	
	}
	var oF;
	if (ChS(frmName)) {
		oF = oDoc.forms[frmName]
	}
	else {
		if (ChO(frmName)) {
			alert("function V.validate requires the form name as a String");
			return false;	
		}
	}
 	var bChecked=false;

	if(!oF) {
		alert("[" + frmName + "] does not exist");
		return false;
	}
	var i,ii,aFE=oF.elements,nFEL=aFE.length,oFE,sVal,sErr,oFE_elm;
	for(i=0;i<nFEL;i++){
		if((oFE=V.aFE[frmName+'_'+aFE[i].name])){
			if(!oFE.elm.type&&ChN(oFE.elm.length)){
				for(ii=0;ii<oFE.elm.length;ii++){
					if (oFE.elm[ii].type!='checkbox')break;
					else if(oFE.req&&oFE.elm[ii].checked){bChecked=true;break}
				}
				for(ii=0;ii<oFE.elm.length;ii++){
					if(oFE.elm[ii].form==oF){
						if((sErr=V._validate(oFE,oFE.elm[ii],bChecked))){
							oFE_elm=oFE.elm[ii];
							break
						}
					}
				}
				if(sErr)break
			} else if((sErr=V._validate(oFE,oFE.elm,Boolean(oFE.elm.type=='checkbox'&&oFE.elm.checked)))){
				oFE_elm=oFE.elm;
				break
			}
		}
		bChecked=false;
	}
	if(sErr){
		if(oFE.evt)oFE.evt(oFE_elm);
		alert(sErr);
		if(oFE_elm.type!='hidden'){
			if(oFE_elm.select&&!b.ns4)oFE_elm.select()
			else if(oFE_elm.focus)oFE_elm.focus();
		}
	}else oF.submit();
	return false
};


function phoneConcat(s, o, oE) {
	var RE_phone3 = /\d{3}/, RE_phone4 = /\d{4}/, bValid=true;
	var aPhone=s.split('-');
	var oFormElms = oE.form.elements;
	var sSelFunc = (!b.ns4)? 'select' : 'focus';
	
	if(!RE_phone3.test(aPhone[0])){ oFormElms.fld_phoneArea[sSelFunc](); bValid=false }
	else if(!RE_phone3.test(aPhone[1])){ oFormElms.fld_phone1[sSelFunc](); bValid=false }
	else if(!RE_phone4.test(aPhone[2])){ oFormElms.fld_phone2[sSelFunc](); bValid=false }
	
	return bValid;
}
function concatPhone(oForm) {
	if (oForm) {
		var oElms = oForm.elements;
 		var sAreaCode = oElms.fld_phoneArea.value;
 		var sPrefix = oElms.fld_phone1.value;
 		var sNumber = oElms.fld_phone2.value;
 		oElms.fld_phone.value = (sAreaCode && sPrefix && sNumber)? sAreaCode + '-' + sPrefix + '-' + sNumber : '';
	}
}

function chkDate(month,day,year) { 
        if (day.substring(0,1) == "0") 
                day = day.substr(1,1); 
        if (month.substring(0,1) == "0") 
                month = month.substr(1,1); 

        var date = month + "/" + day + "/" + year; 
        var date1 = new Date(month + "/" + day + "/" + year).getTime() 
        var date2 = new Date() 
        date2.setTime(date1); 
        if ((date2.getMonth()+1) + "/" + date2.getDate() + "/" + date2.getFullYear() != date) 
       return false; 
        else 
                return true; 
} 

function descLength(oForm) {
alert("##$#");
	var oElms = oForm.elements;
alert(oElms.description.value.length);
	if(oElms.description.value.length > 256)
		return false;
	else 
		return true;
}


V.addType('alpha','Please enter alpha characters only. (a-z, A-Z)',/^[a-z\s]+$/i);
V.addType('numeric','Please enter numeric characters only. (0-9)',/^\d+$/);
V.addType('alpha_numeric');//,'Please enter alpha-numeric characters only. (a-z, A-Z, 0-9)',/^[a-z0-9\s]+$/i);
V.addType('alpha_numeric_under');//,'Please enter alpha-numeric / underscore characters, only. (a-z, A-Z, 0-9, _)',/^\w+$/i);
V.addType('alpha_numeric_under_dot_comma');//,'Please enter alpha-numeric / underscore characters, only. (a-z, A-Z, 0-9, _,.,,#-)',/^[a-z0-9\s\.\,\#\-\_]+$/i);
//V.addType('email','Please enter a valid email address.',/^(\w|.)+@{1}(\w|.)+\.{1}[a-z]{2,4}$/i); 
V.addType('email','Please enter a valid email address.',/^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i);
V.addType('zip','Please enter a valid zip code.',/(^\d{5}$)|(^\d{5}-\d{4}$)/);
V.addType('phone','Please enter a valid phone number.',/^([1](\.|-|\s)?|)(\(\d{3}\)|\d{3})(\.|-|\s)?\d{3}(\.|-|\s)?\d{4}(\.|-|\s)?\d*$/);
V.addType('phoneConcat', 'Please enter a valid phone number.', phoneConcat);
V.addType('min1','Please enter a positive integer.',function(s){return Cb(/\d/.test(s)&&Cn(s)>0)});
V.addType('file_path','Please enter a valid file path',/^[A-za-z0-9_\\:\. -]+$/);

V.addType('max50', 'Must be less than 50 characters.', function(s) { return (s.length <= 50); });
V.addType('max100', 'Must be less than 100 characters.', function(s) { return (s.length <= 100); });
V.addType('max200', 'Must be less than 200 characters.', function(s) { return (s.length <= 200); });
V.addType('max400', 'Must be less than 400 characters.', function(s) { return (s.length <= 400); });
V.addType('max500', 'Must be less than 500 characters.', function(s) { return (s.length <= 500); });
V.addType('max1000', 'Must be less than 1000 characters.', function(s) { return (s.length <= 1000); });
V.addType('max2000', 'Must be less than 2000 characters.', function(s) { return (s.length <= 2000); });
V.addType('max4000', 'Must be less than 4000 characters.', function(s) { return (s.length <= 4000); });
V.addType('max8000', 'Must be less than 8000 characters.', function(s) { return (s.length <= 8000); });

function buildFormStr(thisForm) {
 var str = '';
 for (i = 0; i < thisForm.elements.length; i++) {
  if (thisForm.elements[i].tagName == "INPUT") {
   str += thisForm.elements[i].name + "=" + thisForm.elements[i].value + "&";
  }
  else if (thisForm.elements[i].tagName == "SELECT") {
   if (thisForm.elements[i].options.length > 0) {
    str += thisForm.elements[i].name + "=" + thisForm.elements[i].options[thisForm.elements[i].selectedIndex].value + "&";
   }
  }
  else if (thisForm.elements[i].tagName == "TEXTAREA") {
   str += thisForm.elements[i].name + "=" + thisForm.elements[i].value + "&";
  }
  
  else if (thisForm.elements[i].tagName == "FILE") {
   str += thisForm.elements[i].name + "=" + thisForm.elements[i].value + "&";
  }
 }
 return str;
}