// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}

function submitDoc(formName) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		findObj(formName).submit(); 
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}

/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;



						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}

// custom code below:
var ajaxPrinter = new sack();
var ajaxLamp = new sack();
var ajaxOther = new sack();
var urlPrefix = "";

if (String(document.location).indexOf('/sitemap/') >= 0) urlPrefix = "../";

function getLampMakeList()
{
	ajaxLamp.requestFile = urlPrefix+'lampinfo.php?mode=make';	// Specifying which file to get
	ajaxLamp.onCompletion = createLampMakes;	// Specify function that will be executed after file has been found
	ajaxLamp.runAJAX();		// Execute AJAX function
}

function getLampModelList(sel)
{
	var lampMake = sel.options[sel.selectedIndex].value;
	document.getElementById('lampModel').options.length = 0;	// Empty city select box
	if(lampMake.length>0){
		ajaxLamp.requestFile = urlPrefix+'lampinfo.php?mode=model&make='+lampMake;	// Specifying which file to get
		ajaxLamp.onCompletion = createLampModels;	// Specify function that will be executed after file has been found
		ajaxLamp.runAJAX();		// Execute AJAX function
	}
}

function createLampMakes()
{
	var obj = document.getElementById('lampMake');
	eval(ajaxLamp.response);	// Executing the response from Ajax as Javascript code	
}

function createLampModels()
{
	var obj = document.getElementById('lampModel');
	eval(ajaxLamp.response);	// Executing the response from Ajax as Javascript code	
}


function getindexLampMakeList()
{
        ajaxLamp.requestFile = urlPrefix+'indexlampinfo.php?mode=make';      // Specifying which file to get
        ajaxLamp.onCompletion = createindexLampMakes;        // Specify function that will be executed after file has been found
        ajaxLamp.runAJAX();             // Execute AJAX function
}

function getindexLampModelList(sel)
{
        var indexlampMake = sel.options[sel.selectedIndex].value;
        document.getElementById('indexlampModel').options.length = 0;        // Empty city select box
        if(indexlampMake.length>0){
                ajaxLamp.requestFile = urlPrefix+'indexlampinfo.php?mode=model&make='+indexlampMake;      // Specifying which file to get
                ajaxLamp.onCompletion = createindexLampModels;       // Specify function that will be executed after file has been found
                ajaxLamp.runAJAX();             // Execute AJAX function
        }
}

function createindexLampMakes()
{
        var obj = document.getElementById('indexlampMake');
        eval(ajaxLamp.response);        // Executing the response from Ajax as Javascript code
}

function createindexLampModels()
{
        var obj = document.getElementById('indexlampModel');
        eval(ajaxLamp.response);        // Executing the response from Ajax as Javascript code
}


function validateForm(form) {
	if (form == 1) {
		if (document.getElementById('lampMake').options[document.getElementById('lampMake').selectedIndex].value == "" ||
			document.getElementById('lampModel').options[document.getElementById('lampModel').selectedIndex].value == "") {
			return false;
		}
	}
	return true;
        if (form == 2) {
                if (document.getElementById('indexlampMake').options[document.getElementById('indexlampMake').selectedIndex].value == "" ||
                        document.getElementById('indexlampModel').options[document.getElementById('indexlampModel').selectedIndex].value == "") {
                        return false;
                }
        }
        return true;

}

function goToProductPage(form) {
	pageURL = "";
	if (form == 1) {
		pageURL = urlPrefix+"advanced_search_result.php?keywords=" +document.getElementById('lampModel').options[document.getElementById('lampModel').selectedIndex].value;
	}
	return(pageURL);
        if (form == 2) {
                pageURL = urlPrefix+"advanced_search_result.php?keywords=" +document.getElementById('indexlampModel').options[document.getElementById('indexlampModel').selectedIndex].value;
        }
        return(pageURL);

}

function getEmailTimestamp() {
	var today=new Date();
	var HH=today.getHours();
	if (HH<10) HH="0"+HH
	var MI=today.getMinutes();
	if (MI<10) MI="0"+MI
	var YYYY=today.getFullYear();
	var MM=today.getMonth()+1;
	if (MM<10) MM="0"+MM
	var DD=today.getDate();
	if (DD<10) DD="0"+DD

	return(" ("+YYYY+""+MM+""+DD+"-"+HH+""+MI+")");
}

function popup(mylink, windowname) {
	if (! window.focus)return true;
	var href;

	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'width=750,height=550,resizable=yes,scrollbars=yes');
	return false;
}
