/*************************************************************/ 
/*

$Author: bobo $ 
$Modtime: 2005-06-17 16:07:27+01:00 $ 

*/
/*************************************************************/


// Text Changer device
// Size values are used as percentage font size for BODY element)

LARGE  = 120
MEDIUM = 100
SMALL  = 76          // the default (same as BODY font-size in style sheet)
HILITE = '#BDD8FF'   // currently-selected text sizer background colour
BG     = '#79AEFF'   // regular background colour
DAYS   = 365         // days to retain cookie which remembers user choice of text size

/*************************************************************/

window.onload = checkTextSize

// Conditional compile for IE 5.0 and above only.
// Removes right hand slogan div under a certain window width
// and prevents main content div from becoming too narrow

/*@cc_on @*/
/*@if (@_jscript_version >= 5)

var minWidth = 700;

window.attachEvent("onload", checkWidth);
window.onresize = checkWidth;

function checkWidth()  
{
	if(document.body.offsetWidth <= minWidth)
	{
		document.getElementById('sloganpanel').style.visibility ='hidden';
		document.getElementById('content').style.paddingRight = "0"
		document.getElementById('content').style.width = "465px"
		document.getElementById('ruler').style.width = "665px"
	}
	else 
	{
		document.getElementById('sloganpanel').style.visibility ='visible';
		document.getElementById('content').style.paddingRight = "180px"
		document.getElementById('content').style.width = "auto"
		document.getElementById('ruler').style.width = "100%"
	}
}
@end @*/

function checkTextSize()
{
   // retrieves any cookie-stored text size preference
   var cookie = readCookie("TextSize");
   if (cookie != null) setTextSize(cookie) 
}
                           
function setTextSize(strSize) 
{
   // sets font size in percent for BODY and highlights user choice

   // get matching numeric font size value for strSize (defined as constant)
   intFontSize = eval(strSize.toUpperCase())
   if (intFontSize.NaN) intFontSize = SMALL 

   document.body.style.fontSize = intFontSize + "%"
   highlight(strSize)
   createCookie("TextSize", strSize, DAYS);

   // Firefox type browsers workaround to get the text 
   // to re-render properly after a font resize
   if (checkBrowser() == "Netscape Navigator 5") doWindowResizeHack()
}


function highlight(strID)
{
 // toggles highlighting by applying hilite colour to current text size link
 // and reverting the other two elements to the BG colour
    
	if (strID == "large")
    {
       document.getElementById("small").style.backgroundColor = BG
       document.getElementById("medium").style.backgroundColor = BG
	}
	else if (strID == "medium")
    {
       document.getElementById("small").style.backgroundColor = BG
       document.getElementById("large").style.backgroundColor = BG
	}
	else // default
    {
	   strID = "small"
       document.getElementById("medium").style.backgroundColor = BG
       document.getElementById("large").style.backgroundColor = BG
	}
    document.getElementById(strID).style.backgroundColor = HILITE
}


function createCookie(name,value,days) 
{
   if (days) 
   {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
   }
   else expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) 
   {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}


function validate(formname) 
{

	// Prompts for confirmation before deletion, where applicable
	if (typeof(formname.delconf) == 'object')
	{ 
		if (formname.delconf.value == "Yes")
		{
			if (confirm("Are you sure you want to delete this record?")) 
				return true;
			else
				return false;
		}
	}

    // this used on Quotation form
	if (formname.name == 'quote')
	{
		if (formname.Postcode.value == "")
		   {
		       alert("Please fill in your current Post Code. Thank you.")
			   return false;
		   }

		if ( (formname.Email.value == "") && (formname.Phone.value == "") )
		   {
		       alert("Please fill in a contact email address or phone number. Thank you.")
			   return false;
		   }
	}

    // this used on Instruct Us form
	if (formname.name == 'instruct')
	{

		if (formname.RefName.value == "")
		   {
		       alert("Please fill in the Referrer company name. Thank you.")
			   return false;
		   }
		if (formname.RefBranch.value == "")
		   {
		       alert("Please fill in the Referrer branch name. Thank you.")
			   return false;
		   }
		if (formname.RefReference.value == "")
		   {
		       alert("Please fill in the Referrer initials. Thank you.")
			   return false;
		   }
		if (formname.Terms.checked == false)
		{
		   alert("Please tick the box to indicate your acceptance of the Terms and Conditions. Thank you.")
		   return false;
		}
	}

    // this used on HIPS form
	if (formname.name == 'hips')
	{

		if (formname.OwnerSurname.value == "")
		   {
		       alert("Please fill in the Owner Surname. Thank you.")
			   return false;
		   }
		if (formname.Address.value == "")
		   {
		       alert("Please fill in the property Address. Thank you.")
			   return false;
		   }

	}

    // this only used on the Logon form
	// and only if there is a "Terms Read" check box

	if ( (formname.name == 'logon') && 
		 (typeof(formname.logon_terms) == 'object')
		)
	{
		if (formname.logon_terms.checked == false)
		{
		   alert("Please tick the box to show you have read the Terms and Conditions. Thank you.")
		   return false;
		}
	}

    // if Referrer PostCode field exists, strip out any whitespace
	if (typeof(formname.FORM_rofPostCode) == 'object')
	{
		oldPC = formname.FORM_rofPostCode.value
		cleanPC = oldPC.replace(" ", "")
		formname.FORM_rofPostCode.value = cleanPC
    }

    // if password editing field exists, disallow a blank one
	if (typeof(formname.FORM_logPassword) == 'object')
	{
		if (formname.FORM_logPassword.value == '')
		{
		   alert("Please enter a password. This field cannot be blank. Thank you.")
		   return false;
		}
    }

    // permit submission by default
	return true; 
}

function doToday()
{
    var mydate = new Date()
    var year = mydate.getYear()
    var month = mydate.getMonth()
    var daym = mydate.getDate()
    if (daym < 10) daym = "0" + daym
    var aMonth = new Array("January","February","March",
    "April","May","June","July","August","September","October",
    "November","December")
    document.write(daym + ' ' + aMonth[month] + ', ' + year)
}

 
function doWindowResizeHack()
{
   // force a 1px window width resize followed by 
   // an immediate return to the original window width
   // to work around some text-resizing bugs, notably in FireFox 1.0
 
   var winWidth = window.innerWidth 
   window.innerWidth = winWidth - 1
   window.innerWidth = winWidth
}


// vars used by checkBrowser() & checkIt() from www.quirksmode.org
var detect = navigator.userAgent.toLowerCase();
var OS, browser, version, total, thestring;

function checkBrowser()
{
	
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}

	return browser + " " + version  // + " " OS
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


