// Toggle visibility of date div

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("mainMenu");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;

function copyDetails()
{
var billing=new Array("orderBillingOrganisation","orderBillingStreet","orderBillingSuburb","orderBillingState","orderBillingPostcode","orderBillingCountry");
var shipping=new Array("orderShippingOrganisation","orderShippingStreet","orderShippingSuburb","orderShippingState","orderShippingPostcode","orderShippingCountry");
var i;
for(i=0;i<billing.length;i++)
	{
	document.getElementById(shipping[i]).value=document.getElementById(billing[i]).value;
	}
}

function checkAgreement(id1,id2)
{
var el=new Array(id1,id2);
var i;
var count=0;
for(i=0;i<el.length;i++)
	{
	check=document.getElementById(el[i]);
	if(check.checked)
		{
		count++;
		}
	}
if(count==2)
	{
	return true;
	}
else
	{
	alert("Please confirm your details and accept the terms and conditions to continue.");
	return false;
	}
}

var submitcount = 0;

function checkFields()
{

if (submitcount == 0) {
	//sumbit form
	submitcount ++;	
	return true;	
	}
else
	{	
		alert("Transaction is in progress.");
		return false;
	}
}

function togglePayment(id,el,val)
{
var el=document.getElementById(el).value;
var me=document.getElementById(id);
if (el==val)
	{
	me.style.display="block";
	}
else 
	{
	me.style.display="none";
	}
}

function toggleSurcharge(destEl,el,amountValue,surValue)
{
var el=document.getElementById(el).value;
var destEl=document.getElementById(destEl);
if(el=="American Express"||el=="Diners Club")
	{
	destEl.value=surValue;
	}
else
	{
	destEl.value=amountValue;
	}
}

function validate()
{
if(document.getElementById('orderFirstName').value=='')
	{
	alert("Please fill in your name");
	document.getElementById('orderFirstName').focus();
	return false;
	}
//if(document.getElementById('orderLastName').value=='')
	//{
	//alert("Please fill in your name");
	//document.getElementById('orderLastName').focus();
	//return false;
	//}
if(document.getElementById('orderEmail').value=='')
	{
	alert("Please fill in your email address");
	document.getElementById('orderEmail').focus();
	return false;
	}
if(document.getElementById('orderPhone').value=='')
	{
	alert("Please fill in your phone no.");
	document.getElementById('orderPhone').focus();
	return false;
	}
	if(document.getElementById('orderBillingOrganisation').value=='')
	{
	alert("Please fill in Name");
	document.getElementById('orderBillingOrganisation').focus();
	return false;
	}
	
if(document.getElementById('orderBillingStreet').value=='')
	{
	alert("Please fill in your street");
	document.getElementById('orderBillingStreet').focus();
	return false;
	}
		
if(document.getElementById('orderBillingSuburb').value=='')
	{
	alert("Please fill in your suburb");
	document.getElementById('orderBillingSuburb').focus();
	return false;
	}
/*if(document.getElementById('orderBillingCity').value=='')
	{
	alert("Please fill in your city");
	document.getElementById('orderBillingCity').focus();
	return false;
	}
*/
if(document.getElementById('orderBillingState').value=='')
	{
	alert("Please fill in your state");
	document.getElementById('orderBillingState').focus();
	return false;
	}
if(document.getElementById('orderBillingPostcode').value=='')
	{
	alert("Please fill in your postcode");
	document.getElementById('orderBillingPostcode').focus();
	return false;
	}
if(document.getElementById('orderBillingCountry').value=='')
	{
	alert("Please fill in your country");
	document.getElementById('orderBillingCountry').focus();
	return false;
	}
return true;
}

function validateSize(id1,value1,message)
{
if(document.getElementById(id1).value==value1)
	{
	alert(message);
	return false;
	}
else
	{
	return true;
	}
}

function validateSizes(id1,value1,id2,value2)
{
element1=document.getElementById(id1).value;
element2=document.getElementById(id2).value;
if((element1==value1)||(element2==value2))
	{
	alert("Please select a size for each item.");
	return false;
	}
else
	{
	return true;
	}
}

function changeOptions(elementID,optionValues)
{
var values=optionValues.split(",");
document.getElementById(elementID).options.length = 0; //Clear the 2nd menu
var i;
document.getElementById(elementID).options[0] = new Option("- Select Size -","select");
for(i=0;i<values.length;i++) 
	{ //Repopulate 2nd menu
	document.getElementById(elementID).options[i+1] = new Option(values[i],values[i]);
	}
}

function copySize()
{
var topSize=document.getElementById('productSizeTop').value;
var bottomSize=document.getElementById('productSizeBottom').value;
document.getElementById('productSizeTop2').value=topSize
document.getElementById('productSizeBottom2').value=bottomSize
}

function totalProducts()
{
var priceTop=Number(document.getElementById('productPriceTop').innerHTML);
var priceBottom=Number(document.getElementById('productPriceBottom').innerHTML);
var total=(priceTop+priceBottom).toFixed(2);
changeInnerHtml(total,'total');
}

function switchElements(productID,productIDElement,productID2,productIDElement2,name,nameID,info,infoID,collageImage,price,priceID,size,sizeID,styleImage,styleImageID,productImage,productImageID)
{
//set the size meny
changeOptions(sizeID,size)
//set the productID
changeValue(productID,productIDElement);
//set the productID
changeValue(productID2,productIDElement2);
//set the name
changeInnerHtml(name,nameID);
//set the info
//changeInnerHtml(info,infoID);
//set the collage image
updateMoreInfo(info,collageImage,infoID);
//set the price
changeInnerHtml(price,priceID);
//set image for style type image
//changeImage(styleImage,styleImageID);
//set image for product image
changeImage(productImage,productImageID);
}
function updateMoreInfo(content,image,elementID)
{
document.getElementById(elementID).href=image;
document.getElementById(elementID).title=content;
}
// change value for element
function changeValue(value,elementID)
{
document.getElementById(elementID).value=value;
}
// change image for img element
function changeImage(imgSrc,imageID)
{
document.getElementById(imageID).src=imgSrc;
}
// change innerhtml for element
function changeInnerHtml(content,elementID)
{
document.getElementById(elementID).innerHTML=content;
}

function expand(element)
{
el=document.getElementById(element);
if(el.className=='hide')
	{
	el.className='show';
	}
else
	el.className='hide';
}

function toggleVisibility(id)
{
var me=document.getElementById(id);
if (me.style.display=="none")
	{
	me.style.display="block";
	}
else 
	{
	me.style.display="none";
	}
}

function toggleDisplay(id)
{
var check= new Array("funky","funkita","kiargo");
for(i=0;i<check.length;i++)
	{
	if(check[i]!=id)
		{
		toggleOff(check[i]);
		}
	}
	toggleOn(id,'block');
}

function toggleOn(id,type)
{
var me=document.getElementById(id);
me.style.display=""+type+"";
//me.style.visibility="visible";
}

function toggleOff(id)
{
var me=document.getElementById(id);
me.style.display="none"
//me.style.visibility="hidden"
}

function validatePass()
{
var pass=document.getElementById('userPass').value;
var pass2=document.getElementById('userPassConfirm').value;
if(pass==pass2)
	{
	return true;
	}
else
	{
	alert("Passwords do not match, please try again.");
	return false;
	}
}

