//function to show the sub navigation
function showLayer(id)
{
	var parentId = "p" + id;
	document.getElementById(parentId).className = "highlightedMenu";
	document.getElementById(id).style.display = "block";
}

//function to hide the sub navigation
function hideLayer(id)
{
	var parentId = "p" + id;
	document.getElementById(parentId).className = "Menu";
	document.getElementById(id).style.display = "none";
}

//function to pop-up the image window
function PopUp(imageName,imagePath,noOfImages)
{
	var height = "600";
	var width = "650";
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    str += ",scrollbars=yes,status=yes";
	}
	var url = "PopUp.htm?imagePath=" + imagePath + "&imageName=" + imageName + "&noOfImages=" + noOfImages;
	var name = "FurnitureDetails";
	
	window.open(url, name, str);
    //window.open("PopUp.asp?imagePath=" + imagePath + "&imageName=" + imageName + "&noOfImages=" + noOfImages,"FurnitureDetails","height=500,width=650,status=yes,scrollbar=yes");
}

//function to read the querystring
function qs()
{
	var qsParm = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++)
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0)
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
	/*alert(qsParm['imagePath']);
	alert(qsParm['imageName']);
	alert(qsParm['noOfImages']);*/
}

//function to change the image
function changeImage(imageName, imageURL)
{
	document[imageName].src = imageURL;
}

function launchWindowCenter(url, name, height, width) {
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    str += ",scrollbars=yes,status=yes,menubar=1,resizable=yes";
  }
  window.open(url, name, str);
}

//function to trim the value provided
function trim(str)
{
    return str.replace(/(^\s+)([^\s]*)(\s+$)/, '$2');
}

function validate()
{
	var missingInfo = "";
	if(trim(document.frmOrder.Customer_Name.value) == "")
	{
		missingInfo += "\n First Name";
	}
	if(trim(document.frmOrder.Customer_Email.value) == "")
	{
		missingInfo += "\n Email";
	}
	if(trim(document.frmOrder.Customer_Phone.value) == "")
	{
		missingInfo += "\n Phone";
	}
	if(trim(document.frmOrder.First_Product_Name.value) == "")
	{
		missingInfo += "\n Product Name";
	}
	if(trim(document.frmOrder.First_Product_Number.value) == "")
	{
		missingInfo += "\n Product Number";
	}
	if(trim(document.frmOrder.First_Product_Quantity.value) == "")
	{
		missingInfo += "\n Product Quantity";
	}
	
	if(missingInfo != "")
	{
		missingInfo="Please ensure the following fields are entered correctly :"+
					"\n__________________________________________"+
					"\n"+missingInfo+	
					"\n__________________________________________";
		alert(missingInfo);
		return false;	
	}
}

function validateTellFriend()
{
	var missingInfo = "";
	if(trim(document.frmFriend.Customer_Name.value) == "")
	{
		missingInfo += "\n Your Name";
	}
	if(trim(document.frmFriend.Customer_Email.value) == "")
	{
		missingInfo += "\n Your Email";
	}
	if(trim(document.frmFriend.sendName.value) == "")
	{
		missingInfo += "\n Receiver's Name";
	}
	if(trim(document.frmFriend.sendEmail.value) == "")
	{
		missingInfo += "\n Receiver's Email";
	}
	
	if(missingInfo != "")
	{
		missingInfo="Please ensure the following fields are entered correctly :"+
					"\n__________________________________________"+
					"\n"+missingInfo+	
					"\n__________________________________________";
		alert(missingInfo);
		return false;	
	}
}