//************** CMT FUNCTIONS ****************************

curMode = "HTML";
var normal = new Image();
var html = new Image();
normal.src="toolimages/normalw.gif";
html.src="toolimages/htmlg.gif";
delete_pressed=false;


function swap()
{
if (curMode == "HTML") {
swapImages();
document.frames[0].document.tbContentElement.DOM.body.innerText = document.frames[0].document.tbContentElement.DOM.body.innerHTML;
document.frames[0].document.tbContentElement.DOM.body.style.fontFamily = "monospace";
document.frames[0].document.tbContentElement.DOM.body.style.fontSize = "8pt";
document.frames[0].document.tbContentElement.DOM.body.style.backgroundColor = "#FFFFFF";
curMode="Text";

} else {
swapImages();
document.frames[0].document.tbContentElement.DOM.body.innerHTML = document.frames[0].document.tbContentElement.DOM.body.innerText;
document.frames[0].document.tbContentElement.DOM.body.style.fontFamily = "";
document.frames[0].document.tbContentElement.DOM.body.style.fontSize ="";
document.frames[0].document.tbContentElement.DOM.body.style.backgroundColor = "#FFFFFF";
curMode="HTML";
}
}

function swapImages()
{
tmp=normal.src;
normal.src=document.img1.src;
document.img1.src=tmp;
tmp=html.src;
html.src=document.img2.src;
document.img2.src=tmp;

}



//*********************************************************

function getbrowser(){ 
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom)
	return this
}
var bw=new getbrowser()
if (bw.ie4 || bw.ns4)
	alert("\t!!! WARNING !!! \t\n\nThis admin panel requires IE5/NS6 or greater");

function selectbtn()
{
var location= new String();
location=document.location.href;

len=location.length
var divid="";
while(len > 0)
	{
	if(location.substr(len,1) == "_")
		{
		str=location.substr(len+1);
		divid=str.split("=")[1];
	
		break;
		}
	len--;
	}

if (divid.substr(0,3) =="btn")
	{
	
		btn = eval("document.getElementById('" + divid + "')");
		btn.className='btnselect';
	
	}
}


function selectmenu(menu)
{	
	if (bw.ns6)
		barcount =  document.getElementById("menus").childNodes.length/2 -1;
	else
		barcount = document.getElementById("menus").childNodes.length - 1;
	
		
	for (x=0;x<=barcount;x++)
	{
	 oObject = eval("document.getElementById('menu" + x + "')");
	 oObject.childNodes[0].className='menu';
	}
	if (menu.className != "menuselect") menu.className='menuselect';

}



function validate_settings_form()
{
frm=document.settings_form
if(frm.txtpname.value==""){alert("Please enter the password");frm.txtpname.focus(); return false;}
if(frm.txtrepname.value != frm.txtpname.value ){alert("Both password do not match");frm.txtrepname.focus(); return false;}
}





//====================================COMMON FUNCS===============================
function verify()
{
if(confirm("Are you sure you want to delete?")) 
return true; 
else 
return false;
}


function validateEmail(email)
{
	
	// This function is used to validate a given e-mail 
	// address for the proper syntax
	
	if (email == ""){
		return false;
	}
	badStuff = ";:/,' \"\\";
	for (i=0; i<badStuff.length; i++){
		badCheck = badStuff.charAt(i)
		if (email.indexOf(badCheck,0) != -1){
			return false;
		}
	}
	posOfAtSign = email.indexOf("@",1)
	if (posOfAtSign == -1){
		return false;
	}
	if (email.indexOf("@",posOfAtSign+1) != -1){
		return false;
	}
	posOfPeriod = email.indexOf(".", posOfAtSign)
	if (posOfPeriod == -1){
		return false;
	}
	if (posOfPeriod+2 > email.length){
		return false;
	}
	return true
}



function validate_frmaddRegion()
{
	frm=document.frmaddregion;
	
	
	if(frm.regionName.value=="")
	{
		alert("Please enter the region name");
		frm.regionName.select();
		return false;
	}
}

function validate_frmaddCountry()
{
	frm=document.frmaddCountry;
	
	if(frm.countryName.value=="")
	{
		alert("Please enter the country name");
		frm.countryName.select();
		return false;
	}
}

function validate_frmeditowner()
{
	frm=document.frmeditowner;
	if(frm.name.value=="")
	{
		alert("Please enter the name");
		frm.name.select();
		return false;
	}
	if(frm.address1.value=="")
	{
		alert("Please enter the address");
		frm.address1.select();
		return false;
	}
	if(frm.city.value=="")
	{
		alert("Please enter the city");
		frm.city.select();
		return false;
	}
	if(frm.country.value=="")
	{
		alert("Please enter the country");
		frm.country.select();
		return false;
	}
	if(frm.zip.value=="")
	{
		alert("Please enter the zip code");
		frm.zip.select();
		return false;
	}
	if(frm.phone.value=="")
	{
		alert("Please enter the phone number");
		frm.phone.select();
		return false;
	}
	if(frm.email.value=="")
	{
		alert("Please enter the email address");
		frm.email.select();
		return false;
	}
	if(frm.password.value=="")
	{
		alert("Please enter the password");
		frm.password.select();
		return false;
	}
}



function validate_frmeditcottage()
{
	frm=document.frmeditcottage;
		
	if(frm.cottagename.value=="")
	{
		alert("Please enter the cottage name");
		frm.cottagename.select();
		return false;
	}
	if (frm.pricefrom.value=="")
	{
		alert("Please enter the pricefrom");
		frm.pricefrom.focus();
		return false;
	}
	if(frm.priceto.value=="")
	{
		alert("Please enter the priceto");
		frm.priceto.focus();
		return false;
	}
	if(frm.sleeps.value=="")
	{
		alert("Please select the sleeps");
		frm.sleeps.focus();
		return false;
	}
	
	
}


function showAOption1(val)
{
	frm=document.content_edit;	
	if (frm.optA.checked)
	{
		frm.optionA.value=1;
	}
	else
	{
		frm.optionA.value=0;
	}
	
}

function showBOption1(val)
{
	frm=document.content_edit;	
	
	if (frm.optB.checked)
	{	
		frm.optionB.value=1;
		//document.getElementById("RoptionC").style.display="block";
		
	}
	else
	{
		frm.optionB.value=0;
		//document.getElementById("RoptionC").style.display="none";
		
	}
	
}

function showCOption1(val)
{
	frm=document.content_edit;	
	if (val=="1")
	{
		frm.optionC.value=1;
		document.getElementById("RoptionD").style.display="block";
		document.getElementById("RoptionF").style.display="block";
		document.getElementById("RoptionE").style.display="block";

	}
	else
	{
		frm.optionC.value=0;
		document.getElementById("RoptionD").style.display="none";
		document.getElementById("RoptionE").style.display="none";
		document.getElementById("RoptionF").style.display="none";
	}
	
}

function showDOption1(val)
{	frm=document.content_edit;	
	if (val=="0")
	{	frm.optionD.value=0;
		document.getElementById("RoptionE").style.display="block";
	}
	else
	{
		frm.optionD.value=1;
		document.getElementById("RoptionE").style.display="none";
	}
	
}

function showFOption1(val)
{
	frm=document.content_edit;	
	if (val=="1")
	{
		frm.optionF.value=1;
		document.getElementById("RsiteAddress").style.display="block";
		document.getElementById("RsiteUname").style.display="block";
		document.getElementById("RsitePass").style.display="block";
	}
	else
	{
		frm.optionF.value=0;
		document.getElementById("RsiteAddress").style.display="none";
		document.getElementById("RsiteUname").style.display="none";
		document.getElementById("RsitePass").style.display="none";
	}
}

function validate_frmaddproperty()
{
	frm=document.content_edit;
	if(frm.pname.value=="")
	{
		alert("Please enter the property name");
		frm.pname.select();
		return false;
	}	
	
	if (frm.pricefrom.value=="")
	{
		alert("Please enter the pricefrom");
		frm.pricefrom.focus();
		return false;
	}
	if(frm.priceto.value=="")
	{
		alert("Please enter the priceto");
		frm.priceto.focus();
		return false;
	}
	if(frm.sleeps.value=="")
	{
		alert("Please select the sleeps");
		frm.sleeps.focus();
		return false;
	}
	if(frm.country.value=="0")
	{
		alert("Please select a country")
		frm.country.focus();
		return false;
	}
	if(frm.region.value=="0")
	{
		alert("Please select a region");
		frm.region.focus();
		return false;
	}
	if(frm.countyid.value=="0")
	{
		alert("Please select a county");
		frm.countyid.focus();
		return false;
	}
	if(frm.content.value=="")
	{
		alert("Please enter the property description");
		frm.content.select();
		return false;
	}
	
	if(frm.optionB.value=="1")
	{
		if(frm.optionC.value=="")
		{
			alert("Please indicate whether or not you intend to establish the availability calendars at your own website");
			return false
		}
		
	}
	if(frm.optionC.value=="1")
	{
		if(frm.optionD.value=="")
		{
			alert("Please indicate whether or not you have Merchant Facilities and can process “Card Not Present” transactions");
			return false
		}
		if(frm.optionD.value=="0")
		{
			if(frm.optionE.value=="")
			{
				alert("Please Enter The Name To Whom Cheques Should Be Payable!");
				return false;
			}
		}
		if(frm.optionF.value=="")
		{
			alert("Please indicate whether or not you would like us to establish the links from your own website to each of your cottage’s Availability Calendars");
			return false;
		}

	}
	if(frm.optionF.value=="1") 
	{
		if(frm.siteAddress.value=="")
		{
			alert("Please Enter FTP Host Name!");
			frm.siteAddress.focus();
			return false;
		}
		
		if(frm.siteUname.value=="")
		{
			alert("Please Enter FTP Username!");
			frm.siteUname.focus();
			return false;
		}
		
		if(frm.sitePass.value=="")
		{
			alert("Please Enter FTP Password!");
			frm.sitePass.focus();
			return false;
		}
	}
}

function validate_frmaddimage()
{
	if(frmaddimage.imagename.value=="")
	{
		alert("Please select the file");
		frmaddimage.imagename.focus();
		return false;
	}
	frmaddimage.action=frmaddimage.action+'&caption='+frmaddimage.caption.value.replace("'","");
}

function validate_frmeditpic()
{
	if(frmedipic.cottageimage.value=="")
	{
		alert("Please select cottage image");
		frmeditpic.cottageimage.focus();
		return false;
	}
}


function validate_frmeditdetails()
{
	frm=document.frmeditdetails;

	if(frm.night2per.value=="")
	{
		alert("Please enter the discount price for 2 nights")
		frm.night2per.focus();
		return false;
	}
	if(frm.night3per.value=="")
	{
		alert("Please enter the discount price for 3 nights")
		frm.night3per.focus();
		return false;
	}
	if(frm.night4per.value=="")
	{
		alert("Please enter the discount price for 4 nights")
		frm.night4per.focus();
		return false;
	}
	if(frm.night14per.value=="")
	{
		alert("Please enter the discount price for 14 nights")
		frm.night14per.focus();
		return false;
	}
}




	function validate_frmeditcalendar()
	{	
		var length = document.frmeditcalendar.elements.length;
	
		for(var x=0;x<length;x++) 
		{
			if(document.frmeditcalendar.elements[x].type == "text") 
			{
				if (!isNumeric(document.frmeditcalendar.elements[x].value)) 
				{
				alert("You must enter prices as numeric values, i.e. without any currency symbols or spaces.\n\nYou may leave the field as empty.")
				document.frmeditcalendar.elements[x].focus();
				return false;
				break;
				}	
			}
		}
		return true;
	}
	
	function isNumeric(string) 
	{
    		if (string.length == 0)
        		return true;
    		for (var i=0;i < string.length;i++)
        		if (((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9')) && (string.substring(i,i+1) != '.'))
            		return false;
    
    		return true;
	}

	function validatedate(date,day,cday,avail)
	{
		
		var arrDate = String(date).split("/");
		arrDate[0]=arrDate[0]-1;
		var fromDate = new Date(arrDate[2],arrDate[0],arrDate[1]);
		d1=fromDate.getDay();
		
		
		
		
		if((parseInt(d1)!=5 && parseInt(d1)!=6) && day=='2')
		{		
			if(avail=='Yes')
			{	
				alert("2-Night Break must start on Friday or Saturday");
				frmbook.stdate.value="";
				return false;
			}
			else
			{
				alert("Short Break are not available during this week.");
				frmbook.stdate.value="";
				return false;
			}	
		}
		
		
		if(parseInt(d1)!=5 && day=='3')
		{
			if(avail=='Yes')
			{
				alert("3-Night Break must start on Friday");
				frmbook.stdate.value="";
				return false;
			}
			else
			{
				alert("Short Break are not available during this week.");
				frmbook.stdate.value="";
				return false;
			}
		}
		
		if(parseInt(d1)!=1 && day=='4')
		{
			if(avail=='Yes')
			{
			alert("4-Night Break must start on Monday");
			frmbook.stdate.value="";
			return false;
			}
			else
			{
				alert("Short Break are not available during this week.");
				frmbook.stdate.value="";
				return false;
			}
		}
		
		if(day=='7' || day=='14')
		{
			
			if(cday=='Saturday')
				dday=6
			if(cday=='Friday')
				dday=5
			if(cday=='Sunday')
				dday=0
			
			if(d1!=dday) 
			{	
				
				alert("7-Night Break must start on "+cday);
				frmbook.stdate.value="";
				return false;	
				
				
			}		
		}
		if(day=='7' || day=='14')
		{
			frmbook.stdate.value=date;
			frmbook.startdate.value=date;
			changevalue();
			return;
		}
		if(avail=='Yes' && (day=='2' || day=='3' || day=='4'))
		{
			
			frmbook.stdate.value=date;
			frmbook.startdate.value=date;
			changevalue();
		}
		else	
		{	
			alert("Short Break are not available during this week.");
			frmbook.stdate.value="";
			return false;
		}	
		
		
	}
