// JavaScript Document
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


// Find an object
function findObj(obj){
if (document.getElementById) { return document.getElementById(obj); } //DOM
else if (document.layers)	 { return document.obj; } //NN4
else if (document.all)		 { return document.all.obj; } //IE4+
}

// Show object and change class. If no class change needed, give empty string for CSSclass
function show(obj, CSSclass) {
	var obj = findObj(obj);
	obj.style.visibility = "visible";
	if (CSSclass != '') { obj.className = CSSclass; }
}

// Hide object
function hide(obj) {
	var obj = findObj(obj);
	obj.style.visibility = "hidden";
}


// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


// SERVICES

var total_services = 9;
var showText = "&raquo; Show Details";
var hideText = "&raquo; Hide Details";
var showAllText = "Show All";
var hideAllText = "Hide All";
var delimiter = "<span class=\"greylite\">|</span>"


// Function to run after loading Services page
function services_onload(){
	// Write HTML for the "Show All : Hide All" links
	var controlObj = findObj("showhide_control");
	controlObj.innerHTML = "<p><a href=\"services.php\">&raquo; Services: Overview</a> " + delimiter + " <a onclick=\"showBox()\">" + showAllText + "</a> " + delimiter + " <a onclick=\"hideBox()\">" + hideAllText + "</a></p>";
	
	// Show the first box and hide the others
	showBox(1);
	hideBox(2);
}


function showBox(){
	// var end is the last box to show
	if (arguments.length == 0) { var end = total_services; }
	else { var end = arguments[0]; }
	
	for (var num=1; num<=end; num++)
		{ replaceHTML(num, "show"); }
}

function hideBox(){
	// var start is the first box to hide
	if (arguments.length == 0) { var start = 1; }
	else { var start = arguments[0]; }
	
	for (var num=start; num<=total_services; num++)
		{ replaceHTML(num, "hide"); }
}

function replaceHTML(num, showhide){
	var divobj = findObj("service_div" + num);
	// Show or hide the box and change the "showhide" text link
	if (showhide == "hide")
		{
			divobj.style.display = "none";
			showhide_span(num, "show");
		}
	else
		{
			divobj.style.display = "block";
			showhide_span(num, "hide");
		}
}

function showhide_span(num, showhide){
	// Change the "showhide" text link
	if (showhide == "show") var linkText = showText;
	else var linkText = hideText;
	
	var spanobj = findObj("service_span" + num);
	spanobj.innerHTML = "<a onclick=\"replaceHTML('" + num + "','" + showhide + "')\">" + linkText + "</a>";
}

function sentence_case(str){
	// Convert text case to have first letter in uppercase
	return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
}


// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

// CONTACT FORM

function contact_onload(){
	if (getVar("quote") == "true")
		{
			title = findObj("title");
			title.innerHTML = "Request A Quote";
			return;			
		}

	
	// Write HTML for the "Show / Hide Details" links
	var showhide_span = findObj("showhide_span");
	showhide_Contact("show");
}


function showhide_Contact(showhide){
	var extra = findObj("extra");
	var spanobj = findObj("showhide_span");
	var msg_label = findObj("msg_label");

// Change the "showhide" text link
	if (showhide == "show")
		{
			//var linkText = "&raquo; Show extra options";
			var linkText = "&raquo; Show options below";
			extra.style.display = "none";
			msg_label.innerHTML = "Message <span class=\"red\">*</span>";
			var next_showhide = "hide";
		}
	else
		{
			//var linkText = "&laquo; Hide extra options";
			var linkText = "&laquo; Hide options below";
			extra.style.display = "block";
			msg_label.innerHTML = "Further information";
			var next_showhide = "show"
		}
	
	spanobj.innerHTML = "<a onclick=\"showhide_Contact('" + next_showhide + "')\">" + linkText + "</a>";
}


function getVar(name){ // http://scripts.franciscocharrua.com/javascript-get-variables.php
 get_string = document.location.search;         
 return_value = '';
 
 do { //This loop is made to catch all instances of any get variable.
	name_index = get_string.indexOf(name + '=');
	
	if(name_index != -1)
	  {
	  get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
	  
	  end_of_value = get_string.indexOf('&');
	  if(end_of_value != -1)                
		value = get_string.substr(0, end_of_value);                
	  else                
		value = get_string;                
		
	  if(return_value == '' || value == '')
		 return_value += value;
	  else
		 return_value += ', ' + value;
	  }
	} while(name_index != -1)
	
 //Restores all the blank spaces.
 space = return_value.indexOf('+');
 while(space != -1)
	  { 
	  return_value = return_value.substr(0, space) + ' ' + 
	  return_value.substr(space + 1, return_value.length);
					 
	  space = return_value.indexOf('+');
	  }
  
 return(return_value);        
}

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


// OPEN WINDOW
function open_window(url, x, y){
	child = window.open(url, "", "scrollbars=no,menubar=no,height=" + y + ",width=" + x + ",top=0,resizable=no,location=no,status=no");
}



function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}


// SAFE MAIL FUNCTIONS

function safeMail2(tld, domain, user, obj){
  var a,b;
  b = '@';
  a = 'mai';
  a+= 'lto:';
  user+= b + domain + '.' + tld;
  obj.href = a+user;
 }

function safeMail(text, domain, user){
  var a,b,c;
  a = '<' + 'a hr' + 'ef' + '="&#109;&#97;&#105;';
  b = '">';
  a+= '&#108;&#116;&#111;:';
  c = '&#0' + (60 + 4) +';';
  d = '</a>';
  if(text==''){text=user+' {at} '+domain;}
  user+= c + domain;
  document.write(a+user+b+text+d);
}


// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
