function isArray(obj) {
	return obj.constructor == Array;
}

function allow1Upper(checkValue,elem) {
	var foundUpper = false;
	var c;
	var resultValue = '';
	for (var i = 0; i < checkValue.length; i++) {
		c = checkValue.charAt(i);
		if ((c >= 'A') && (c <= 'Z')) {
			if (foundUpper){
				c = c.toLowerCase();
			} else {
				foundUpper = true;
			}
		}
		resultValue = resultValue + c;
	}
	elem.value = resultValue;
}

function changeCustom1stText(newValue) {
	if (newValue == '') {
		document.getElementById('submitBtn').disabled = 'none';
	} else {
		document.getElementById('submitBtn').style.display = 'block';
		allow1Upper(newValue,document.getElementById('line1text'));
	}
}

function toggle(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block')
		e.style.display = 'none';
	else
		e.style.display = 'block';
}

function blink_reverse()
{
	if (document.getElementById) {
		document.getElementById("shirt_price").style.color = "#ffeeff";
		document.getElementById("shirt_price").style.background = "#444444";
	}
}

function blink_normal()
{
	if (document.getElementById) {
		document.getElementById("shirt_price").style.color = "#444444";
		document.getElementById("shirt_price").style.background = "#ffeeff";
	}
}

function changeCustom2ndText(newValue) {
	var setBlink = false;
	if (newValue == '') {
		if (document.getElementById('shirt_amount').value == '20.00') setBlink = true;
		document.getElementById('shirt_amount').value = '15.00';
		document.getElementById('shirt_price').innerHTML = 'Price: £15.00';
	} else {
		if (document.getElementById('shirt_amount').value == '15.00') setBlink = true;
		document.getElementById('shirt_amount').value = '20.00';
		document.getElementById('shirt_price').innerHTML = 'Price: £20.00';
		allow1Upper(newValue,document.getElementById('line2text'));
	}
	if (setBlink) {
		for(var i=900; i < 4500; i=i+900)
		{
			setTimeout("blink_reverse()",i);
			setTimeout("blink_normal()",i+450);
		}
	}
}

function initPersonalisedTShirt() {
	document.getElementById('ordering').style.display = 'none';;
	document.getElementById('washing').style.display = 'none';;
	document.getElementById('garment').style.display = 'none';;
}

function initCustomText() {
	changeCustomText("Katie's<br>Hen Do");
	changeCustomPageSize('A4',true);
	changeCustomJustify('center');
	changeCustomPosition('middle','center',true);
	changeCustomFontFace('arial');
	changeCustomFontWeight(false);
	changeCustomFontStyle(false);
	changeCustomFontColour('#000000');
	changeCustomBgColour('#ffd6e8');
}

function changeCustomText(newValue) {
	var outputText = newValue.replace(new RegExp("\\n", "g" ),"<br>");
	var outputText = outputText.replace(new RegExp("!pic!", "g" ),"(Picture Here!)");
	document.getElementById('custom_text_result').innerHTML = outputText;
}

function changeCustomPageSize(newValue,checked) {
	if (checked) {
		if (newValue == 'A4') {
			document.getElementById('text_position').style.display = 'none';
			changeCustomPosition('middle','center',true);
			document.getElementById('custom_font').size = 5;
		} else {
			document.getElementById('text_position').style.display = '';
			if (newValue == 'A5') {
				document.getElementById('custom_font').size = 4;
			} else {
				document.getElementById('custom_font').size = 3;
			}
		}
	}
}

function customGetSelectedColours(selector) {
	selector.style.color = selector.options[selector.selectedIndex].style.color;
	selector.style.background = selector.options[selector.selectedIndex].style.background;
}

function changeCustomJustify(newValue) {
	document.getElementById('custom_text_cell').style.textAlign = newValue;
}

function changeCustomPosition(VPos,HPos,checked) {
	if (checked) {
		document.getElementById('custom_text_cell').style.verticalAlign = VPos;
		if (HPos == 'left') {
			document.getElementById('left_padding').style.display = 'none';
			document.getElementById('right_padding').style.display = '';
		} else if (HPos == 'center') {
			document.getElementById('left_padding').style.display = 'none';
			document.getElementById('right_padding').style.display = 'none';
		} else {
			document.getElementById('left_padding').style.display = '';
			document.getElementById('right_padding').style.display = 'none';
		}
	}
}

function changeCustomFontFace(newValue) {
	document.getElementById('custom_font').face = newValue;
}

function changeCustomFontWeight(newValue) {
	var boldStr = '';
	if (newValue) {
		boldStr = 'bold';
	}
	document.getElementById('custom_font').style.fontWeight = boldStr;
}

function changeCustomFontStyle(newValue) {
	var italicStr = '';
	if (newValue) {
		italicStr = 'italic';
	}
	document.getElementById('custom_font').style.fontStyle = italicStr;
}

function changeCustomFontColour(newValue) {
	document.getElementById('custom_font').color = newValue;
	document.getElementById('custom_text_result').style.color = newValue;
}

function changeCustomBgColour(newValue) {
	document.getElementById('inner_table').style.backgroundColor = newValue;
	document.getElementById('custom_text_cell').style.backgroundColor = newValue;
	document.getElementById('custom_text_result').style.backgroundColor = newValue;
}

function create_price_table_line_dets(desc,no_desc_column,col_align,line){
	if (line.length < 4){
		document.write("<p>buy_now_table Error - line array is too smaller, descr =" + line[1] + ". Please advise the Webmaster.</p>");
		return;
	}else if (line.length > 5){
		document.write("<p>buy_now_table Error - line array is too large, descr =" + line[1] + ". Please advise the Webmaster.</p>");
		return;
	}
	document.write("<tr>");
	document.write("<td style=\"text-align: " + col_align[0] + ";\">");
	if (line[0] == ""){
		document.write(line[1] + "</td>");
	}else{
		document.write("<a href=\"" + line[0] + "\">" + line[1] + "</a></td>");
	}
	if (no_desc_column != 1) {
		document.write("<td style=\"text-align: " + col_align[1] + ";\">" + line[2] + "</td>");
	}
	document.write("<td style=\"text-align: " + col_align[2] + ";\">&pound;" + line[3] + "</td>");
	document.write("<td style=\"text-align: " + col_align[3] + ";\">");
	if (line.length == 4){
		document.write("<a href=\"#footer\">Please Phone</a>");
	} else {
		document.write("<form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">");
		document.write("<input type=\"hidden\" name=\"cmd\" value=\"_cart\">");
		document.write("<input type=\"hidden\" name=\"business\" value=\"vince@trulymadlydeeply.biz\">");
		document.write("<input type=\"hidden\" name=\"item_name\" value=\"" + desc + " " + line[1] + " " + line[2] + "\">");
		document.write("<input type=\"hidden\" name=\"amount\" value=\"" + line[3] + "\">");
		document.write("<input type=\"hidden\" name=\"item_number\">");
		document.write("<input type=\"hidden\" name=\"page_style\" value=\"primary\">");
		document.write("<input type=\"hidden\" name=\"image_url\" value=\"/images/logo_paypal.jpg\">");
		document.write("<input type=\"hidden\" name=\"return\" value=\"/successful.html\">");
		document.write("<input type=\"hidden\" name=\"cancel_return\" value=\"/fail.html\">");
		document.write("<input type=\"hidden\" name=\"currency_code\" value=\"GBP\">");
		document.write("<input type=\"hidden\" name=\"lc\" value=\"GB\">");
		document.write("<input type=\"hidden\" name=\"cn\" value=\"IMPORTANT - Please let us know the date of your special occasion and daytime phone number.\">");
		document.write("<input type=\"hidden\" name=\"add\" value=\"1\">");
		if (isArray(line[4])){
			var selector = line[4];
			if (selector != "") {
				document.write("<input type=\"hidden\" name=\"on0\" value=\"" + selector[0] + "\">");
				document.write("<select name=\"os0\">");
				for(var s = 1; s < selector.length; s++){
					document.write("<option value=\"" + selector[s] + "\">" + selector[s] + "</option>");
				}
				document.write("</select>");
			}
		}else if (line[4] != ""){
			document.write(line[4]);
		}
		document.write("&nbsp;&nbsp;<input type=\"image\" src=\"../images/tmd_images/buttons/060/buy_now.gif\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\" width=\"60px\">");
		document.write("</form>");
	}
	document.write("</td>");
	document.write("</tr>");
}

function create_aligned_price_table(desc,header,table_align,col_align,lines){
	if (((header.length != 0) && (header.length != 4)) || (col_align.length != 4)){
		document.write("<p>buy_now_table Error - either the header array(" + header.length + ") or col_align array(" + col_align.length + ") are the wrong length. Please advise the Webmaster.</p>");
		return;
	}
	if (table_align == "") {
		document.write("<div class=\"indented\">");
		document.write("<table id=\"buy_now_table\" border=\"1\">");
	} else {
		document.write("<div>");
		document.write("<table id=\"buy_now_table\" align=" + table_align + " border=\"1\">");
	}
	if (header.length > 0) {
		var no_desc_column = 0;
		if (header[0] == "") no_desc_column = 1;

		document.write("<tr>");
		for(var h = no_desc_column; h < header.length; h++){
			document.write("<th>" + header[h] + "</th>");
		}
		document.write("</tr>");
	}
	for(var l = 0; l < lines.length; l++){
		create_price_table_line_dets(desc,no_desc_column,col_align,lines[l]);
	}
	document.write("</table>");
	document.write("</div>");
}

function create_price_table(desc,header,table_align,col_align,lines){
	return create_aligned_price_table(desc,header,table_align,col_align,lines);
}

function popup_image_and_table(main_desc,desc,size_price,img,selection){
	if (selection === undefined){
		selection = "";
	}
	document.write("<p id=\"spacing_para\">&nbsp;</p>");
	var header = new Array();
	var col_align = new Array("left","left","right","centre");

	var lines = new Array();
	if (isArray(size_price)){
		for(var i = 0; i < size_price.length; i++){
			lines.push(new Array("",desc,size_price[i][0],size_price[i][1],selection));
		}
	}else{
		lines.push(new Array("",desc,"Each",size_price,selection));
	}
	create_aligned_price_table(main_desc,header,"center",col_align,lines);
	document.write("<p id=\"spacing_para\">&nbsp;</p>");
	document.write("<img alt=\"" + desc + "\" src=\"" + img + "\">");
}

var descToShow="";
function pic_init() {
	var picToShow = document.location.href;
	if (picToShow.indexOf("?") != -1) {
		picToShow  = picToShow.substr((picToShow.indexOf("?")+1),picToShow.length);
		if (picToShow.indexOf(":") != -1) {
			descToShow = picToShow.substr((picToShow.indexOf(":")+1),picToShow.length);
			picToShow = picToShow.substr(0,picToShow.indexOf(":"));
		} else {
			descToShow = "";
		}
		document.getElementById("pic").src = picToShow;
	} else {
		alert('No Picture to display');
	}
}

function pic_description() {
	pic_init();
	if (descToShow != "") {
		document.write("<tr>");
		document.write("<td id=\"pop_descriptions_edit\" align=\"center\">");
		document.write("<h3 id=\"centred_header\">");
		document.write(descToShow);
		document.write("</h3>");
		document.write("</td>");
		document.write("</tr>");
	}
}

var menuids=["header_menu"]; //Enter menu names in the array, separated by commas.
var subbottom=0;
var subindent=-2;
var subzIndex=0;

function init_vertical_menu(){
	for (var i=0; i<menuids.length; i++){
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
		for (var t=0; t<ultags.length; t++){
			ultags[t].parentNode.getElementsByTagName("a")[0].className+=" subfolderstyle";
			if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
				subzIndex=1;
				var subheight=ultags[t].parentNode.offsetHeight+subbottom;
				ultags[t].style.top=subheight+"px"; //position menu to the right of menu item that activated it
			}else{ //This is a sub level submenu (ul)
				var subwidth=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+subindent;
				ultags[t].style.left=subwidth+"px"; //position menu to the right of menu item that activated it
			}
			ultags[t].style.zIndex=subzIndex++;
			ultags[t].parentNode.onmouseover=function(){
				this.getElementsByTagName("ul")[0].style.display="block";
			}
			ultags[t].parentNode.onmouseout=function(){
				this.getElementsByTagName("ul")[0].style.display="none";
			}
		}
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars)
			ultags[t].style.visibility="visible";
			ultags[t].style.display="none";
		}
	}
}

function onloadGoogleFriends() {
	var skin = {};
	skin['BORDER_COLOR'] = '#FFEEFF';
	skin['ENDCAP_BG_COLOR'] = '#FFF4FF';
	skin['ENDCAP_TEXT_COLOR'] = '#666666';
	skin['ENDCAP_LINK_COLOR'] = '#CC3366';
	skin['ALTERNATE_BG_COLOR'] = '#FFF4FF';
	skin['CONTENT_BG_COLOR'] = '#FFF4FF';
	skin['CONTENT_LINK_COLOR'] = '#CC3366';
	skin['CONTENT_TEXT_COLOR'] = '#666666';
	skin['CONTENT_SECONDARY_LINK_COLOR'] = '#CC3366';
	skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#444444';
	skin['CONTENT_HEADLINE_COLOR'] = '#444444';
	skin['NUMBER_ROWS'] = '3';
	google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
	/*
	google.friendconnect.container.renderMembersGadget(
	{ id: 'div-3833051401690266287',
		site: '09579090562925674294' },
	skin);
	*/

	google.friendconnect.container.renderSignInGadget(
	{ id: 'div-2266706177036173419',
		site: '09579090562925674294' },
	skin);
}

if (window.addEventListener){
	window.addEventListener("load", init_vertical_menu, false);
}else if (window.attachEvent){
	window.attachEvent("onload", init_vertical_menu);
}
