// JavaScript Document


function RefreshImage(valImageId) {

	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function fade_open()
{

var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Netscape"))
{
//	document.getElementById('prod_img').style.visibility='hidden';
}

	document.getElementById('fade').style.display='block';
	document.getElementById('light').style.display='block';
	document.getElementById('light').style.visibility='visible';	
	javascript:scroll(0,0);
	ajax_update_cart();
}


function alert_fade_open()
{

var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Netscape"))
{
//	document.getElementById('prod_img').style.visibility='hidden';
}

	document.getElementById('fade').style.display='block';
	//document.getElementById('light').style.display='block';
	//document.getElementById('light').style.visibility='visible';	
	javascript:scroll(0,0);
}

function fade_close()
{
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Netscape"))
{
	document.getElementById('prod_img').style.visibility='visible';
}
	document.getElementById('fade').style.display='none';
//	alert("executed1");
	document.getElementById('light').style.display='none';
//	alert("executed2");
	ajax_update_cart();
}






// constants to define the title of the alert and button text.
var ALERT_TITLE = "Oops, there seems to be a problem !";
var ALERT_BUTTON_TEXT = "Ok";

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
	window.alert = function(txt) {
		createCustomAlert(txt);
	}
}

function createCustomAlert(txt) {
	// shortcut reference to the document object
	alert_fade_open();
	d = document;

	// if the modalContainer object already exists in the DOM, bail out.
	if(d.getElementById("modalContainer")) return;

	// create the modalContainer div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = document.documentElement.scrollHeight + "px";

	// create the DIV that will be the alert 
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	// center the alert box
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";

	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	// create a paragraph element to contain the txt argument
	msg = alertObj.appendChild(d.createElement("p"));
	msg.innerHTML = txt;
	
	// create an anchor element to use as the confirmation button.
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() { removeCustomAlert();return false; }

	
}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
	fade_close();
}


/* Modified to support Opera */
function bookmarksite(){
if (window.sidebar) // firefox
	window.sidebar.addPanel(document.title, document.location, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',document.location);
	elem.setAttribute('title',document.title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(document.location,document.title);
}

 
function stock_error(myid)
{
alert('The Selected Item is Out of Stock, Please try again !');
document.getElementById(myid).selectedIndex=0;
}

function stock_error_checkbox(myid)
{
alert('The Selected Item is Out of Stock, Please try again !');
document.getElementById(myid).checked=false;

}


function myPopup(url,windowname,w,h,x,y){
window.open(url,windowname,"resizable=no,toolbar=no,scrollbars=yes,menubar=no,location=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");

}


function show_eta()
{
	$("#fade").show();
	$("#mynotification").css("visibility","visible");
	return false;
}

function hide_eta()
{
	$("#mynotification").css("visibility","hidden");
	$("#fade").hide();
	return false;
}

	

function hide_stock_notification()
{
	$("#stock_notification").hide();
	$("#prod_nextday").fadeIn('slow');
	$("#bottom_price").fadeIn('slow');
	$("#add_basket").fadeIn('slow');
}




function mysubmit()
{
	var rtn_val;
	$("#eta_request").hide();
	$("#eta_loading").show();
	$.post("/eta_notification.asp", $("#frm_eta").serialize(), function(data){process_data(data)});
}

function process_data(rtn_val)
{
	$("#eta_loading").hide();

	if(rtn_val=="noname")
	{
		$("#eta_loading").hide();
		RefreshImage('imgCaptcha');		
		$("#eta_request").show();
		$("#eta_err").html('Error: Name is required !');
	}
	
	if(rtn_val=="noemail")
	{
		$("#eta_loading").hide();
		RefreshImage('imgCaptcha');		
		$("#eta_request").show();
		$("#eta_err").html('Error: Email Address is required !');
	}	
	
	if(rtn_val=="True")
	{
		$("#eta_request").hide();
		$("#eta_response").fadeIn('Slow');
	}
	if(rtn_val=="False")
	{
		$("#eta_loading").hide();
		RefreshImage('imgCaptcha');		
		$("#eta_request").show();
		$("#eta_err").html('Error: Invalid code, please try again !');
	}	
}


function show_sizeguide()
{
	$("#fade").fadeIn();
	$("#mysizeguide").fadeIn();
	scroll(0,0);
}

function hide_sizeguide()
{
	$("#mysizeguide").fadeOut('slow');
	$("#fade").fadeOut();
}


//MM_preloadImages('/images/alert_close.gif','/images/alert_bg.jpg','/images/instock.jpg','/images/small_instock.jpg');


