//form valiation for credit application on YFS contact page
function validate_form(thisform) {
	with (thisform) {
		
		if (strVal(strNameYacht,"Name of Yacht must be filled out!")==false) {
			document.getElementById('strNameYacht').className="incorrect";
			strNameYacht.focus();
			return false;
		}
		else {
			document.getElementById('strNameYacht').className="";
		}		

		if (strVal(strContactName,"Contact Name must be filled out!")==false) {
			document.getElementById('strContactName').className="incorrect";
			strContactName.focus();
			return false;
		}
		else {
			document.getElementById('strContactName').className="";
		}
		
		if (emailVal(strContactEmail,"Contact Email must be filled out!")==false) {
			document.getElementById('strContactEmail').className="incorrect";
			strContactEmail.focus();
			return false;
		}
		else {
			document.getElementById('strContactEmail').className="";
		} 
		
		if (document.credit_form.attachment1[0].checked==true && attach_browse.value=="") {
			alert("You have selected 'Yes' to attachment, please browse to location and select file!");
			return false;
		}
		else {
			return true;			
		}
	}
}
	
//validation for strings
function strVal(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		}
		else {
			return true
		}
	}
}
//validation for email
function emailVal(field,alerttxt) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {
			alert(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}

//rollovers for credit application on YFS contact page
function sOver() {
	document.getElementById('submit').className="Over";
}
function sOut() {
	document.getElementById('submit').className="Out";
}	
function rOver() {
	document.getElementById('reset').className="Over";
}
function rOut() {
	document.getElementById('reset').className="Out";
}	
	
//reload page due to earlier shading of incorrect fields
function allReset() {
	window.location.reload(false);
}

//email attachment for credit form
function add_attachment() {
	document.getElementById('hide_attachment').innerHTML="<input type='file' name='attach_browse' size='45' />";
}
//email attachment for credit form
function remove_attachment() {
	document.getElementById('hide_attachment').innerHTML="&nbsp;";
}

//for images swaps
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];}
}

