//4/12/10 - checkpw

function checkpw(obj) {
	pw = document.getElementById("Password");
	if(obj.value != pw.value) {
		document.getElementById("checkPW").innerHTML = "X";
	} else {
		document.getElementById("checkPW").innerHTML = "OK";
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
} 

function MM_validateForm() { //v4.0 - 2/28/2010 edits by SLS
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  noAddress = 0;
  noSite = 0;
  for (i=0; i<(args.length-2); i+=3) {//1
	test=args[i+2];
	val=MM_findObj(args[i]);	
	if (val) {//2		
	  //SLS edit: use middle parameter for alternate wording
	  if(args[i+1]!= '') {//3
	    nm = args[i+1];
		onm = val.name;
	  } else
	    nm=onm=val.name;
	  //if default JS text, it is considered blank
	  if(val.value == 'Your Phone' || val.value == 'Your Name Here' || val.value == 'Your Email')
	    val.value="";
	  if ((val=val.value)!="") {//3	  	
        if (test.indexOf('isEmail')!=-1) {//4		  
		  p=val.indexOf('@');
          if (p<1 || p==(val.length-1))
		    errors+='- '+nm+' must contain an e-mail address.\n';
	  //if isName test added by SLS	
      } else if(test.indexOf('isName') != -1) {//4
	    if(val == 'Your Name Here')
		  errors+='- recommended by must be your name.\n';
	  //if isURL test added by SLS
	  } else if (test.indexOf('isURL') != -1) {//4
		if(!isUrl(val))
		  errors+='- '+nm+' must be a URL with \'http://\'.\n';
	  //if isZIP test added by SLS
	  } else if(test.indexOf('isZIP') != -1) {//4
	  	if(val.length != 5)
			errors+='- '+nm+' must be a valid ZIP code.\n';
	  //if isPhone test added by SLS
	  } else if(test.indexOf('isPhone') != -1) {//4
		if(!isPhone(val))
			errors+='- '+nm+' must be a valid phone number.\n';
	   //if isBody test added by SLS
	  } else if(test.indexOf('isBody') != -1) {//4
	  	if(val.length > 10000)
			errors+='- '+nm+' body must be shorter than 10,000 characters.\n';
	  } else if (test!='R' && test!='') {//4
		num = parseFloat(val);
        if (isNaN(val))
		  errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) {//5
		  p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
        if (num<min || max<num)
		    errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') {//3
			errors += '- '+nm+' is required.\n';
	  //in some cases, an address OR website is required
	  }	else if(onm=='address'||onm=='zip'||onm=='city') {	//3
		noAddress = 1;
	  } else if(onm=='website') {//3
		noSite = 1;
	  }//end if(val!='')
	}//end if(val)	
  }//end for loop
  //edit by SLS: need website OR address
  if (noAddress && noSite)
	errors+= '- please provide a website or an address.\n';
  if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}//end MM_validateForm()

function isUrl(url) {
	return /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/.test(url);
}

function isPhone(phone) {
	return /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/.test(phone);
}
