function showhide(id){
  if (document.getElementById(id).style.display == "none") show(id);
  else hide(id);
  
  
}

function em (name, domain){
	window.location = "mailto:" + name + "@" + domain;
}

function show(id){
    document.getElementById(id).style.display = "block";  
}

function fade(id){
	var browser = navigator.appName;
	if (browser != "Microsoft Internet Explorer") {
		document.getElementById(id).style.opacity = "0.4";	
	} else {
		document.getElementById(id).style.filter = "alpha(opacity = 40)";
	}
    

}
function recolor(id){
	var browser = navigator.appName;
	if (browser != "Microsoft Internet Explorer") {
		document.getElementById(id).style.opacity = "1";	
	} else {
		document.getElementById(id).style.filter = "alpha(opacity = 100)";
	}
}

function hide(id){
  
    document.getElementById(id).style.display = "none";  
  
}

function c(id){
  if (document.getElementById(id).checked==true)
    document.getElementById(id).checked=false;
  else
    document.getElementById(id).checked=true ;
}

function popup_booking(params){
    if (params == "") {
        params = "default";
    }
    var height = 630;
    var width = 600;

    var X = (screen.width/2)-(width/2);
    var Y = (screen.height/2)-(height/2);
    var pos = "left="+X+",top="+Y;
    window.Window = window.open("popup.php?action=viewonline_booking&booking_req="+params, "popup", "width="+width+", height="+height+","+pos+"");
}

function popup_wheel(){
	
	var height = 292;
	var width = 389;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window = window.open("popup.php\?action=view_wheel_info","Popup","width="+width+",height="+height+","+pos+",scrollbars=no, status=no, resizable=no, menubar=no");  
}

function popup_evoucher(eid){
	
	var height = 500;
	var width = 500;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window = window.open("popup.php\?action=view_evoucher&evoucher_id="+eid,"eVoucher","width="+width+",height="+height+","+pos+",scrollbars=no, status=no, resizable=false, menubar=yes");
}

function popup_service(){
	
	var height = 620;
	var width = 700;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window = window.open("popup.php\?action=view_service","Service","width="+width+",height="+height+","+pos+",scrollbars=yes, status=no, resizable=no, menubar=yes");  
}

function directions(){
  post_code = document.getElementById('post_code').value;
  
  if (post_code == "") {
    alert('Post Code Is Empty');
  } else {
    window.open("http://maps.google.co.uk/maps?f=d&hl=en&saddr="+post_code+"&daddr=EH3+9QT",'_blank');
    
  }  
  
}

// JavaScript Document
function DisableForm (formname)  {
  if(document.getElementById('next')) {
    document.getElementById('next').disabled = true;
    document.getElementById('next').className = "button_disabled";
  }

  if(document.getElementById('back')) {
    document.getElementById('back').disabled = true;
    document.getElementById('back').className = "button_disabled";
  }
	
  if(document.getElementById('complete')) {
    document.getElementById('complete').disabled = true;
    document.getElementById('complete').className = "button_disabled";
  }

  formname.submit();	
}

function popup_print_order(oid){
  var height = 600;
	var width = 700;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window = window.open("popup.php\?action=print_order&order_id="+oid,"Order","width="+width+",height="+height+","+pos+",scrollbars=yes, status=no, resizable=yes, menubar=yes");  
}

function popup_add_car(cust_id){
  var height = 400;
	var width = 389;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window = window.open("popup.php\?action=add_car&customer_id="+cust_id,"Popup","width="+width+",height="+height+","+pos+",scrollbars=no, status=no, resizable=no, menubar=no");  
}

function popup_edit_car(car_id, cust_id){
var height = 400;
	var width = 389;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window = window.open("popup.php\?action=edit_car&car_id="+car_id+"&customer_id="+cust_id,"Popup","width="+width+",height="+height+","+pos+",scrollbars=no, status=no, resizable=no, menubar=no");  
}

function popup_preview_reminder(r_id){
  var height = 400;
	var width = 550;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window2 = window.open("popup.php\?action=preview_reminder&reminder_id="+r_id,"Preview","width="+width+",height="+height+","+pos+",scrollbars=yes, status=no, resizable=no, menubar=no");  

}


function popup_preview_reminder(r_id,type){
  var height = 400;
	var width = 550;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window2 = window.open("popup.php\?action=preview_reminder&type="+type+"&reminder_id="+r_id,"Preview","width="+width+",height="+height+","+pos+",scrollbars=yes, status=no, resizable=no, menubar=no");  

}

function popup_preview_recipients(r_id,type){
  var height = 400;
	var width = 650;
	
	var X = (screen.width/2)-(width/2);
	var Y = (screen.height/2)-(height/2);
	var pos = "left="+X+",top="+Y;

	window.Window2 = window.open("popup.php\?action=preview_recipients&type="+type+"&reminder_id="+r_id,"Preview","width="+width+",height="+height+","+pos+",scrollbars=yes, status=no, resizable=no, menubar=no"); 

}

/*function append_text (id, string) {
  //document.getElementById(id).seltext
  document.getElementById(id).value += string;
  
}

// calling the function
insertAtCursor(document.formName.fieldName, �this value�);
*/
function append_text(id, myValue) {
myField = document.getElementById(id);

//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}

//myField.focus();

}



function sms_content_update() {
    var limit = 160;
   
    var old = document.getElementById('counter').innerHTML;
    var n = document.getElementById('sms_content').value.length;
   
    document.getElementById('counter').innerHTML = n;
    
    if (n > limit) {
      document.getElementById('counter').style.color="#ff0000";   
    } else {
      document.getElementById('counter').style.color="#000000";   
    }
   

}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789 ");
}


function validate_contact_form(){
  name = document.getElementById('name').value;
  email = document.getElementById('email').value;
  phone = document.getElementById('phone').value;
  msg = document.getElementById('msg').value;
  
  var error = "";
  
  if (name == "") error += "Name (blank)\n";
  if (email !="" && !isEmailAddr(email)) error += "Email Address (invalid)\n";
  if (phone !="" && !allDigits(phone)) error += "Phone Number (invalid)\n";
  if (msg == "")  error += "Message (blank)\n";
  if (email == "" && phone == "") error += "Please enter Email Address or Phone Number\n";
  
  
  if (error != "") {
    error = "The following fields have errors:\n" + error;
    alert(error);
    return false;
  } else {
    return true;
  }
}

function validate_callback_form(){
  name = document.getElementById('name').value;
  phone = document.getElementById('telephone').value;
  
  var error = "";
  
  if (name == "" || name=="name") error += "Name (blank)\n";
  if (phone == "" || !allDigits(phone)) error += "Phone Number (invalid)\n";
  
  
  if (error != "") {
    error = "The following fields have errors:\n" + error;
    alert(error);
    return false;
  } else {
    return true;
  }
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) {
			
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 	    
} 

function slideMenu(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
	
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) 
        { 
			setTimeout("changePos(" + i + ",'" + id + "')",(timer * speed)); 						
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
        {             
			setTimeout("changePos(" + i + ",'" + id + "')",(timer * speed));                 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changePos(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.position = "relative"; 
    object.top = opacity + "px";	
    object.display="";
} 

function fadeOut(id)
{
	opacity(id, 100, 0, 500);	
}

function fadeIn(id)
{
	opacity(id, 0, 100, 500);
}


function slideDown(id,flag)
{
	slideMenu(id,-180,0,500);
}

function shiftDown()
{

	slideDown("slidemn3");
	slideDown("slidemn2");
	slideDown("slidemn1");
	
	elem1 = document.getElementById("image1").style;
	elem1.display="";
	
	slideDown("menu5");
	slideDown("menu4");
	slideDown("menu3");
	slideDown("menu2");
	slideDown("menu1");
}

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 var 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 eraseCookie(name) {
	createCookie(name,"",-1);
}
