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

function showhide_row(id){
  
    if (document.getElementById(id).style.display == "none") document.getElementById(id).style.display='';
    else document.getElementById(id).style.display='none';    
  }

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

function show(id){
    document.getElementById(id).style.display = "block";  
    //document.getElementById(id).style.display = "table-row-group";  
}

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

function c(id){
  if (document.getElementById(id).checked==true && document.getElementById(id).type != "radio")
    document.getElementById(id).checked=false;
  else
    document.getElementById(id).checked=true ;
}

function group_checkbox(cb, g) {
	c(cb);
	
	if (document.getElementById(cb).checked == true) {
		document.getElementById(g).style.display='';    
	} else {
		document.getElementById(g).style.display='none';    
	}
	
}

function group_checkbox2(cb, g) {
	if (document.getElementById(cb).checked == true) {
		document.getElementById(g).style.display='';    
	} else {
		document.getElementById(g).style.display='none';    
	}
	
}


// 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_list_order_changes(oid){
  var height = 350;
	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=list_order_changes&order_id="+oid,"Order","width="+width+",height="+height+","+pos+",scrollbars=yes, status=no, resizable=yes, menubar=yes");  
}

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_order_form(){
  name = document.getElementById('name').value;
  email = document.getElementById('email').value;
  phone = document.getElementById('phone').value;
  msg = document.getElementById('msg').value;
  package = document.getElementById('package').value;
  video = document.getElementById('video').value;
  parent = document.getElementById('parent').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_brochure_form(){
  name = document.getElementById('name').value;
  address = document.getElementById('address').value;
  email = document.getElementById('email').value;
  
  var error = "";
  
  if (name == "") error += "Name (blank)\n";
  if (email == "") error += "Email Address (blank)\n";
  if (email != "" && !isEmailAddr(email)) error += "Email Address (invalid)\n";
  if (address == "")  error += "Address (blank)\n";
  
  
  if (error != "") {
    error = "The following fields have errors:\n" + error;
    alert(error);
    return false;
  } else {
    return true;
  }
}

function update_complete() {
	theform = document.getElementById('complete_form');
	var total = parseInt(document.getElementById('base_price').value);
	var temp = '<table class="full">';
	
	
	for (i=0; i < theform.length; i++)  {
		//temp = temp + theform[i].name + "\n";
		
		if (theform[i].checked == true && theform[i].id.substr(0,3) != "bvg") {
			if (document.getElementById(theform[i].id+"_p")) {
				temp = temp + '<tr> <td class="left" style="font-size:10px;">';
				temp = temp + document.getElementById(theform[i].id+"_d").value + '</td> <td class="right">&pound;';
				temp = temp + document.getElementById(theform[i].id+"_p").value + "</td> </tr>";

				total = total + parseInt(document.getElementById(theform[i].id+"_p").value);
			}
		} else {
			
			if (theform[i].checked == true && theform[i].id.substr(0,3) == "bvg") {
				
				id = theform[i].name.replace("group[","");
				id = id.replace("]","");
				
				if (document.getElementById("bv_"+id).checked) {
				
					temp = temp + '<tr> <td class="left" style="font-size:10px;">';
					temp = temp + document.getElementById(theform[i].id+"_d").value + '</td> <td class="right">&pound;';
					temp = temp + document.getElementById(theform[i].id+"_p").value + "</td> </tr>";
	
					total = total + parseInt(document.getElementById(theform[i].id+"_p").value);
				}
			} 			
			
		}

	}
	
	if (temp == '<table class="full">') temp = temp + '<tr> <td colspan="2" class="center"> <em> No Customisation </em> </td> </tr>';
	
	
	//temp = temp + '<tr> <td colspan="2" class="right" style="border-top:1px solid #000000; font-weight:bolder;">&pound;' + total + '</td> </tr>';
	
	temp = temp + "</table>";
	
	document.getElementById('chosen').innerHTML=temp;
	document.getElementById('price').innerHTML=total;
	
}

function update_custom() {
	theform = document.getElementById('custom_form');
	var total = parseInt(document.getElementById('base_price').value);
	var temp = '<table class="full">';
	var j = 0;
	
	for (i=0; i < theform.length; i++)  {
		//temp = temp + theform[i].name + "\n";
		
		if (theform[i].checked == true && theform[i].id.substr(0,3) != "bvg") {
			if (document.getElementById(theform[i].id+"_p")) { //theform[i].value != 1
				j++;
				temp = temp + '<tr> <td class="left" style="font-size:10px;">';
				temp = temp + document.getElementById(theform[i].id+"_d").value + '</td> <td class="right">&pound;';
				temp = temp + document.getElementById(theform[i].id+"_p").value + "</td> </tr>";

				total = total + parseInt(document.getElementById(theform[i].id+"_p").value);
			}
		} else {
			
			if (theform[i].checked == true && theform[i].id.substr(0,3) == "bvg") {
				
				id = theform[i].name.replace("group[","");
				id = id.replace("]","");
				
				if (document.getElementById("bv_"+id).checked || document.getElementById("bv_"+id).type == "hidden") {
					j++;
					temp = temp + '<tr> <td class="left" style="font-size:10px;">';
					temp = temp + document.getElementById(theform[i].id+"_d").value + '</td> <td class="right">&pound;';
					temp = temp + document.getElementById(theform[i].id+"_p").value + "</td> </tr>";
	
					total = total + parseInt(document.getElementById(theform[i].id+"_p").value);
				}
			} 			
			
		}

	}
	
	if (temp == '<table class="full">') temp = temp + '<tr> <td colspan="2" class="center"> <em> No Customisation </em> </td> </tr>';
	
	
	temp = temp + "</table>";
	
	document.getElementById('chosen').innerHTML=temp;
	
	//alert(document.getElementById('chosen').innerHTML);
	
	var totalp = '<table class="full"> <tr> <td colspan="2" class="right" style="border-top:1px solid #000000; font-weight:bolder;">&pound;' + total + '</td> </tr></table>';

	document.getElementById('total_price').innerHTML=totalp;
	
	//var right_height = parseInt(document.getElementById('right_height').value) + parseInt((j*100));
	
	//alert(right_height);
	
	//document.getElementById('right_bar').style.background="url("+SITE_ADDRESS+"'image.php?path=assets/images/main/image18.jpg&height='"+right_height+")";
	
	
}