// JavaScript Document

var sMenu = 1;
var tMenu =1;
var tParent = null;
var currentPage = null;
var currentSMenu = null;
var currentSBG = null;
var currentSC = null;
var pageId = null;
var sectionId = null;
var pageType;
var promoInterval;
var Ypos = 0;
var	Xpos = 0;
var hoverClassName = 'briefImage';
function init(){
	//new Resizable('columnOne', {constraint:'horizontal', onResize:updateColOne});
	//new Resizable('header', {constraint:'vertical'});
	if($('secondul')){
		$('secondul').onmousedown = $('secondul').onselectstart = function(){return false;}
	}
	
	/*
	if($('promoLine')){
		loadPromoLine();
		promoInterval = setInterval(loadPromoLine, 5000);
	}
	*/
 
  
}



function userSearch(){
	var searchVal = $('searchInput').value;
	redirect('page.php?section=85&searchString='+searchVal);
}

function showTotalBrief(id){
	
	
	// <![CDATA[	
	showBriefSolution = 1;			
	var ajax;
	var d = new Date();
	var t = d.getTime();
	
	ajax =  new
	Ajax.Updater(
		 "solutionBriefText",        		// DIV id must be declared before the method was called
		 'ajax/tsBrief.php?t='+t+'&id='+id,{method:'get',asynchronous:true, onComplete:startBubbleFollow});

	// ]]>
	
}

function startBubbleFollow(){
	document.onmousemove=MouseFollow;
	fadein('solutionBrief');
	//MouseFollow(event);
	
}

function checkMouseOver(e){
	BrowserDetect.init();
	if(BrowserDetect.browser == 'Firefox' || BrowserDetect.browser == 'Safari' || BrowserDetect.browser == 'Chrome'){
		var eSrc = e.target;
		var trimmed = eSrc.className.replace(/^\s+|\s+$/g, '') ;
		hoverClassName = trimmed;
		
		
	}else{
		var eSrc = event.srcElement;
		var trimmed = eSrc.className.replace(/^\s+|\s+$/g, '') ;
		hoverClassName =trimmed;
		
	}
}

function MouseFollow(e){
	document.onmouseover = checkMouseOver; 
	
	if(hoverClassName == 'briefImage'){
		BrowserDetect.init();
		if(BrowserDetect.browser == 'Firefox' || BrowserDetect.browser == 'Safari' || BrowserDetect.browser == 'Chrome'){
			$('solutionBrief').style.top = (window.pageYOffset+e.clientY)-35+"px";
			$('solutionBrief').style.left = (window.pageXOffset+e.clientX)+20+"px";
		}else{
			$('solutionBrief').style.top = document.documentElement.scrollTop+event.clientY-35;
			$('solutionBrief').style.left = document.documentElement.scrollLeft+event.clientX+20;
		}
	}else{
		hideDivQuick('solutionBrief');		
	}
}

function hideTotalBrief(id){
	$('solutionBrief').style.display = 'none';
	// alertTimerId = setTimeout ( "hideDivQuick('solutionBrief')", 500 );	
	
}
function hideDivQuick(divId){
	 $(divId).style.display = 'none';	
}

function hideDiv(divId){
		
	new Effect.Fade(divId);
}

function displayTotalSolution(id){
	//$('solutionContent').style.display = 'none';	

	switch(id){
		case 55:
			document.location.href='page.php?section=118';
		break;
		case 57:
			document.location.href='page.php?section=118';
		break;
		case 58:
			document.location.href='page.php?section=118';
		break;
		case 59:
			document.location.href='page.php?section=118';
		break;
		case 60:
			document.location.href='page.php?section=118';
		break;
		case 61:
			document.location.href='page.php?section=118';
		break;
		case 56:
			document.location.href='page.php?section=117';
		break;
		
	}
	/*
	this is what we use to do but alas another change was made.
	// <![CDATA[	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	
	ajax =  new
	Ajax.Updater(
		 "solutionContent",        		// DIV id must be declared before the method was called
		 'ajax/totalSolution.php?t='+t+'&id='+id,{method:'get',asynchronous:true, onComplete:showSolution});

	// ]]>
	*/
}

function showSolution(){
	new Effect.Appear('solutionContent');	
}

function fadein(divid){
	
	new Effect.Appear(divid, {duration:0.5, from:0.0, to:1.0});	
}


function loadPromoLine()
{
	
   
	
	$('promoLine').style.display = 'none';	
	// <![CDATA[	
	var ajax;
	var d = new Date();
	var t = d.getTime();
	
	ajax =  new
	Ajax.Updater(
		 "promoLine",        		// DIV id must be declared before the method was called
		 'ajax/promoLine.php?t='+t,{method:'get',asynchronous:true, onComplete:showPomoLine});

	// ]]>
	
}


function showPomoLine(){
	new Effect.Appear('promoLine');	
}


function displayVideo()
{

	// <![CDATA[	
	clearInterval(promoInterval);
	var ajax, ajax2;
	var d = new Date();
	var t = d.getTime();
	//$('promoLine').style.display = 'none';	
	$('homeBanner').style.display = 'none';
	$('leftTopCorner').style.display = 'block';
	$('leftBottomCorner').style.display = 'block';
	$('videoContainer').style.display = 'block';
	
	$('homeContentText').style.display='none';
	$('homeContent1_left').style.backgroundImage = 'none';
	
	
	
	ajax = new Ajax.Updater(
		 "homeContentText",        		// DIV id must be declared before the method was called
		 'ajax/displayVideoText.php?t='+t,{method:'get',asynchronous:true, onComplete:showVideoText});

	// ]]>
	
}


function showVideoText()
{
			
	new Effect.Appear('homeContentText');

}

function showVideo(){
		
}

function updateColOne(resizable, event){
	var delta = resizable.currentDelta();
	$('columnTwo').style.width = (970 - delta[0]-55)+"px";
	$('columnOne').innerHTML = delta[0];
}

function redirect(url){
	document.location.href=url;	
}


function openWindow(url){
	myRef = window.open(url,'mywin',
'left=0,top=0,width=1024,height=600,toolbar=0,resizable=1,scrollbars=1');

}
function primaryMenu(id)
{
	// <![CDATA[	
	alert('test');
	var ajax;
	var d = new Date();
	var t = d.getTime();
	
	ajax =  new Ajax.Updater(
		 "pageContent",        		// DIV id must be declared before the method was called
		 'ajax/pageContent.php?id='+id+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage});

	// ]]>
}



function setMenuOn(){
	sMenu = 1;	
}

function setTMenuOn(){
	tMenu = 1;	
}
 
function rollover(divId){
	//$('header').innerHTML = divId +':'+tParent;
	
	if($(divId).className != 'on'){
		$(divId).style.backgroundColor = '#d1d1d1';
		$(divId).style.color = '#3F78A1';
	}
	
}
function rollout(divId){
	if($(divId).className != 'on'){
		$(divId).style.backgroundColor = '#f8f8f8';
		$(divId).style.color = '#333';
	}
	parentId = null;
}

function rollover2(divId, parentId){
	tParent = parentId;
	if(divId != currentSMenu){
		
		$(divId).style.backgroundColor = '#d1d1d1';
		$(divId).style.color = '#FFF';
	}
}
function rollout2(divId){
	
	tParent = null;
	if(currentSMenu != divId){
		$(divId).style.backgroundColor = '#FFFFFF';
		$(divId).style.color = '#5b5b5b';
	}
}

function closeSubMenu(pId){
	
	if($('tert_'+pId).style.display == ''){
		
		new Effect.BlindUp('tert_'+pId);
	}
	
}

function secondaryMenu(pId, sId, obj){	
	// <![CDATA[
	currentSMenu = sId;			
	document.location.href='page.php?section='+sId;			
	pageId = pId;
	sectionId = sId;
	
	if($('tert_'+pId)){	
		if($('tert_'+pId).style.display == 'none'){	
			
			new Effect.Appear('tert_'+pId);
			new Effect.Fade('arrow_'+pId);
		}
	}
	setTimeout ( "setMenuOn()",500);
	
	
	
	if(sMenu == 1){
		if(currentSMenu != null){
			$(currentSMenu).morph("background-color:"+currentSBG+";color:"+currentSC+";");
		}
		currentSMenu = 'secondLi_'+pId;
		currentSBG = "#f8f8f8";
		currentSC = "#333";
		$('secondLi_'+pId).morph("background-color:#ababab;color:#FFF;");	
		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "pageContent",        		// DIV id must be declared before the method was called
			 'ajax/pageContent.php?pId='+pId+'&sId='+sId+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage, onFailure:showError});
	
		sMenu = 0;	
	}
	// ]]>
}

function tertiaryMenu(pId, sId, obj){	
	// <![CDATA[
	document.location.href='page.php?section='+sId;				
	pageId = pId;
	sectionId = sId;
	
	if($('tert_'+pId)){			
		new Effect.Appear('tert_'+pId);
	}
	setTimeout ( "setMenuOn()",1000);
	
	
	if(sMenu == 1){
		if(currentSMenu != null){
			$(currentSMenu).morph("background-color:"+currentSBG+";color:"+currentSC+";");
		}
		currentSMenu = 'secondLi_'+pId;
		currentSBG = "#FFFFFF";
		currentSC = "#5b5b5b";
		$('secondLi_'+pId).morph("background-color:#ababab;color:#FFF;");
		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "pageContent",        		// DIV id must be declared before the method was called
			 'ajax/pageContent.php?pId='+pId+'&sId='+sId+'&t='+t,{method:'get',asynchronous:true, onSuccess:showPage, onFailure:showError});
	
		sMenu = 0;	
	}
	// ]]>
}

function showError(req){
	$('pageContent').innerHTML = req.responseText+"<br />Please try again";
}

function showPage(){

	if($('pageContent')){
		
	//	new Effect.Appear('pageContent');	
	}
	
}

function showJournal(id){
	$('journal_'+id).morph("height:100%");
	
}
function divOn(div)
{	
	document.getElementById(div).style.display = 'block';	
}

function getAddress(postcode, divId){
	// <![CDATA[
		if((postcode.length >= 2 && postcode.length <= 8) && IsAlphaNumeric(postcode)){
			
			new Effect.Appear('saRow');	
			
			
			new Effect.Appear('addressDisplay');
			$('addressDisplay').innerHTML = ' <img src="images/loader.gif" /> <span style="background:transparent;">loading...</span>';
			/*
			if($('mainError') != null){	 
				new Effect.Fade('mainError');
			}
			
			if($('selectedAddress') != null){	 
				new Effect.Fade('selectedAddress');
			}
		*/
			var ajax;
			var d = new Date();
			var t = d.getTime();
			
			ajax =  new Ajax.Updater(
				 divId,        		// DIV id must be declared before the method was called
				 'ajax/getAddress.php?postcode='+postcode+'&divId=selectedAddress&t='+t,{method:'get',asynchronous:true, onSuccess:maybeShow});
		}else{
			alert('The postcode must be alpha-numeric and between 2 and 8 characters.');	
		}
		
		
	// ]]>
}


function maybeShow(req){
	var resp = req.responseText; 
	
	if(resp.indexOf('<span>') >= 0){
		addr = resp.substring((resp.indexOf('value="')+7),resp.indexOf('">',resp.indexOf('value="') ) ); 
		
		//new Effect.Appear('finalAddress');	
		//showFinalAddress(addr);
	}
	$('address').focus();
	$('address').select();
	
}
	
function showFinalAddress(address, divId){
	// <![CDATA[
		new Effect.Appear('addieTimeRow');		
		if($('addieTime0').checked == true){
			checkapply2($('page2'));
		}
		
		new Effect.Appear('address1');
		new Effect.Appear('selectedAddress');
		
		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 divId,        		// DIV id must be declared before the method was called
			 'ajax/displayAddress.php?address='+address+"&t="+t,{method:'get',asynchronous:true});
		/*if(effects){	
		 new Effect.toggle('hide_'+divId);
		}*/
	 
	// ]]>
}	
	
function IsNumeric(strString){
  //  check for valid numeric strings	

   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
		 {
		 blnResult = false;
		 }
	  }
   return blnResult;
}

function IsAlphaNumeric(strString){
  //  check for valid numeric strings	

   var strValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
		 {
		 blnResult = false;
		 }
	  }
   return blnResult;
}


function checkAddie1(){
	if($('address').value != ""){
		checkapply2($('page2'));
	}else{
		alert('Please select an address');	
	}
}


function checkContactForm(theform)
{
	// <![CDATA[
	fields = "";
	valid = true;

	if(theform.firstname.value == ""){
		fields += "You must enter a First name.\n";
		theform.firstname.className='inputError';
		valid = false;
	}
	if(theform.surname.value == ""){
		fields += "You must enter a Surname.\n";
		theform.surname.className='inputError';
		valid = false;
	}
	
	if(theform.email.value == ""){
		fields += "You must enter an Email Address.\n";
		theform.email.className='inputError';
		valid = false;
	}
	
	if(theform.postcode.value == ""){
		fields += "You must enter a Postcode.\n";
		theform.postcode.className='inputError';
		valid = false;
	}
	
	if(theform.enquiry.value == ""){
		fields += "You must enter an Enquiry.\n";
		theform.enquiry.className='inputError';
		valid = false;
	}

	
	
	if(valid == false){
		new Effect.Appear('formError');
		return(false);
	}else{
		var d = new Date();
		var t = d.getTime(); 
		var crypticVal = theform.cryptic.value.toUpperCase();	
		
		var result = new Ajax.Request('ajax/checkCrypt.php?cryptic='+crypticVal+'&date='+t, {method: 'get', asynchronous:'true',
		  onSuccess: function(transport) {
				
				if (transport.responseText == "false"){
					alert("You must enter the correct security code");
					secureCheck = "false";
					
				}else{
					
					document.getElementById('contactor').action = 'actions/processContactForm.php';
					document.getElementById('contactor').submit();
				}
		  }
		});
		
		return(false);	
	}
		
	// ]]>
}


function refreshCryptImage(){
		var randomnumber=Math.floor(Math.random()*11);
		document.images['cryptImage'].src = 'includes/crypt.php?t='+randomnumber;	
	}

function checkapply2(theform){
	// <![CDATA[
	 
	 
	var ajax, ajax2;
	var d = new Date();
	var t = d.getTime(); 
	var validation = "false";
	new Effect.Appear('validationError');
		
	if(theform.address){ 
		new Ajax.Request('ajax/URUcheck1.php?address='+theform.address.value+'&date='+t, {
		  method: 'get',evalScripts: true, asynchronous:'true',
		  onSuccess: function(transport) {
			var valErrror = $('validationError');
			
			if (transport.responseText < 1001){
				document.location.href='apply2.php?error=points';	
			}else if(transport.responseText >= 1001 && transport.responseText <= 1109){
			  $('continueHolder').innerHTML = "<input type=\"submit\" name=\"submitter\" class=\"input\" value=\"Continue\" />";
			  new Effect.Appear('drivingLicenseRow');	
			  new Effect.Appear('passport1Row');	
			  new Effect.Appear('passport2Row');	
			  validation = "false";		
			  valErrror.update('<span style=\"color:#ff0000;font-weight:bold;\">Your details do not provide us with enough information, please provide either your Drivers license or Passport number. ');
			}else{
				
			  validation = "true";
			  valErrror.update('<span style=\"color:#0A8326;font-weight:bold;\">Your details have been confirmed, please wait.......</span>');
			  theform.submit();
			}
		  }
		});
	}else{
		document.location.href='apply2.php?error=points';
	}
	// ]]>
	return false;
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

function showCountryBox(){
$('flag_box').style.display = ''	
$('choose_country_box').style.borderColor = '#000000'	
$('choose_country_box').style.borderBottomWidth = '0px'	
$('choose_country_box').style.borderBottomColor = '#ffffff'	
$('choose_country_box').style.color = '#000000'	
}

function hideCountryBox(){
$('flag_box').style.display = 'none'	
$('choose_country_box').style.borderColor = '#507090'	
$('choose_country_box').style.borderBottomWidth = '1px'	
$('choose_country_box').style.color = '#507090'	
}
