var home_scrolling = true;
var home_manual_scrolling = false;
var active_scrolling = 1;

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_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">';
	
	var pre = document.getElementById('pre').value+"_";
	var pren;
	
	if (pre == "s_") pren = "p_";
	else pren = "s_";
	
	for (i=0; i < theform.length; i++)  {
		//temp = temp + theform[i].name + "\n";
		if (theform[i].id.substr(0,5) != pren+"bvg" && theform[i].id.substr(0,4) != pren+"bv") {
		
			if (theform[i].checked == true && theform[i].id.substr(0,5) != pre+"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;';
					
					if(document.getElementById(theform[i].id+"_t").value == "stan") {
						temp = temp + document.getElementById(theform[i].id+"_p").value + "</td> </tr>";
					} else {
						
						temp = temp + (parseInt(document.getElementById(theform[i].id+"_p").value)-300) + "</td> </tr>";
					}
					total = total + parseInt(document.getElementById(theform[i].id+"_p").value); 
				}
			} else {
				
				if (theform[i].checked == true && theform[i].id.substr(0,5) == pre+"bvg") {
					
					id = theform[i].name.replace(pre+"group[","");
					id = id.replace("]","");
					
					if (document.getElementById(pre+"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 + "</table>";
	
	document.getElementById('chosen').innerHTML=temp;
	document.getElementById('price').innerHTML=total;
	
}

function venue_type(t) {
	if (t == "p") {
		document.getElementById('pre').value = 'p';
		document.getElementById('std').style.display='none'
		blenddiv('prem', 'prem', 600)
	} else {
		document.getElementById('pre').value = 's';
		document.getElementById('prem').style.display='none'
		blenddiv('std', 'std', 600)
	}
	
}

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;
	
	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;
	
	
}


function clear_text(obj, text) {
	
	if (obj.value == text) obj.value = '';
	
}

function put_text(obj, text) {
	
	if (obj.value == '') obj.value = text;
	
}

function scroll_prev() {
	home_scrolling = false;
	home_manual_scrolling = true;

	if (active_scrolling > 1) active_scrolling --;
	else active_scrolling = 3;
	
	home_banner(active_scrolling,false);

}

function scroll_next() {
	home_scrolling = false;
	home_manual_scrolling = true;

	if (active_scrolling < 3) active_scrolling ++;
	else active_scrolling = 1;
	
	home_banner(active_scrolling,false);


}


function home_banner(id,s) {
	var ids = Array(3);
	var active_id = 1;
	
	ids[1] = 'home-banner-packages';
	ids[2] = 'home-banner-venues';
	ids[3] = 'home-banner-hotels';
	
	
	// Get Active 
	if (document.getElementById(ids[1]).style.display=='block') active_id = 1
	if (document.getElementById(ids[2]).style.display=='block') active_id = 2
	if (document.getElementById(ids[3]).style.display=='block') active_id = 3
	
	//if (active_id != id) 
	blenddiv(ids[active_id], ids[id], 600);
	
	document.getElementById('button_'+active_id).className='home-banner-buttons';
	document.getElementById('button_'+id).className='home-banner-buttons-active';
	
	
	if (s) home_scrolling = false;
	
}


function scolling(next) {
	if (home_scrolling) {
		if (active_scrolling < 3) active_scrolling ++
		else active_scrolling = 1;
		
		home_banner(active_scrolling,false);
	}
	
}

function scolling_on() {
	if (home_manual_scrolling == false) home_scrolling=true;
}

function scolling_off() {
	home_scrolling=false;
}

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 shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function blenddiv(divid, div2id, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	//document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	hide(divid);
	changeOpac(0, div2id);
	show(div2id);
	//make new image
	//document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + div2id + "')",(timer * speed));
		timer++;
	}
	
	
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function addBookmark(title,url) {
if (window.sidebar) { 
window.sidebar.addPanel(title, url,""); 
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}

function show_review_form() {
	document.getElementById('show_link').style.display='none';
	document.getElementById('review_wrapper').style.display='block';
}


function star_select(n) {
	document.getElementById('rrating').value = n;
}

function star_hide() {
	if (document.getElementById('rrating').value < 1 || document.getElementById('rrating').value == "" ) {
		for (i=1;i<=5;i++) {
			document.getElementById('star_'+i).src=SITE_ADDRESS+'assets/images/v3/star-none.png';
		}
	} else {
		var n = document.getElementById('rrating').value;
		for (i=1;i<=5;i++) document.getElementById('star_'+i).src=SITE_ADDRESS+'assets/images/v3/star-none.png';
		for (i=1;i<=n;i++) document.getElementById('star_'+i).src=SITE_ADDRESS+'assets/images/v3/star.png';
	}
}

function star_highlight(n) {
	
	
	var i;
	for (i=1;i<=n;i++) {
		document.getElementById('star_'+i).src=SITE_ADDRESS+'assets/images/v3/star.png';
	}
	
}


function switch_tabs(id) {
	if (id == 1) {
		document.getElementById('home-tab-1').style.display = 'block';
		document.getElementById('tab-img-1').src = SITE_ADDRESS+'assets/images/v4/home-circle-1-active.png';
		document.getElementById('tab-1').className='tab-active'

		document.getElementById('home-tab-2').style.display = 'none';
		document.getElementById('tab-img-2').src = SITE_ADDRESS+'assets/images/v4/special-offers.gif';
	}
	
	if (id == 2) {
		document.getElementById('home-tab-1').style.display = 'none';
		document.getElementById('tab-img-1').src = SITE_ADDRESS+'assets/images/v4/home-circle-1.png';
		document.getElementById('tab-1').className='tab'


		document.getElementById('home-tab-2').style.display = 'block';
		document.getElementById('tab-img-2').src = SITE_ADDRESS+'assets/images/v4/special-offers-active.gif';
	}
}

function switch_tabs2(id) {
	if (id == 1) {
		document.getElementById('home-tab-1').style.display = 'block';
		document.getElementById('tab-img-1').src = SITE_ADDRESS+'assets/images/v4/home-circle-1-active.png';
		document.getElementById('tab-1').className='tab-active'

		document.getElementById('home-tab-2').style.display = 'none';
		document.getElementById('tab-img-2').src = SITE_ADDRESS+'assets/images/v4/home-circle-2.png';
		document.getElementById('tab-2').className='tab'
		
		document.getElementById('home-tab-3').style.display = 'none';
		document.getElementById('tab-img-3').src = SITE_ADDRESS+'assets/images/v4/special-offers.gif';
		document.getElementById('tab-3').className='special-offers'
	}
	
	if (id == 2) {
		document.getElementById('home-tab-1').style.display = 'none';
		document.getElementById('tab-img-1').src = SITE_ADDRESS+'assets/images/v4/home-circle-1.png';
		document.getElementById('tab-1').className='tab'


		document.getElementById('home-tab-2').style.display = 'block';
		document.getElementById('tab-img-2').src = SITE_ADDRESS+'assets/images/v4/home-circle-2-active.png';
		document.getElementById('tab-2').className='tab-active'
		
		document.getElementById('home-tab-3').style.display = 'none';
		document.getElementById('tab-img-3').src = SITE_ADDRESS+'assets/images/v4/special-offers.gif';
		document.getElementById('tab-3').className='special-offers'
	}
	
	if (id == 3) {
		document.getElementById('home-tab-3').style.display = 'block';
		document.getElementById('tab-img-3').src = SITE_ADDRESS+'assets/images/v4/special-offers-active.gif';
		document.getElementById('tab-3').className='special-offers'


		document.getElementById('home-tab-1').style.display = 'none';
		document.getElementById('tab-img-1').src = SITE_ADDRESS+'assets/images/v4/home-circle-1.png';
		document.getElementById('tab-1').className='tab'
		
		document.getElementById('home-tab-2').style.display = 'none';
		document.getElementById('tab-img-2').src = SITE_ADDRESS+'assets/images/v4/home-circle-2.png';
		document.getElementById('tab-2').className='tab'
	}
}

function explode(item,delimiter) {
	tempArray=new Array(1);
	var Count=0;
	var tempString=new String(item);

	while (tempString.indexOf(delimiter)>0) {
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
		Count=Count+1
	}
	tempArray[Count]=tempString;
	return tempArray;
}

