// ========================= Go Away Old Browsers ===============
if (!document.getElementById) {
	window.location="http://www.webstandards.org/upgrade";
}
// ========================= Go Away Old Browsers ===============


// ========================= Invalidable CSS ===============
// invalidable.js  <-- note the extension
//
// Dynamically Inserts CSS Link Tag
var headTag = document.getElementsByTagName("head")[0];
var linkTag = document.createElement('link');
linkTag.type = 'text/css';
linkTag.rel = 'stylesheet';
linkTag.href = 'includes/styles/invalidable.css';
linkTag.media = 'screen';
headTag.appendChild(linkTag);
// ========================= Invalidable CSS ===============


//========================= Quick Reference =====================
function SelectQuickReference() {
	str_quick_ref=document.forms["frmQuickReference"].lstQuickRef.options[document.forms["frmQuickReference"].lstQuickRef.selectedIndex].value;
	if (str_quick_ref=="n") {
		return false;
	}
	else {
		window.location=str_quick_ref;
		return true;
	}
}
//========================= Quick Reference =====================


//========================= Validate Search Box =================
function SearchProductValidation() {
	itc=document.forms["frmSearchForm"].txtSearchString.value.toLowerCase();
	if (itc==""||itc.length<3) {
		window.alert("What Do You Want To Search ? Please Type At Least 3 Characters...");
		document.forms["frmSearchForm"].txtSearchString.focus();
		return false;
	}
	else {
		return true; 
	} 
}
//========================= Validate Search Box =================


//========================= Preloading Images ===================
function MM_preloadImages() {
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//========================= Preloading Images ===================


//========================= Date ================================
function fnShowCurrentDate() {
	var ye,mon,dat;
	ye=new Date();
	mon=ye.getMonth();
	dat=ye.getDate();
	document.write('<span class="Fnt10Pix">');
	document.write(dat);
	document.write(" : ");
	document.write((mon==0)?"January":"");
	document.write((mon==1)?"February":"");
	document.write((mon==2)?"March":"");
	document.write((mon==3)?"April":"");
	document.write((mon==4)?"May":"");
	document.write((mon==5)?"June":"");
	document.write((mon==6)?"July":"");
	document.write((mon==7)?"August":"");
	document.write((mon==8)?"September":"");
	document.write((mon==9)?"October":"");
	document.write((mon==10)?"November":"");
	document.write((mon==11)?"December":"");
	document.write(" : ");
	document.write(ye.getFullYear());
	document.write("... ");
	document.write("</span>");
}
//========================= Date ================================


//========================= Window ================================
function MiniWindowOpen(WhatWin,WID,HEI) {
	open(WhatWin,'miniwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=' + WID + ',height=' + HEI);
}
//========================= Window ================================


//========================= Tell Friend ================================
function TellFriend(paraLevel) {
	var LinkLevel;
	switch (paraLevel) {
		case "0" :
			LinkLevel = "";
			break;
		case "1" :
			LinkLevel = "../";
			break;
		case "2" :
			LinkLevel = "../../";
			break;
		case "3" :
			LinkLevel = "../../../";
			break;
		default :
			LinkLevel = "";
	}
	MiniWindowOpen(LinkLevel + 'includes/asps/tell_friend.asp?txtURL=' + window.location,'410','390');
}
//========================= Tell Friend ================================


//========================= Feedback ================================
function Feedback(paraLevel) {
	var LinkLevel;
	switch (paraLevel) {
		case "0" :
			LinkLevel = "";
			break;
		case "1" :
			LinkLevel = "../";
			break;
		case "2" :
			LinkLevel = "../../";
			break;
		case "3" :
			LinkLevel = "../../../";
			break;
		default :
			LinkLevel = "";
	}
	MiniWindowOpen(LinkLevel + 'includes/asps/website_feedback.asp','410','390');
}
//========================= Feedback ================================


//========================= Stock In ================================
function StockOutNotification(paraLevel,productLine,productCode) {
	var LinkLevel;
	switch (paraLevel) {
		case "0" :
			LinkLevel = "";
			break;
		case "1" :
			LinkLevel = "../";
			break;
		case "2" :
			LinkLevel = "../../";
			break;
		case "3" :
			LinkLevel = "../../../";
			break;
		default :
			LinkLevel = "";
	}
	MiniWindowOpen(LinkLevel + 'includes/asps/stock_out_notification.asp?hidProdLine=' + productLine + '&hidProdCode=' + productCode + '&strStockOutNotification=Yes','450','460');
}
//========================= Stock In ================================


//========================= Mega Seasonal Catalogue ================================
function MegaSeasonalCatalogue(paraLevel) {
	var LinkLevel;
	switch (paraLevel) {
		case "0" :
			LinkLevel = "";
			break;
		case "1" :
			LinkLevel = "../";
			break;
		case "2" :
			LinkLevel = "../../";
			break;
		case "3" :
			LinkLevel = "../../../";
			break;
		default :
			LinkLevel = "";
	}
	//MiniWindowOpen(LinkLevel + 'includes/asps/mega_seasonal_catalogue.asp','550','300');
	MiniWindowOpen('http://www.singermega.com/register/register.php','550','300');
}
//========================= Mega Seasonal Catalogue ================================


//======================================================================
// ========== These functions will show & hide form contents when submitting. ==========
//======================================================================
// The name of the element to be shown is passed to this
// function. It then removes the none styling of the
// element, thus showing it.
var isDivHidden;
function showContent(myElement) {
	if(document.getElementById(myElement)) {
		//if(isDivHidden==false) {
		//	hideContent(myElement);
		//}
		//else {
			document.getElementById(myElement).style.display="";
		//	isDivHidden = false;
			//document.body.style.cursor="wait";
			//window.alert("showContent");
		//}
	}
}

// Change the style of the element passed to the function
// to none, which hides it.
function hideContent(myElement) {
	if(document.getElementById(myElement)) {
		document.getElementById(myElement).style.display="none";
	//	isDivHidden = true;
		//document.body.style.cursor="wait";
		//window.alert("hideContent");
	}
}

// Calls both the hideContent and showContent functions, then submits the form.
function submitFormContents() {
	hideContent("tblSubmit");
	document.body.style.cursor="wait";
	showContent("tblSubmitting");
}
//======================================================================
// ========== These functions will show & hide form contents when submitting. ==========
//======================================================================


//========================= XssHttpRequest For AJAX ================================
//========================= AJAX Requests Within 2 DNSs
/* XssHttpRequest version 1.0
 * (c) 2005 Jeffrey Sambells <info@jeffreysambells.com>
 *
 * XssHttpRequest is freely distributable under the terms of an MIT-style license.
 * For details, see the XssHttpRequest web page: http://jeffreysambells.com/XssHttpRequest
 */
var XssHttpRequestCount=0;
var XssHttpRequestWatchList=[];
var X=function(){this.ins=++XssHttpRequestCount;this.u;this.so;this.w;this.wc=0;this.to=30;this.responseText=null;this.responseXML=null;this.status=null;this.readyState=0;};
X.prototype.onreadystatechange=function(){};
X.prototype.onerror=function(){};
X.prototype.onload=function(){};
X.prototype.ss=function(s){this.status=s;};
X.prototype.srs=function(a){if(this.readyState<a||a==0){this.readyState=a;this.onreadystatechange();if(this.readyState=='2'){this.srs(3);eval("if(typeof XssHttpRequest"+this.ins+"Loaded!='undefined'){this.responseText=XssHttpRequest"+this.ins+"Loaded;this.ss('200');}else{alert('invalidresponsefromserver.');}");this.so.parentNode.removeChild(this.so);this.srs(4);this.onload();}}};
X.prototype.open=function(m,u,n){this.u=u;this.so=document.createElement('script');this.so.setAttribute('id','XssHttpRequest'+this.ins);if(navigator.userAgent.indexOf('Safari')){this.so.setAttribute('charset','utf-8');}};
X.prototype.send=function(){this.srs(1);this.so.setAttribute('type','text/javascript');this.so.setAttribute('src',this.u+((this.u.indexOf('?')!=-1)?'&':'?')+'XssHttpRequestVar=XssHttpRequest'+this.ins+'Loaded');this.so=document.getElementsByTagName('head')[0].appendChild(this.so);XssHttpRequestWatchList[this.ins]=this;this.w=setInterval('XssHttpRequestWatchList['+this.ins+'].wl()',500);};
X.prototype.wl=function(){this.wc++;eval("if(typeof XssHttpRequest"+this.ins+"Loaded!='undefined'){clearInterval(this.w);this.srs(2);}else if(this.wc==this.to){clearInterval(this.w);this.onerror('TimedOut');}");};
var XssHttpRequest=X;
//========================= XssHttpRequest For AJAX ================================


//========================= Contents Load From ASP Via AJAX ================================
function doRequest(page_name,var_name,load_text,place_id) {
	request = new XssHttpRequest();
	document.getElementById(place_id).innerHTML=load_text;
	request.open("GET", page_name+var_name+"&sid="+Math.random(), true);
	request.onreadystatechange=function() {
		if(request.readyState==4) {
			document.getElementById(place_id).innerHTML=request.responseText;
		}
	}
	request.send(null);
}
//========================= Contents Load From ASP Via AJAX ================================


//========================= Login Status Load From ASP Via AJAX ================================
function doLoadLoginStatus(page_name,var_name,load_text,place_id) {
	LoadLoginStatus = new XssHttpRequest();
	document.getElementById(place_id).innerHTML=load_text;
	LoadLoginStatus.open("GET", page_name+var_name+"&sid="+Math.random(), true);
	LoadLoginStatus.onreadystatechange=function() {
		if(LoadLoginStatus.readyState==4) {
			document.getElementById(place_id).innerHTML=LoadLoginStatus.responseText;
		}
	}
	LoadLoginStatus.send(null);
}
//========================= Login Status Load From ASP Via AJAX ================================


//========================= Contents Load From ASP Via AJAX V2 ================================
//========================= AJAX Requests Within The Same DNS
var xmlHttp;
var posPlace;

function fnAJAXRequest(page_name,var_name,load_text,place_id) {
	posPlace = place_id
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
  	document.getElementById(posPlace).innerHTML=load_text;
	var url=page_name+var_name;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() {
	if (xmlHttp.readyState==4) {
		document.getElementById(posPlace).innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try
  	{
  	// Firefox, Opera 8.0+, Safari
  	xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  		// Internet Explorer
  		try
    		{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
  		catch (e)
    		{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
  	}
	return xmlHttp;
}
//Function to call the ASP and load the contents...
//========================= Contents Load From ASP Via AJAX V2 ================================


//========================= Delete Confirmation Alert ================================
function fnDeleteConfirmation(strURL) {
	var ConfQ=window.confirm("Are You Sure You Want To Delete This Record?\n\nCan Not Be Recovered Again...");
	if (ConfQ==true) {
		window.location=strURL;
		window.alert('Successfully Deleted...');
	}
	else {
		window.alert("Not Deleted...");
	}
}
//========================= Delete Confirmation Alert ================================


//========================= Right Section ================================
function doDisplayRightSection(paraLevel) {
	var LinkLevel, ImageLevel;
	switch (paraLevel) {
		case "0" :
			LinkLevel = "";
			ImageLevel="images/";
			break;
		case "1" :
			LinkLevel = "../";
			ImageLevel="../images/";
			break;
		case "2" :
			LinkLevel = "../../";
			ImageLevel="../../images/";
			break;
		case "3" :
			LinkLevel = "../../../";
			ImageLevel="../../../images/";
			break;
		default :
			LinkLevel = "";
			ImageLevel="images/";
	}
	//document.write("<iframe id=\"frmAdvertisements\" src=\"" + LinkLevel + "advertisements/advertisements.html\" width=\"100%\" height=\"900\" frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\"><p>Your browser does not support iframes.</p></iframe>");
	document.write("<iframe id=\"frmAdvertisements\" src=\"" + LinkLevel + "advertisements/advertisements.asp\" width=\"100%\" height=\"1200\" frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\"><p>Your browser does not support iframes.</p></iframe>");
	document.write("<img src=\"" + ImageLevel + "common/pix_trans.gif\" alt=\"\" width=\"15\" height=\"15\" />");
}
//========================= Right Section ================================

//======================================================================
//===== © 2009 Singer (Sri Lanka) PLC. All Rights Reserved.
