// JavaScript Document
var set = new Array();
set['tb_1'] = 1; // flag first button active

function swapWith(swap, bigImageAvail, bigImageName) {
	temp.src = document[swap].src;
	document[swap].src = document[0].src;
	document[0].src = temp.src;
	if(bigImageAvail == 1) { // A Large version of this is available so display the hover to zoom message etc
		document.getElementById("bim").src = bigImageName;
		document.getElementById("hoverToZoom").style.display="block";
		zoom1 = new zoom('sc', 'sim', 'bc', 'bim');
		zoom1.initZoom();	
		document.zoom2set=true;
	} else { // No large version available so hide message
		document.getElementById("hoverToZoom").style.display="none";
	}
}

function tb_mouseout(id, file)
{
	if (set[id] != 1) {
		document.getElementById(id).src = file;
	}
}

function tb_mouseover(id, file)
{
	if (set[id] != 1) {
		document.getElementById(id).src = file;
	}
}

function tb_mouseclick(id, file)
{
	//alert("Mouse click");
	document.getElementById('tb_1').src="images/information.gif";
	document.getElementById('tb_2').src="images/delivery.gif";
	document.getElementById('tb_3').src="images/sizeguide.gif";
	document.getElementById('centre1').style.display="none";
	document.getElementById('centre2').style.display="none";
	document.getElementById('centre3').style.display="none";
	document.getElementById(id).src = file;
	set['tb_1'] = set['tb_2'] = set['tb_3'] = 0;
	set[id] = 1; // make this one active
	
	switch (id){
		case "tb_1":
			document.getElementById('centre1').style.display="block";
			break;
		case "tb_2":
			document.getElementById('centre2').style.display="block";
			break;
		case "tb_3":
			document.getElementById('centre3').style.display="block";
			break;
		default:
		break;
	}
		
			
}

function changeprice(myElement) { // replace the innerHTML of "itemprice" with myElement.value

	details = myElement.value; // get size/price details for selected frame size
	pos = details.indexOf("-");  // locate the position of the £ in the size/price string
	document.getElementById("itemprice").innerHTML = details.substr(pos +2,5); // put price portion of the size/price string into #itemprice
}


function sendPhoto(special) { // show options for sending photo
	//alert ("swap.js Line 64:Special = " + special);
	//document.getElementById("").style.display="none";

	document.getElementById("colourselect").disabled="disabled";  // disable selection box so no further changes to order take place
	document.getElementById("sizeselect").disabled="disabled"; // disable selection box so no further changes to order take place
	document.getElementById("alsobought").style.display="none"; // Hide "similar items" on the right
	document.getElementById("middlehide1").style.display="none"; // Hide the three info sections
	document.getElementById("sendphotobutton").style.display="none"; // hide send photo button
	document.getElementById("middlehide2").style.display="block"; // show send options
	if (special == "S") {
		inner = document.getElementById("specialref").innerHTML; 
		if (inner.length < 5) {// check to see if we already have a serial number on this page/ Just check this one. All are the same.
			//alert("swap.js Line 76: Doing ajax");
			ajaxFunction("S"); // call ajax and get serial number from server and stuff into innerHTML of specialref
		}	
	}
}

function sendmethod(showwhat) {
	inner = document.getElementById("postref").innerHTML; 
	if (inner.length < 5) {// check to see if we already have a serial number on this page/ Just check this one. All are the same.
		ajaxFunction(""); // call ajax and get serial number from server and stuff into innerHTML of postref, emailref & uploadref
	}
	
	document.getElementById("middlehide2").style.display="none"; // hide the send options
	document.getElementById(showwhat).style.display="block"; // make the method visible
}


function addtobasket(methodref)
{
rchref = "http://www.romancart.com/cart.asp?blockdata=%31%37%64%67%79%73%38%68%64%68%6a%65%38%38%48%47%6e%6e%6a%63%64%32%37%68%72%38%32%37%68%64%33%32%64%37%79%33%32%38%47%48%47%4a%39%37%36%37%33%32%37%67%65%66%68%6a%77%39%66%79%77%66%67%77%38%37%77%65%36%37%36%30%37%36%38%37%36%38%39%37%32%31%31%38%39%32%37%36%31%39%32%38%36%37%31%38%37%36%33%39%31%35%39%38%39%38%31%39%33%38%37%34%36%33%32%38%32%38%34%36%32%37%34%32%33%36%39%37%32%36%33%37%38%36%38%39%33&passthru=33089&storeid=33089&quantity=1&"; // start to build up the URL & query string to add item to basket.
price = document.getElementById("itemprice").innerHTML;

rchref = rchref+"price=" + price.substr(1,5); // get price that was previous inserted into itemprice (strip off the leading character which is a £)

switch(methodref) { // no need for any serial numbers in cart for these items.
		case "normal":
			//rchref = rchref + "&tangible=no&itemname=";
			rchref = rchref + "&itemname=";
			break;
			
		default:
			rchref = rchref + "&itemname=[" + document.getElementById(methodref).innerHTML + "] ";	// add serial number what the innerHTML of whch ever method of sending the photo was used.
			break;
}

rchref = rchref + document.getElementById("itemname").innerHTML; // add item title to description
rchref = rchref + " - " + document.getElementById("itemcode").innerHTML; // add item code to description

details = document.getElementById("sizeselect").value;
var mycolour = " " + document.getElementById("itemcolour").innerHTML;

var pos = details.indexOf("-");
rchref = rchref + " " + details.substr(0,pos-1) + mycolour;

		if (methodref == "emailref" && document.getElementById("emailspecial").name == "1") {
			rchref = rchref + " -- (" + document.getElementById("emailspecial").value.replace(/&/g, "%26") + ")";// Add special instructions here replacing & with %26
		} else if (methodref == "postref" && document.getElementById("postspecial").name == "1") {
			rchref = rchref + " -- (" + document.getElementById("postspecial").value.replace(/&/g, "%26") + ")";// Add special instructions here
		}

rchref = rchref.replace(/ /g, "%20"); // replace any spaces with %20
rchref = rchref.replace(/</g, "%20"); // replace any < with %20 to prevent html insertion


window.location.href=rchref; // call up romancart and add this item.


}
function addtobasket2(serial)
{
rchref = "http://www.romancart.com/cart.asp?blockdata=%31%37%64%67%79%73%38%68%64%68%6a%65%38%38%48%47%6e%6e%6a%63%64%32%37%68%72%38%32%37%68%64%33%32%64%37%79%33%32%38%47%48%47%4a%39%37%36%37%33%32%37%67%65%66%68%6a%77%39%66%79%77%66%67%77%38%37%77%65%36%37%36%30%37%36%38%37%36%38%39%37%32%31%31%38%39%32%37%36%31%39%32%38%36%37%31%38%37%36%33%39%31%35%39%38%39%38%31%39%33%38%37%34%36%33%32%38%32%38%34%36%32%37%34%32%33%36%39%37%32%36%33%37%38%36%38%39%33&passthru=33089&storeid=33089&quantity=1&"; // start to build up the URL & query string to add item to basket.
price = document.getElementById("itemprice").innerHTML;

rchref = rchref+"price=" + price.substr(1,5); // get price that was previous inserted into itemprice (strip off the leading character which is a £)
rchref = rchref + "&itemname=[U" + serial + "] ";	// add serial number that is sent from Flash
											// sending the photo was used.
rchref = rchref + document.getElementById("itemname").innerHTML; // add item title to description 
details = document.getElementById("sizeselect").value;
mycolour = " " + document.getElementById("itemcolour").innerHTML;
pos = details.indexOf("-");
rchref = rchref + " " + details.substr(0,pos-1) + mycolour;

if (document.getElementById("uploadspecial").name == "1") {
	rchref = rchref + " -- (" + document.getElementById("uploadspecial").value.replace(/&/g, "%26") + ")";// Add special instructions here replacing & with %26
}

rchref = rchref.replace(/ /g, "%20"); // replace any spaces with %20

window.location.href=rchref; // call up romancart and add this item.

}

function mailto() {
//alert("You clicked on the email link");
serial = document.getElementById("emailref").innerHTML;
//alert("Serial = " + serial);
href="mailto:photo@wallfillers.com?subject=Photograph for order REF:" + serial + "&body=My Order Reference: " + serial + "%0d%0aMy Telephone Number:";
//alert("mailto = " + href); 
window.location.href=href;
}

function editspecial(myelement) { // arrive here when the text area has been clicked
// the purpose of this function is to remove the default text from the text area as soon as the viewer clicks in the box to type.
if (document.getElementById(myelement).name == "0") { // Check name attribute. If it's "0" then the text area contents are not changed
	document.getElementById(myelement).value=""; // clear out the default text area contents
	document.getElementById(myelement).style.color="black"; // make the text colour full black to reassure viewer their text is accepted
	document.getElementById(myelement).name = "1"; // set attribute to "1" so that next time the textarea is clicked, we don't clear it again
}

}

function returnto(where) { // let viewer go back to choose method of sending again or go to original page view

if (where == "main" ) { // hide middlehide2 so that page appears as original. nothing else should be visible at this point
	document.getElementById("middlehide2").style.display="none"; // hide send method options
	document.getElementById("middlehide1").style.display="block"; // display main middle block
	document.getElementById("sendphotobutton").style.display="block";
	if (disabled == "disabled") { // disabled is set to disabled by PHP if this dropdown box is disabled
		document.getElementById("colourselect").disabled="disabled";  // Put dropdown back to revious state of disabled.
	} else {
		document.getElementById("colourselect").disabled="";  // Put dropdown back to previous state of NOT disabled
	}
	document.getElementById("sizeselect").disabled=""; // disable selection box so no further changes to order take place
	document.getElementById("alsobought").style.display="block"; // Show "similar items" on the right
	

} else if (where == "methods") { // hide all specific send methods and make send method choice visible again.
	document.getElementById("middlepost").style.display = "none";
	document.getElementById("middleemail").style.display = "none";
	document.getElementById("middleupload").style.display = "none";
	document.getElementById("middlehide2").style.display = "block";
}
}

function colourChange(myelement) { // show new item when user has selected another colour variation
	document.getElementById("centreblock").style.display="none";
	window.location.href=myelement.value;
}

function sizeChange(myelement) { // show new item when user has selected another colour variation
	document.getElementById("centreblock").style.display="none";
	window.location.href=myelement.value;
}

function showbig (itemid, displaystate) {
	document.getElementById(itemid).style.display = displaystate;	
}
function sendmessage() { // for sending an email to us via the contact us pages
errors = ""; // clear out any error messages
// validate name -------------------------
s_name = document.getElementById('contact_name').value;

if (document.getElementById('contact_name').name=="0") {
	errors = "You did not enter your name\n";
} else if(s_name.length < 3) {
	errors = "Your name is too short\n";
}

// validate email ---------------------------

var emailFilter=/^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
if (document.getElementById('contact_email').value.search(emailFilter) == -1) { 
       errors += "Please enter a valid email address.\n";
}

//Validate phone number
if (document.getElementById('contact_phone').name != "0" && document.getElementById('contact_phone').value.length > 0) { 
	var phoneFilter=/^[0-9\s]{10,15}$/;
	if (document.getElementById('contact_phone').value.search(phoneFilter) == -1) {
		errors += "Enter a valid phone number or leave blank\n"
	}

}

// validate message
if (document.getElementById('contact_message').name == "0" || document.getElementById('contact_message').value.length < 5) {
	errors += "Please enter a message\n";
}
if (errors =="") { // there are no errors in the inoput data
s_name = document.getElementById('contact_name').value.replace(/\s/g, "%20");
s_name = s_name.replace(/&/g, "%26");
s_name = s_name.replace(/\?/g, "%3f");

s_phone = document.getElementById('contact_phone').value.replace(/\s/g, "%20");

s_message = document.getElementById('contact_message').value.replace(/\s/g, "%20");
s_message = s_message.replace(/&/g, "%26");
s_message = s_message.replace(/\?/g, "%3f");

	href="messagesent.php?name=" + s_name + "&email=" + document.getElementById('contact_email').value + "&phone=" + s_phone + "&message=" +	s_message;
		window.location.href=href; // Now send message by calling the messagesent.php script
} else {
	alert("ERROR: The following items need correcting before we can send a message\n\n" + errors);
}
}

