// JavaScript Document
function picNext(currentdiv){
		for (var i=0;i<count;i++){
			document.getElementById("div"+i).style.display="none";
			document.getElementById("imggallery"+i).src="images/imggallery-off.gif"
		}
		document.getElementById("div"+currentdiv).style.display="block";
		document.getElementById("imggallery"+currentdiv).src="images/imggallery-on.gif"
		
	}
function picNextold(){
		for (var i=0;i<count;i++){
			document.getElementById("div"+i).style.display="none";
		}
		document.getElementById("div"+currentdiv).style.display="block";
		if (currentdiv==count-1){
			currentdiv=0;
		}
		else{
			currentdiv=currentdiv+1;
		}
	}
function ValidateLogin(username, password){
	if (Trim(document.getElementById("txtUsername").value)=="" || Trim(document.getElementById("txtPassword").value)==""){
		alert("Please enter your username and your password");
		 return false;
	}
	else{
	  return true;
	}
 }	
function openIT(u,W,H, sc, rz) {
	window.open(u, '',"width="+W+",height="+H+",scrollbars="+(sc ? "yes" : "no")+",resizable="+(rz ? "yes" : "no")+",status=yes, left="+250+",top="+200);
} 
function PopImage(img, caption)
{
	caption = escape(caption);
	openIT('pop_gl.htm?img='+img+"&caption="+caption,450,700);
}
function popYachtDetails(ID){
	openIT('Pre-Owned-YachtDetails.aspx?ID='+ID,655,645,true,false);
	}

function ValidateRepair(){
	var msg="";
	if (document.getElementById("txtBrandName").value=="")
		msg+=" - Brand Name\n";
	if (document.getElementById("txtModel").value=="")
		msg+=" - Model\n";
	if (document.getElementById("txtHull").value=="")
		msg+=" - Hull#\n";
	if (document.getElementById("txtLocation").value=="")
		msg+=" - Boat location\n";
	if (document.getElementById("txtRequiredService").value=="")
		msg+=" - Required service or repair\n";
	if (document.getElementById("txtInterventionDate").value=="")
		msg+=" - Required intervention date\n";
	if (document.getElementById("txtOwnerName").value=="")
		msg+=" - Owner Name\n";
	if (document.getElementById("txtOwnerTel").value=="")
		msg+=" - Owner Phone\n";
	if (document.getElementById("txtOwnerEmail").value=="")
		msg+=" - Owner Email\n";
	else{
		if (IsValidEmail(document.getElementById("txtOwnerEmail"))==false)
			msg+=" - Invalid Email Adddress\n"
		}
	if(msg==""){
		return true;
		}
	else{
		alert("The following fields are required:\n\n"+msg);
		return false;
		}
	}
	
function ValidateCrew(){
	var msg="";
	if (document.getElementById("txtPositionRequired").value=="")
		msg+=" - Position Required\n";
	if (document.getElementById("txtFrom").value=="")
		msg+=" - Period Required: From\n";
	if (document.getElementById("txtTo").value=="")
		msg+=" - Period Required: To\n";
	if (CheckRadioButtons(document.form1.rdPeriod)==false)
		msg+=" - Part time/Fulltime\n";
	if (document.getElementById("txtExpReq").value=="")
		msg+=" - Experience requirements:\n";
	if (document.getElementById("txtLangReq").value=="")
		msg+=" - Citizensship/Language requirements:\n";
	if(msg==""){
		return true;
		}
	else{
		alert("The following fields are required:\n\n"+msg);
		return false;
		}
	}
	
function ValidateRegistration (){
	var msg="";
	if (document.getElementById("txtBrandName").value=="")
		msg+=" - Brand Name\n";
	if (document.getElementById("txtBoatName").value=="")
		msg+=" - Boat Name\n";
	if (document.getElementById("txtModel").value=="")
		msg+=" - Model\n";
	if (document.getElementById("txtHull").value=="")
		msg+=" - Hull#\n";
	if (CheckRadioButtons(document.form1.rdNew)==false)
		msg+=" - New Boat/Used Boat\n";
	if (CheckRadioButtons(document.form1.rdRegistered)==false)
		msg+=" - New Built/Already registered \n";
	if (document.getElementById("txtLangReq").value=="")
		msg+=" - Citizensship/Language requirements\n";
	
	if(msg==""){
		return true;
		}
	else{
		alert("The following fields are required:\n\n"+msg);
		return false;
		}
	}
function ValidateTransport(){
	var msg="";
	if (document.getElementById("txtBrandName").value=="")
		msg+=" - Brand Name\n";
	if (document.getElementById("txtBoatName").value=="")
		msg+=" - Boat Name\n";
	if (document.getElementById("txtHull").value=="")
		msg+=" - Hull#\n";
	if (document.getElementById("txtlength").value=="")
		msg+=" - Overall length\n";
	if (document.getElementById("txtMaxBeam").value=="")
		msg+=" - Max. beam\n";
	if (document.getElementById("txtTonnage").value=="")
		msg+=" - Tonnage\n";
	if (document.getElementById("txtHeight").value=="")
		msg+=" - Height from keel to top arch\n";
	if (CheckRadioButtons(document.form1.rdNew)==false)
		msg+=" - Yacht condition\n";
	if (document.getElementById("txtFrom").value=="")
		msg+=" - Shipment: From\n";
	if (document.getElementById("txtTo").value=="")
		msg+=" - Shipment: To\n";
	if (document.getElementById("txtShipDate").value=="")
		msg+=" - Yacht  available for shipment as of date \n";
	if (CheckRadioButtons(document.form1.rdCradle)==false)
		msg+=" - Yacht cradle available\n";
	if (CheckRadioButtons(document.form1.rdInsurance)==false)
		msg+=" - Transport insurance required\n";
	 if(document.form1.rdInsurance[1].checked==true && document.getElementById("txtInsuredValue").value=="") 
	 	msg+=" - Insured value\n";
	if (document.getElementById("txtOwnerName").value=="")
		msg+=" - Owner Name\n";
	if (document.getElementById("txtOwnerTel").value=="")
		msg+=" - Owner Phone\n";
	if (document.getElementById("txtOwnerEmail").value=="")
		msg+=" - Owner Email\n";
	else{
		if (IsValidEmail(document.getElementById("txtOwnerEmail"))==false)
			msg+=" - Invalid Email Adddress\n"
		}
	if(msg==""){
		return true;
		}
	else{
		alert("The following fields are required:\n\n"+msg);
		return false;
		}
	}	

function ValidateFinancing(){
	var msg="";
	if (document.getElementById("txtPurshaseValue").value=="")
		msg+=" - Yacht Purchase Value\n";
	if (document.getElementById("txtModel").value=="")
		msg+=" - Yacht Brand: Model\n";
	if (document.getElementById("txtYear").value=="")
		msg+=" - Yacht Brand: Year\n";
	if (CheckRadioButtons(document.form1.rdNew)==false)
		msg+=" - Yacht condition\n";
	if (document.getElementById("txtAmount").value=="")
		msg+=" - Amount of financing required\n  (Maximum 70% of yacht purchase value)\n";
	if (CheckRadioButtons(document.form1.rdPeriod)==false)
		msg+=" - Required period of financing\n";
	if (document.getElementById("txtOwnerName").value=="")
		msg+=" - Owner Name\n";
	if (document.getElementById("txtOwnerTel").value=="")
		msg+=" - Owner Phone\n";
	if (document.getElementById("txtOwnerEmail").value=="")
		msg+=" - Owner Email\n";
	else{
		if (IsValidEmail(document.getElementById("txtOwnerEmail"))==false)
			msg+=" - Invalid Email Adddress\n"
		}
	if(msg==""){
		return true;
		}
	else{
		alert("The following fields are required:\n\n"+msg);
		return false;
		}
	}	
function ValidateContact (){
	var msg="";
	if (document.getElementById("txtFname").value=="")
		msg+=" - First Name\n";
	if (document.getElementById("txtLname").value=="")
		msg+=" - Last Name\n";
	if (document.getElementById("txtPhone").value=="")
		msg+=" - Phone\n";
	if (document.getElementById("txtFullAddress").value=="")
		msg+=" - Full Address\n";
	if (document.getElementById("txtZip").value=="")
		msg+=" - Zip/Postal Code\n";
	if (document.getElementById("txtEmail").value=="")
		msg+=" - Email\n";
	else{
		if (IsValidEmail(document.getElementById("txtEmail"))==false)
			msg+=" - Invalid Email Adddress\n"
		}
	if (document.getElementById("txtMessage").value=="")
		msg+=" - Enquiry message\n";
	
	if(msg==""){
		return true;
		}
	else{
		alert("The following fields are required:\n\n"+msg);
		return false;
		}
	}	
function CheckRadioButtons(rdBtn){
   var check=false;
   var i=0;
   for (i=0;i<rdBtn.length;i++){
       if(rdBtn[i].checked==true) 
       check=true
   } 
     if (check==false)
      return false;
   else
      return true;
}	
function IsValidEmail(txt){
    var stremail="";
    //txt=document.forms(0).txtEmail
    //return false;
	var goodEmail = txt.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	if (goodEmail){
		 return true;
	} 
	else{
		return false;
		}
}
function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function


