//validate and submit the form



function formSubmit(frm) {



	if (isEmpty(frm.cName, "Contact name")) return

	if (isEmpty(frm.cEmail, "Contact e-mail")) return

	if (notEmail(frm.cEmail, "Contact e-mail")) return

	if (isEmpty(frm.linkTitle, "Link title")) return

	if (isEmpty(frm.linkURL, "Link URL")) return

	if (isEmpty(frm.linkDesc, "Link description")) return

	if (isEmpty(frm.recipURL, "Links page URL")) return



	//Check Site URL is valid length

	if (frm.linkURL.value.length < 12) {

		alert("Site URL is invalid")

		return

	}



	//Check Site URL contains a dot

	var dot = false

	for (var i=0; i < frm.linkURL.value.length; i++) {

		if (frm.linkURL.value.charAt(i) == ".")  var dot = true

	}

	

	if (!dot) {

		alert("Invalid Site URL")

		return

	}



	//Check that the ReciprocalURL contains the SiteURL domain

	if (frm.recipURL.value.indexOf("http://") == 0) j = 7;

	else j = 0;

	

	if (frm.linkURL.value.indexOf("http://") == 0) l = 7;

	else l = 0;



	if (frm.recipURL.value.substring(j).indexOf("/") > 0) i = frm.recipURL.value.substring(j).indexOf("/") + j - 1;

	else i = frm.recipURL.value.length-1;

	

	if (frm.linkURL.value.substring(l).indexOf("/") > 0) k = frm.linkURL.value.substring(l).indexOf("/") + l - 1;

	else k = frm.linkURL.value.length-1;

	

	if (frm.linkURL.value.substring(l, k+1) != frm.recipURL.value.substring(j, i+1)) {

		alert("Reciprocal Link URL and Site URL must be in the same domain")

		return

	}



	//submit form

	frm.submit()	

}


function populateParishes(frm)
{
	//alert(frm.drop_off_location.selectedIndex);
	
	if( frm.pick_up_location.selectedIndex == 1 || frm.pick_up_location.selectedIndex == 2 )
	{
		//alert(frm.drop_off_location.selectedIndex);
		frm.drop_off_location.options.length = 14;
		frm.drop_off_location.options[1]  = new Option( "Kingston" ,'Kingston', true );
		frm.drop_off_location.options[2]  = new Option( "Montego Bay",'Montego Bay' );
		frm.drop_off_location.options[3]  = new Option( "Hanover",'Hanover', true );
		frm.drop_off_location.options[4]  = new Option( "Trelawny",'Trelawny' );
		frm.drop_off_location.options[5]  = new Option( "St. Ann",'St. Ann' );
		frm.drop_off_location.options[6]  = new Option( "St. Mary",'St. Mary' );
		frm.drop_off_location.options[7]  = new Option( "St. Andrew",'St. Andrew'  );
		frm.drop_off_location.options[8]  = new Option( "Portland",'Portland'  );
		frm.drop_off_location.options[9]  = new Option( "Westmoreland",'Westmoreland' );
		frm.drop_off_location.options[10]  = new Option( "St. Elizabeth",'St. Elizabeth'  );
		frm.drop_off_location.options[11]  = new Option( "Manchester",'Manchester' );
		frm.drop_off_location.options[12]  = new Option( "Clarendon",'Clarendon'  );
		frm.drop_off_location.options[13]  = new Option( "St. Catherine",'St. Catherine'  );
		frm.drop_off_location.options[14]  = new Option( "St. Thomas",'St. Thomas'  );		
	}
	else
	{
		if( frm.pick_up_location.selectedIndex != 0)
		{
			//alert(frm.pick_up_location.selectedIndex);
			frm.drop_off_location.options.length = 2;
			frm.drop_off_location.options[1]  = new Option( "Kingston" ,'Kingston', true );
			frm.drop_off_location.options[2]  = new Option( "Montego Bay",'Montego Bay' );
		}
		
	}	
	
		
}

function ValForm(frm) 
{
	//alert("called")
	
	if (isEmpty(frm.pick_up_location, "Pick Up Location")) return false;
	
	if (isEmpty(frm.drop_off_location, "Drop Off Location")) return	false;
	
	//frm.submit()
}