
/* ====================================================

	GENERAL SITE COMMANDS AND VARIABLES

  Created by John Mounsey, Peaknet Limited.
  john@peaknet.ltd.uk
  © 2OO6 - please do not steal!

==================================================== */

/* ____________________________________________________

Set Overall Variables..
____________________________________________________ */

var siteName		= '_Generic inc.'
var pagelink		= document.location
var pagename		= document.title
var developer		= 'John Mounsey'
var developerurl	= 'http://www.peaknet.co.uk/'
var defaultStatus	= developerurl

/* ____________________________________________________

Date and Time Functions..
____________________________________________________ */

var months=new Array(13);

months[1]	= "January";
months[2]	= "February";
months[3]	= "March";
months[4]	= "April";
months[5]	= "May";
months[6]	= "June";
months[7]	= "July";
months[8]	= "August";
months[9]	= "September";
months[10]	= "October";
months[11]	= "November";
months[12]	= "December";

var time	= new Date();
var lmonth	= months[time.getMonth() + 1];
var date	= time.getDate();
var dateEnd	= "th"
var year	= time.getYear();

if 	(date == 1 || date == 21 || date == 31)	{ dateEnd = 'st'; }
else if (date == 2 || date == 22) 		{ dateEnd = 'nd'; }
else if (date == 3 || date == 23)		{ dateEnd = 'rd'; }

if (year < 2000) year = year + 1900

function today() { document.write(date + dateEnd + " " + lmonth + ", " + year); }



/* ====================================================
Page Greeting
==================================================== */

function greeting()

{
if (hour >= 22)		{ period = 'night'; }
else if (hour >= 17)	{ period = 'evening'; }
else if (hour >= 12) 	{ period = 'afternoon'; }
else if (hour >= 6) 	{ period = 'morning'; }
document.write('Good afternoon');
}


/* ====================================================
Hide "Loading" message
==================================================== */

function hideLoad()

{
// alert('Loading complete!')
document.getElementById('loading')
loading.style.display='none';
}

/* ====================================================
Things to do when page 100% loaded or resized
==================================================== */

function loaded()

{
window.status		= 'Page 100% Loaded.';
hideLoad();
}

/* ====================================================
Show Destination of a url
==================================================== */

function preUrl(destUrl)

{
var destTarg	= destUrl.target;

if (destTarg != '' || destTarg != '_top')
	{
	destUrl.title	= 'Opens: ' + destUrl.href + ' (in a new window)';
	}
}

/* ====================================================
Bookmark / Add to Favorites script
==================================================== */

function bookmark()

{ 
if (window.external)
	{
	external.AddFavorite(pagelink,pagename)
	}
}



/* ====================================================
Recommend a Friend
==================================================== */

function sendPage()
	{
	alert('This opens a blank Email for you to send to friends ..');
	window.location='mailto:?subject=I recommend this site: ' + siteUrl + ' (' + siteName + ')';
	}


/* ====================================================
Previous Pages
==================================================== */

function goBack(dest) { history.go(-1); }
function doubleBack() { history.go(-2); }



/* ====================================================
Change text within an ID'd <P> or <TD> tag
==================================================== */

function change(part,msg)
{
document.getElementById(part).innerText = msg;
}


/* ____________________________________________________

Footer Tools
____________________________________________________ */

function credit()
{
document.write('<P TITLE="copyright message" CLASS="tools">© ' + siteName + ' ' + thisYear + '</P>');
}



/* ____________________________________________________

Generic Change-Class Function
____________________________________________________ */

function rollTo(piece,prefClass)
{
piece.className=prefClass;
}



/* ____________________________________________________

No Class Function
____________________________________________________ */

function deClass(targCell)
{
targCell.className='';
}



/* ____________________________________________________

MM Jump Menu
____________________________________________________ */

function jumpTo(targ,selObj,restore)
{
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}



/* ____________________________________________________

GO to a page
____________________________________________________ */

function go(destPage)
{
top.location=destPage
}



/* ____________________________________________________

Hide all menus
____________________________________________________ */

function m1()
{
document.getElementById('m3').style.display='none';
document.getElementById('m2').style.display='none';
document.getElementById('m1').style.display='inline';
}

function m2()
{
document.getElementById('m1').style.display='none';
document.getElementById('m3').style.display='none';
document.getElementById('m2').style.display='inline';
}

function m3()
{
document.getElementById('m1').style.display='none';
document.getElementById('m2').style.display='none';
document.getElementById('m3').style.display='inline';
}

function hideRecent()
{
document.getElementById('recentGridLo').className='visible';
document.getElementById('recentGrid').className='hidden';
}

function showRecent()
{
document.getElementById('recentGrid').className='visible';
document.getElementById('recentGridLo').className='hidden';
}

function showContents()
{
document.getElementById('contentsLo').className='hidden';
document.getElementById('contents').className='visible';
}

function hideContents()
{
document.getElementById('contents').className='hidden';
document.getElementById('contentsLo').className='visible';
}

/* ====================================================
Previous Pages
==================================================== */

function windowOpener(page,w,h)
{
window.open(page,'ImageZoom','resizable=yes,location=no,directories=no,toolbar=no,status=no,scrollbars=no,width='+ 800 + ',height='+ 600);
} 

/* Show or hide list of specific cars */

function toggleVehiclesList(currentState)
{
if (currentState == 'Car')
	{
	//alert(currentState);
	document.getElementById('vanList').className='hidden';
	document.getElementById('otherBox').className='hidden';
	document.getElementById('carList').className='visible';
	}
	
else if (currentState == 'Van')
	{
	//alert(currentState);
	document.getElementById('carList').className='hidden';
	document.getElementById('otherBox').className='hidden';
	document.getElementById('vanList').className='visible';
	}

else if (currentState == 'Other')
	{
	alert('Please detail the ideal vehicle you would like to hire in the box provided, thank you.');
	document.getElementById('carList').className='hidden';
	document.getElementById('vanList').className='hidden';
	document.getElementById('otherBox').className='visible';
	}
}

/* Checks for the referring page */

function checkReferrer(cameFrom)
{
//alert(cameFrom);
if (cameFrom == 'http://chiefrentals.peaknet.ltd.uk/north.html' || cameFrom == 'http://www.chiefrentals.com/north.html')
	{
	document.booking.recipient[2].checked=true;
	document.getElementById('everythingElse').className='visible';
	}
	
else if (cameFrom == 'http://chiefrentals.peaknet.ltd.uk/birmingham.html' || cameFrom == 'http://www.chiefrentals.com/birmingham.html')
	{
	document.booking.recipient[1].checked=true;
	document.getElementById('everythingElse').className='visible';
	}
	
else if (cameFrom == 'http://chiefrentals.peaknet.ltd.uk/torbay.html' || cameFrom == 'http://www.chiefrentals.com/torbay.html')
	{
	document.booking.recipient[0].checked=true;
	document.getElementById('everythingElse').className='visible';
	}
	
else { }
}

function map(panel)
{
	if(panel == "zooma")
	{
		document.getElementById("zooma").style.display='block';
		document.getElementById("mapa").style.display='none';
	}

	if(panel == "mapa")
	{
		document.getElementById("mapa").style.display='block';
		document.getElementById("zooma").style.display='none';
	}
	
	if(panel == "zoomb")
	{
		document.getElementById("zoomb").style.display='block';
		document.getElementById("mapb").style.display='none';
	}

	if(panel == "mapb")
	{
		document.getElementById("mapb").style.display='block';
		document.getElementById("zoomb").style.display='none';
	}
}


function golocal(local){

	/*
	if(!document.getElementById("redirect"))
	{
		//** Build image container div and place it at the bottom of the body **
		var body = document.getElementsByTagName("body")[0];
		var dv = document.createElement("div");
		body.appendChild(dv);
		dv.setAttribute("id", "redirect");
	}
	
	document.getElementById("redirect").innerHTML = '<div id="redirectmssg"><b>Chief Rentals Car and Van Hire</b><br /><br />You are now being redirect to our Booking site:<br /><br /> <span class="utxt">'+local+'</span><br /><br /><br /><img src="/gfx/loading.gif" alt="Redirecting..." class="redirectimg" /><a href="javascript:closemssg();" id="closem">close</a></div>';
	document.getElementById("redirect").style.display = "block";
	
	var tiou = setTimeout("window.location='"+local+"'", 2000);
	*/
	top.location = local;
	

}

function closemssg(){

	document.getElementById("redirect").style.display = "none";
	document.getElementById("redirect").innerHTML = '';

}


function changelink(){

//document.getElementById("chglink").setAttribute("href","javascript:golocal('http://www.chiefrentalscarhire.co.uk')");
document.getElementById("chglink").setAttribute("href","http://www.chiefrentalscarhire.co.uk");
document.getElementById("chglink").setAttribute("target","_blank");

}

function changelinkb(){

//document.getElementById("chglinkc").setAttribute("href","javascript:golocal('http://www.chiefrentalscarhire.co.uk/car_hire.html')");
//document.getElementById("chglinkv").setAttribute("href","javascript:golocal('http://www.chiefrentalscarhire.co.uk/van_hire.html')");

document.getElementById("chglinkc").setAttribute("href","http://www.chiefrentalscarhire.co.uk/car_hire.html");
document.getElementById("chglinkv").setAttribute("href","http://www.chiefrentalscarhire.co.uk/van_hire.html");
document.getElementById("chglinkc").setAttribute("target","_blank");
document.getElementById("chglinkv").setAttribute("target","_blank");

}

function apos(){

document.getElementById("redirect").style.marginTop = "90px";

}


function checkEnq() {

	var theform = "Required Fields";
	var origform = theform;
	
	cfname = document.enqform.realname.value;
	tcfemail = document.enqform.email.value; cfemail = tcfemail.match("@");
	tcfphone = document.enqform.phone.value; cfphone = tcfphone.replace(/ /gi,"");
	cfsubject = document.enqform.subject.value;
	cfmessage = document.enqform.message.value;
	cfsec = document.enqform.security.value;
	
	if(cfname == "" || cfname == " " || cfname == "  " || cfname == "   ")
	{
		document.getElementById("errorA").innerHTML = '<span class="errorin">Required Field!</span>';
		theform += "addme";
	}
	else
	{
		document.getElementById("errorA").innerHTML = "";
	}


	if(cfemail == "" || cfemail == null || cfemail == " " || cfemail == "  " || cfemail == "   ")
	{
		document.getElementById("errorB").innerHTML = '<span class="errorin">Not Valid!</span>';
		theform += "addme";
	}
	else
	{
		document.getElementById("errorB").innerHTML = "";
	}

	
	if(isNaN(cfphone) || cfphone == "" || cfphone == " " || cfphone == "  " || cfphone == "   ")
	{
		document.getElementById("errorC").innerHTML = '<span class="errorin">Not Valid!</span>';
		theform += "addme";
	}
	else
	{
		document.getElementById("errorC").innerHTML = "";
	}
	
	if(cfsubject == "" || cfsubject == " " || cfsubject == "  " || cfsubject == "   ")
	{
		document.getElementById("errorD").innerHTML = '<span class="errorin">Required Field!</span>';
		theform += "addme";
	}
	else
	{
		document.getElementById("errorD").innerHTML = "";
	}
	
	if(cfmessage == "" || cfmessage == " " || cfmessage == "  " || cfmessage == "   ")
	{
		document.getElementById("errorE").innerHTML = '<span class="errorin">Required Field!</span>';
		theform += "addme";
	}
	else
	{
		document.getElementById("errorE").innerHTML = "";
	}
	
	if(cfsec == "" || cfsec == " " || cfsec == "  " || cfsec == "   ")
	{
		document.getElementById("errorF").innerHTML = '<span class="errorin">Required Field!</span>';
		theform += "addme";
	}
	else
	{
		document.getElementById("errorF").innerHTML = "";
	}

	if (theform == origform)
	{
		document.enqform.submit();
		document.getElementById("errormsg").innerHTML = "";
		return true;
 	}
 	else
 	{
 		document.getElementById("errormsg").innerHTML = '<span class="errorin">Please fill in all required fields!</span>';
 		window.scrollTo(0,0);
 		return false;
 	}
}

