//startFlash
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
//clip name should match the 'IDhere'_DoFSCommand
function ipBtn_DoFSCommand(command, args) {
	if (command == "ipLink") {
		window.open(args);
	}
}
// Hook for Internet Explorer for intLinkClip 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub ipBtn_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call ipBtn_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}
//
//endof Flash
//
//startFlash
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
//clip name should match the 'IDhere'_DoFSCommand
function mainMenu_DoFSCommand(command, args) {
	if (command == "menuLink") {
		if(args == "home"){
			document.location = "default.asp";
		}
		else{
			document.location = args+".asp";
		}
	}
}
// Hook for Internet Explorer for intLinkClip 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub mainMenu_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call mainMenu_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}
//
//endof Flash
//
//submit form
function doSearch() {
	//var L = document.qS.LocDD.value;
	//var T = document.qS.TypeDD.value;
	//var B = document.qS.BedsDD.value;
	//var P = document.qS.PriceDD.value;
	//document.location = "results.temp.asp?L="+L+"&T="+T+"&B"+B+"&P="+P;
	document.qS.submit();
}
//
//endof submit form
//
function ValCVForm(){
	var isAnError = false;
	var errMsg = "";
	if (document.CVForm.FullName.value == ''){
		errMsg += "Please enter your First Name.\n";
		isAnError = true;
	}
	//
	if (document.CVForm.email.value == ''){
		errMsg += "Please enter your E-Mail Address.\n";
		isAnError = true;
	}
	if (document.CVForm.email.value != ''){
		if (!isEmail(document.CVForm.email.value)){
			errMsg += document.CVForm.email.value+" is not a valid E-Mail Address.\n";
			isAnError = true;
		}
	}
	//
	if(isAnError){
		alert(errMsg);
	}
	if(!isAnError){
		document.CVForm.submit();
	}
}
//
function isEmail(eml){
	var i = 1;
	var emlLength = eml.length;
	while ((i < emlLength) && (eml.charAt(i) != "@")){
		i++;
	}
	if ((i >= emlLength) || (eml.charAt(i) != "@")) {
		return false;
	}
	else {
		i += 2;
	}
	while ((i < emlLength) && (eml.charAt(i) != ".")){
		i++;
	}
	if ((i >= emlLength - 1) || (eml.charAt(i) != ".")){
		return false;
	}
	else {
		return true;
	}
}
//
//
function isPrice(price) {
    for (var i=0, len=price.length-1, valid='0123456789.,' ; i<len ; i++) {
        if (valid.indexOf(price.substring(i,i+1)) == -1) {
            return false;
        }
		else {
			return true;
		}
    }
}
//
//
function isNumber(EnteredNumber) {
    for (var i=0, len=EnteredNumber.length, valid='0123456789' ; i<len ; i++) {
        if (valid.indexOf(EnteredNumber.substring(i,i+1)) == -1) {
            return false;
        }
		else {
			return true;
		}
    }
}
//
//
function ValForm(){
	var isAnError = false;
	var errMsg = "";
	errMsg += "The following are missing or incorrect:\n\n"
	//
	if (document.RecInfo.CL_Firstname.value == ''){
		errMsg += "• Your First Name.\n";
		isAnError = true;
	}
	//
	if (document.RecInfo.CL_Lastname.value == ''){
		errMsg += "• Your Last Name.\n";
		isAnError = true;
	}
	//
	if (document.RecInfo.CL_Email.value == ''){
		errMsg += "• Your Email Address.\n";
		isAnError = true;
	}
	//
	if (document.RecInfo.CL_Email.value != ''){
		if (!isEmail(document.RecInfo.CL_Email.value)){
			errMsg += "• " + document.RecInfo.CL_Email.value + " is not a valid email address.\n";
			isAnError = true;
		}
	}
	//
	if (document.RecInfo.PropTitle.value == ''){
		errMsg += "• A Title for your Property.\n";
		isAnError = true;
	}
	//
	if (document.RecInfo.Region.value == ''){
		errMsg += "• The Region your Property is in.\n";
		isAnError = true;
	}
	//
	if (document.RecInfo.Location.value == '' && document.RecInfo.Region.value == 'Algarve'){
		errMsg += "• The Location of your Property.\n";
		isAnError = true;
	}
	//
	if (document.RecInfo.PropType.value == ''){
		errMsg += "• Your Property Type.\n";
		isAnError = true;
	}
	//
	if ((document.RecInfo.BedNum.value == '') && (document.RecInfo.PropType.value != 'Plot')){
		errMsg += "• The Number of Bedrooms.\n";
		isAnError = true;
	}
	//
	if ((document.RecInfo.BedNum.value != '') && (document.RecInfo.PropType.value != 'Plot')){
		if (!isNumber(document.RecInfo.BedNum.value)){
			errMsg += "• Number of bedrooms must be a Number.\n";
			isAnError = true;
		}
	}
	//
	if ((document.RecInfo.BathNum.value == '') && (document.RecInfo.PropType.value != 'Plot')){
		errMsg += "• The Number of Bathrooms.\n";
		isAnError = true;
	}
	//
	if ((document.RecInfo.BathNum.value != '') && (document.RecInfo.PropType.value != 'Plot')){
		if (!isNumber(document.RecInfo.BathNum.value)){
			errMsg += "• Number of Bathrooms must be a Number.\n";
			isAnError = true;
		}
	}
	//
	if ((document.RecInfo.PlotSize.value == '') && (document.RecInfo.PropType.value == 'Plot')){
		errMsg += "• The Size of the Plot.\n";
		isAnError = true;
	}
	//
	if ((document.RecInfo.PlotSize.value != '') && (document.RecInfo.PropType.value == 'Plot')){
		if (!isNumber(document.RecInfo.PlotSize.value)){
			errMsg += "• Plot Size must be a Number.\n";
			isAnError = true;
		}
	}
	//
	if (document.RecInfo.Pool.value == ''){
		errMsg += "• Whether or Not your Property has a Pool.\n";
		isAnError = true;
	}
	//
	if ((document.RecInfo.Heated.value == '') && (document.RecInfo.Pool.value == 'Yes')){
		errMsg += "• Whether or Not your Pool is Heated.\n";
		isAnError = true;
	}
	if (document.RecInfo.EUR_Price.value == ''){
		errMsg += "• The Price of your Property.\n";
		isAnError = true;
	}
	if (document.RecInfo.EUR_Price.value != ''){
		if (!isPrice(document.RecInfo.EUR_Price.value)){
			errMsg += "• When entering a price, please use numbers only.\n   You do not need to use a currency symbol.\n";
			isAnError = true;
		}
	}
	//
	if (document.RecInfo.Desc.value == ''){
		errMsg += "• A Brief Description for your Property.\n";
		isAnError = true;
	}
	//
	if(isAnError){
		alert(errMsg += "\n For detailed help click the help icon next to \n the item you are having trouble with.");
	}
	if(!isAnError){
		document.RecInfo.HasSaved.value="Yes";
		document.RecInfo.submit();
	}
}
//
function checkDDVal(ListName) {
	if(ListName == "Region"){
		if(document.RecInfo.Region.value == 'Algarve'){
			document.getElementById("LocRow").style.display = "block";
		} else {
			document.getElementById("LocRow").style.display = "none";
			document.RecInfo.Location.selectedIndex = 0;
		}
	}
}