function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object 
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to 
      // build the message. Message includes i (the object's property name) 
      // then the object's property value on a new line 
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they 
      // click "CANCEL" then quit this level of recursion 
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object 
      if (typeof obj[i] == "object") { 
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

// kac.registerEvent ("OnSelect",function(sender,arg){ dumpProps(sender); } );

function runAjaxAction(action, params, showPreload, updateElement)
{
	if (params != "") { params="&"+params; }
	url = "scripts/ajax_events.php?action="+action+params;
	var htmlResponse = LoadHTML(url,showPreload,updateElement);
	return htmlResponse;
}
function runAjaxActionById(action, params,showPreload,updateId)
{
	element = document.getElementById (updateId);
	return runAjaxAction (action,params,showPreload,element);
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}



// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


function checkEmail(str) {
	///// function for validating email address
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){
		return false
	} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	} else  if (str.indexOf(at,(lat+1))!=-1){
		return false
	} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	} else  if (str.indexOf(dot,(lat+2))==-1){
		return false
	} else if (str.indexOf(" ")!=-1){
		return false
	} else {
		return true
	}
}

function checkMultipleEmail(emails, split_char)
{
	emails_array = emails.split(split_char);
	checkStatus = true;
	for (e in emails_array)
	{
		if (trim(emails_array[e]) != "" && !checkEmail(trim(emails_array[e])))
		checkStatus =false;
	}
	return checkStatus;
}


function checkML(emailValue)
{
	if(!checkEmail(emailValue))
	{
		alert (_tpl_emailNotValid);
		document.joinML.focus();
		return false;
	} else {
		var url = "xmlJoinML.php?joinML_email="+emailValue+"&siteLang="+siteLang;
		var xml = LoadXML(url);
		if(xml != null)
		{
			var message = xml.getElementsByTagName('rsp')[0].firstChild.data;
			alert(message);
			var response = xml.getElementsByTagName('rsp_stat')[0].firstChild.data;
			if (response)
			document.joinML.reset();
			else
			document.joinML.focus();
		}
		return false;
	}
}

function getHTTPObject()
{
	try { return new XMLHttpRequest(); } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	alert("XMLHttpRequest not supported");
	return null;
}

var donepage = 0;
var LoadHTMLLayer = 0;
function LoadHTML(url,showPreload,updateElement)
{
	var xmlHttp = getHTTPObject();
	if (showPreload == true) 
	{
		show_preload();
		LoadHTMLLayer+=1;
	}
	if (updateElement == null) 
		xmlHttp.open("GET",url, false);
	else 
	{
		xmlHttp.open("GET",url, true);
	}
		
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState != 4)  { return; }

		if (showPreload == true) {
			LoadHTMLLayer-=1;
			if (LoadHTMLLayer==0)
			var t = setTimeout('hide_preload();',500); 
		}
		var serverResponse = xmlHttp.responseText;
		if (updateElement != null)
		{
			updateElement.innerHTML = serverResponse;
		}
	}
	xmlHttp.send(null);
	if (updateElement == null) return xmlHttp.responseText;
}

function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState != 4)  { return; }
		var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}



// bulid string with the form values, fobj the form object, valFunc is validate function
function getFormValues(fobj)
{
	var str = "";
	var valueArr = null;
	var val = "";
	var cmd = "";

	for(var i = 0;i < fobj.elements.length;i++)
	{
		switch(fobj.elements[i].type)
		{
			case "text":
			case "hidden":
			case "textarea":
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;

			case "radio":
			case "checkbox":
			if(fobj.elements[i].checked)
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;

			case "select-one":
			str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
			break;
		}
	}

	str = str.substr(0,(str.length - 1));
	return str;
}

// validate is got the validate function, if false then skip the validation
function submitAjaxForm(f,url)
{
	var str = getFormValues(f);
	xmlReq = postAjaxForm(url ,str);

}

function postAjaxForm(url,str)
{
	var doc = null
	if (typeof window.ActiveXObject != 'undefined' )
	{
		doc = new ActiveXObject("Microsoft.XMLHTTP");

	}
	else
	{
		doc = new XMLHttpRequest();
		doc.onload = displayState;
	}

	doc.open( "POST", url, true );
	doc.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	doc.send(str);
	return doc.responseXML.documentElement;
}

function showMessage(message, elementID)
{
	document.getElementById(elementID).innerText=message;
}

function clearMessage(elementID)
{
	document.getElementById(elementID).innerText="";
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;


	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function trim(strText) {
	/// TRIM STRING FUNCTION
	// this will get rid of leading spaces
	while (strText.substring(0,1) == ' ')
	strText = strText.substring(1, strText.length);
	// this will get rid of trailing spaces
	while (strText.substring(strText.length-1,strText.length) == ' ')
	strText = strText.substring(0, strText.length-1);
	return strText;
}

function escapeString(sString)
{
	// DETECT WHAT TO PUT STRING IN FOR HTML FORM ( ' OR " ) DEPANDING ON STRING CONTENTS
	if (sString.indexOf("'") == -1)
	valSep = "'";
	else
	valSep = '"';
	return valSep+sString+valSep;
}

function replaceSubstring(inputString, fromString, toString) {
	// GOES THROUGH THE INPUTSTRING AND REPLACES EVERY OCCURRENCE OF FROMSTRING WITH TOSTRING
	var temp = inputString;
	if (fromString == "") {
		return inputString;
	}
	if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
		while (temp.indexOf(fromString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
		var midStrings = new Array("~", "`", "_", "^", "#");
		var midStringLen = 1;
		var midString = "";
		// Find a string that doesn't exist in the inputString to be used
		// as an "inbetween" string
		while (midString == "") {
			for (var i=0; i < midStrings.length; i++) {
				var tempMidString = "";
				for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
				if (fromString.indexOf(tempMidString) == -1) {
					midString = tempMidString;
					i = midStrings.length + 1;
				}
			}
		} // Keep on going until we build an "inbetween" string that doesn't exist
		// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
		while (temp.indexOf(fromString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + midString + toTheRight;
		}
		// Next, replace the "inbetween" string with the "toString"
		while (temp.indexOf(midString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(midString));
			var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} // Ends the check to see if the string being replaced is part of the replacement string or not
	return temp; // Send the updated string back to the user
}

function popupWin(popUrl, width, height)
{
	if (!navigator.appName.indexOf("Microsoft")) width+=20;
	height+=5;
	topVar=((screen.height / 2)-(height/2));
	leftVar=((screen.width / 2)-(width/2));
	window.open(popUrl, "PopUp", "height="+height+", width="+width+", top="+topVar+", left="+leftVar+", scrollbars=yes, status=no, location=no, resize=yes, menubar=no, titlebar=no, toolbar=no");
}

function findPos(obj)
{
    var curleft = curtop = 0;

    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);

        return [curleft,curtop];
    }
}

function switchDisplayByID(elemID,display_type){
	var elm = document.getElementById(elemID);
	switchElementVisibility (elm,display_type);
}
function switchElementVisibility (obj,display_type){
//	if (!display_type) var display_type="";
	if (obj) {
//		if (display_type=="inline" || display_type="none") obj.style.display=display_type; else
		if (obj.style.display=="none" || obj.style.display=="") obj.style.display="inline"; else
		if (obj.style.display=="inline") obj.style.display="none";
	}
}
function hideDisplayByID(elemID){
	switchDisplayByID(elemID,'none');
}
function showDisplayByID(elemID){
	switchDisplayByID(elemID,'inline');
}

function switchElementDisplay(elementID, display_type, callObj){
	// SWITCH SELECTED ELEMENT DISPLAY: NONE/INLINE
	var elm = document.getElementById(elementID);
	var leftOffset = 260;
	var topOffset = -75;
	if ((callObj && elm.style.top == '' && elm.style.display != 'none')	|| (!callObj && elm.style.top != ''))	//it is open from cart
		elm.style.display = "none";

	if (elm.style.display=="none") {
		if (callObj) {
			var curPos = findPos(callObj);
			elm.style.top = (curPos[1] + topOffset) + 'px';
			elm.style.left = (curPos[0] + leftOffset) + 'px';
		}
		else {
			elm.style.top = '';
			elm.style.left = '';
		}
		elm.style.display=display_type;
	}
	else
		elm.style.display="none";
}

function expand_menu(table_id, menu_path, this_div)
{
	// FUNCTION FOR EXPANDING MENU BRANCHES
	curTable = document.getElementById(table_id);
	tableRows = curTable.rows.length;
	display_show = (navigator.appName == "Microsoft Internet Explorer") ? "inline" : "table-row";
	div_cClass = this_div.className;
	time_int = 0;
	if (div_cClass == "sMenu_closed")
	{
		for (i=1; i<tableRows; i++)
		{
			curRow = curTable.rows[i];
			if (curRow.id.indexOf(menu_path+"_") > -1)
			{
				setTimeout("switchElementDisplay('"+curRow.id+"', '"+display_show+"')", time_int);
				time_int+=10;
			}
		}
		this_div.className = "sMenu_open";
	}
	else if (div_cClass == "sMenu_open")
	{
		for (i=1; i<tableRows; i++)
		{
			curRow = curTable.rows[i];
			if (curRow.id.indexOf(menu_path) > -1)
			{
				setTimeout("switchElementDisplay('"+curRow.id+"', 'none')", time_int);
				row_arrow = curRow.firstChild.firstChild;
				if (row_arrow.className == "sMenu_open")
				row_arrow.className = "sMenu_closed";
				time_int+=10;
			}
			this_div.className = "sMenu_closed";
		}
	}
}

function beginDrag(elementToDrag, event){
	var deltaX = event.clientX - parseInt(elementToDrag.style.left);
	var deltaY = event.clientY - parseInt(elementToDrag.style.top);
	if (document.addEventListener){
		document.addEventListener("mousemove", moveHandler, true);
		document.addEventListener("mouseup", upHandler, true);
	}
	else if (document.attachEvent){
		document.attachEvent("onmousemove", moveHandler);
		document.attachEvent("onmouseup", upHandler);
	}
	else {
		var oldmovehandler = document.onmousemove;
		var olduphandler = document.onmouseup;
		document.onmousemove = moveHandler;
		document.onmouseup = upHandler;
	}
	if (event.stopPropagation) event.stopPropagation();
	else event.cancelBubble = true;
	if (event.preventDefault) event.preventDefault();
	else event.returnValue = false;
	function moveHandler(e){
		if (!e) e = window.event;
		elementToDrag.style.left = (e.clientX - deltaX) + "px";
		elementToDrag.style.top = (e.clientY - deltaY) + "px";
		if (e.stopPropagation) e.stopPropagation();
		else e.cancelBubble = true;
	}
	function upHandler(e){
		if (!e) e = window.event;
		if (document.removeEventListener){
			document.removeEventListener("mouseup", upHandler, true);
			document.removeEventListener("mousemove", moveHandler, true);
		}
		else if (document.detachEvent){
			document.detachEvent("onmouseup", upHandler);
			document.detachEvent("onmousemove", moveHandler);
		}
		else {
			document.onmouseup = olduphandler;
			document.onmousemove = oldmovehandler;
		}
		if (e.stopPropagation) e.stopPropagation();
		else e.cancelBubble = true;
	}
}



// AJAX for login form (replay_header.php)
function checkLogin(cForm)
{
	if (cForm.userName.value == "" || cForm.password.value == "")
	{
		alert(_empLogin);
		if(cForm.userName.value == "")
		cForm.userName.focus();
		else if(cForm.password.value == "")
		cForm.password.focus();
	}
	else
	{
		// ajax check login
		var url = "xml_login.php?logMember=true&userName="+cForm.userName.value+"&password="+cForm.password.value;
		//		window.clipboardData.setData('Text',url);
		var xml = LoadXML(url);
		if(xml != null)
		{
			if (xml.getElementsByTagName('login')[0].firstChild.data == "logged")
			location.reload();
			else
			{
				var message = xml.getElementsByTagName('rsp')[0].firstChild.data;
				alert (message);
				cForm.userName.focus();
			}
		}
	}
	return false;
}



function getHTTPObject()
{
	try { return new XMLHttpRequest(); } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	alert("XMLHttpRequest not supported");
	return null;
}

function LoadXMLObject(url)
{

	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState != 4) { return; }
		var serverResponse = xmlHttp.responseText;
	}
	xmlHttp.send(null);

	return xmlHttp.responseText;
}



var last_open = null;

function expandMenu(elm)
{
	var parent = elm.parentNode;
	//look for a UL in tag name

	for (var i=0; i<parent.childNodes.length; i++) {
		if (parent.childNodes[i].tagName == "UL") {
			break;
		}
	}
	if (i == parent.childNodes.length) {	//not found
		return;
	}
	parent.childNodes[i].style.display = (parent.childNodes[i].style.display == "none") ? "block" : "none";
	last_open = parent.childNodes[i];


	elm.className=(elm.className == "expand_button") ? "minusbutton" : "expand_button";

	return;
}
function expandparent(curelm)
{

	var parent = curelm.parentNode;
	expandMenu(parent.childNodes[0]);
}

var curinterval=0;
function autoexpand(pelm)
{
	var parent=pelm.parentNode;
	curinterval=setInterval(expandMenu,1000,parent);

}



function disableinterval()
{
	curinterval=window.clearInterval(curinterval);
}


/***************************************
	 SMALL CART FUNCTION
	Author: Eytan Chen, Feb 2008
***************************************/

// FUNCTION FOR REMOVING ITEM FROM SHOPCART

function ShopCart_DeliveryType(obj)
{
	if (!obj)
		return;

	var actionStr = 'setDeliveryType&type=' + obj.selectedIndex;
	ShopCart_Action(actionStr, null);
}

function ShopCart_Action(action, prdID)
{
//	url = "scripts/ajax_events.php?action="+action+"&prdID="+prdID;
//	var htmlResponse = LoadHTML(url);
	var htmlResponse = runAjaxAction(action,"prdID="+prdID);
	if(htmlResponse != null)
	{
		sCart = document.getElementById("sCart_data");
		sCart.innerHTML = htmlResponse;
	}
}

function frameShopCart_Action(action, prdID)
{
//	url = "scripts/ajax_events.php?action="+action+"&prdID="+prdID;
//	var htmlResponse = LoadHTML(url);
	var htmlResponse = runAjaxAction(action,"prdID="+prdID);
	if(htmlResponse != null)
	{
		sCart = parent.document.getElementById("sCart_data");
		sCart.innerHTML = htmlResponse;
	}
}

function sendUserOrder()
{
	var obj = document.getElementById('phoneOrderNum');
	if (!obj) return false;
//	alert (obj.value.match(/[^0-9\-]/)));
	if (obj.value.match(/[^0-9\-]/)) {
		alert(_numbersOnly);
		return false;
	}

//	url = "scripts/ajax_events.php?action=phoneOrder&number="+obj.value;
//	var htmlResponse = LoadHTML(url);
	runAjaxAction ("phoneOrder","number="+obj.value);
	obj.value = _orderSend;
	return true;
}

function ShowHelpFlash(flashFile)
{
	var obj = document.getElementById('HelpWindow');
	if (obj) {
		var par = obj.parentNode;
		par.removeChild(obj);
	}
	obj = document.getElementById('FlashHelpCnt');
	obj.innerHTML = null;		//will clear if flash is playing already
	var fo = new FlashObject(flashFile, "f_helpFlash", "200", "300", "6", "#FFFFFF");
	fo.addParam("quality", "high");
	fo.addParam("wmode", "transparent");
	fo.write("FlashHelpCnt");
	obj.style.display = "block";
}

function switchSelection(id)
{
	var obj = document.getElementById(id);
	if (!obj)
		return;
	if (obj.checked)
		obj.checked = false;
	else
		obj.checked = true;
	 updateMnfFilter();
}

/***********************************************
* DHTML Billboard script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function contractboard(){
	var inc=0;
	while (document.getElementById("billboard"+inc)){
		document.getElementById("billboard"+inc).style.display="none";
		inc++;
	}
}


function expandboard(){
	var selectedDivObj=document.getElementById("billboard"+selectedDiv)
	contractboard()
	if (selectedDivObj.filters){
		if (billboardeffects.length>1){
			filterid=Math.floor(Math.random()*billboardeffects.length);
			selectedDivObj.style.filter="progid:DXImageTransform.Microsoft."+billboardeffects[filterid];
		}
		selectedDivObj.filters[0].duration=effectduration/1000;
		selectedDivObj.filters[0].Apply();
	}
	selectedDivObj.style.display="block";
	if (selectedDivObj.filters)	selectedDivObj.filters[0].Play();
	selectedDiv=(selectedDiv<totalDivs-1)? selectedDiv+1 : 0;
	setTimeout("expandboard()",tickspeed);
}

function startbill(){
	while (document.getElementById("billboard"+totalDivs)!=null)
		totalDivs++;
	if (document.getElementById("billboard0").filters);
	tickspeed+=effectduration;
	expandboard();
}

function getSelectedPrd()
{
	var ins = document.getElementsByTagName('input');
	var res = new Array();
	
	for (j=0, i=0; i<ins.length; i++) {
		if (!ins[i].id.match(/comp+/))
		{
			continue;
		}

		if (ins[i].checked) 
		{
			res[j++] = ins[i].value;						
		}
	}
	
	return res;	
}

function applyComparePrd()
{
	var url = location.href;
	//remove any previous filter
	url = url.replace(/\&ids=[^&]*/, '');
	//remove any page numbering
	//url = url.replace(/\&Secid=[^&]*/, '');
	
	var fltData = getSelectedPrd();
	if (!fltData.length)
	{
		alert(_chcomprdt);
		return false;
	}
	var fltStr = '';
	for (i=0; i<fltData.length-1; i++)
		fltStr += fltData[i] + ',';
	fltStr += fltData[i];
	
	if( fltStr &&  fltData[0] && fltData[1])	
	{
		var retstr = 'product_compare.php?ids='+ fltStr;
		location.href = retstr;
	}
	else
	{
		alert(_chcomprdt);
		return false;
	}
	return false;
}

function switchSelectiononly(id)
{
	var obj = document.getElementById(id);
	if (!obj)
		return;
	if (obj.checked)
		obj.checked = false;
	else
		obj.checked = true;
	// updateMnfFilter();
}

function changetextsize(curid,type)
{
	if(type=="close")
	      curid.className="";	
	else
	      curid.className="bigtextarea";	
	return false;
}

function combotext_onkeydown(e,oText,Select){
  
  keyCode = e.keyCode;  
  oSelect = document.getElementById (Select);
  if (oSelect == null) return false;
  
  if (keyCode == 40 || keyCode == 38) {  
    oSelect.style.display = 'block';  
    oSelect.focus();  
    comboselect_onchange(oSelect, oText);  
  }  
  else if (keyCode == 13) {  
    e.cancelBubble = true;  
    if (e.returnValue) e.returnValue = false;  
    if (e.stopPropagation) e.stopPropagation();  
    comboselect_onchange(oSelect, oText);  
    oSelect.style.display='none';  
    oText.focus();  
    return false;  
  }  
  else if(keyCode == 9) return true;  
 /* else { //alert(keyCode);  
  
    oSelect.style.display = 'block';  
  
    var c = String.fromCharCode(keyCode);  
    c = c.toUpperCase();   
    toFind = oText.value.toUpperCase() + c;  
  
    for (i=0; i < oSelect.options.length; i++){  
       nextOptionText = oSelect.options.text.toUpperCase();  
  
        if(toFind == nextOptionText){  
            oSelect.selectedIndex = i;  
            break;  
        }  
  
        if(i < oSelect.options.length-1){  
           lookAheadOptionText = oSelect.options[i+1].text.toUpperCase() ;  
           if( (toFind > nextOptionText) &&   
              (toFind < lookAheadOptionText) ){  
              oSelect.selectedIndex = i+1;  
              break;  
           }  
         }  
         else {  
           if(toFind > nextOptionText){  
               oSelect.selectedIndex = oSelect.options.length-1; // stick it at the end  
               break;  
           }  
       }  
    } 
  }   */
}  

function comboselect_onchange(oSelect,oText) {  
  if(oSelect.selectedIndex != -1)  
    oText.value = oSelect.options[oSelect.selectedIndex].text;  
}  
  
function comboselect_onkeyup(keyCode,oSelect,oText){  
  if (keyCode == 13) {  
    comboselect_onchange(oSelect, oText);  
    oSelect.style.display='none';  
    oText.focus();  
  }  
}  

function updatemaininp(id,propname)
{
	propiddata=document.getElementById("prop."+id+"."+propname);
	propselectid=document.getElementById("prdselpupd_"+id+"_"+propname);
	if(propselectid.value!="none")
	{
		propiddata.value=propselectid.value;
	}
	return false;
}

function changeelementsdisplay(id,propname)
{
		propiddata=document.getElementById("prop."+id+"."+propname);
		propselectid=document.getElementById("prdselpupd_"+id+"_"+propname);
		if(propselectid.style.display=="none")
		{
			propselectid.style.display="inline";
		}
		else
		{
			propselectid.style.display="none";
		}
		
		if(propiddata.style.display=="none")
		{
			propiddata.style.display="inline";
		}
		else
		{
			propiddata.style.display="none";
		}
	return false;
}

function hideSelect(id)
{
	var selectedtr=document.getElementById(id);
	selectedtr.style.display='none';
	return false;
}


function frameparentlink(curprdid)
{
	parent.location="Products.php?id="+curprdid;
	return false;
}

if (window.addEventListener) window.addEventListener("load", startbill, false);
else if (window.attachEvent) window.attachEvent("onload", startbill);
else if (document.getElementById) window.onload=startbill;

function updateTextBox(textBoxId,valueToUpdate,otherOptions)
{
	var cnt = document.getElementById(textBoxId);
	var boxValue = cnt.value;
	var select = document.getElementById(otherOptions);
	
	if(options == null)
		cnt.value = valueToUpdate;
	else {
		var options = select.getElementsByTagName("option");
		for(i=0; i<options.length; i++) {
			var tempValue = options[i].value;
			if(boxValue.search(tempValue)>0)
				break;
		}
		boxValue = boxValue.replace(tempValue,valueToUpdate);
	}
}

function onlyNumbers(e)
{
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
    		keynum = window.event.keyCode;
	  else if(e.which) // Netscape/Firefox/Opera
  		  keynum = e.which;
  	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
	return numcheck.test(keychar);
}

function onlyNumbersAndDot(e)
{
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
    		keynum = window.event.keyCode;
	  else if(e.which) // Netscape/Firefox/Opera
  		  keynum = e.which;
  	keychar = String.fromCharCode(keynum);
	numcheck = /[\d\.]/;
	return numcheck.test(keychar);
}

function getTimeValue(id)
{
	cnt = document.getElementById(id);
	var hours = document.getElementById(id+'_hours');
	var minutes = document.getElementById(id+'_minutes');
	var string = "";
	string = hours.value + ":" + minutes.value;
	cnt.value = string;
}

function objectAdd(objectId, inputId)
{
	cnt = document.getElementById(inputId);
	cnt.value = objectId;
}

function multipleObjectAdd(objectId,inputId)
{
	cnt = document.getElementById(inputId);
	var value = cnt.value;
	if(!(value.search(objectId)>0))
		value += ", " + objectId;
	cnt.value = value;
}

function redirectPage()
{
	var url = location.href;
	location.href = url;
}

function openInfoPage(url)
{
//	window.open (url); 
window.open(url, "", "width=600px, height=450px, resizable");
//	window.open(url);
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}


function getPageSize() {
  size_arr = new Array();
  size_arr[0] = 0;
  size_arr[1] = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    size_arr[0] = window.innerWidth;
    size_arr[1] = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    size_arr[0] = document.documentElement.clientWidth;
    size_arr[1] = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    size_arr[0] = document.body.clientWidth;
    size_arr[1] = document.body.clientHeight;
  }
  return size_arr;
}


var overlay="";

function show_preload()
{
	pageScroll = getPageScroll();
	pageSize = getPageSize();

	if (!document.getElementById("pageOverlay"))
	{
		var overlay = document.createElement("DIV");
		overlay.id = "pageOverlay";
		overlay.style.top = pageScroll[1];
		document.body.appendChild(overlay);

	}
	else
		overlay.style.top = pageScroll[1];

	if (!document.getElementById("preloader"))
	{
		preload = document.createElement("DIV");
		preload.id = "preloader";
		preload.style.display = "block";
		preload.style.top = (parseFloat(pageSize[1])/2) + pageScroll[1];
		preload.style.zIndex = "999";
		document.body.appendChild(preload);
	}
	else
		preload.style.top = (parseFloat(pageSize[1])/2) + pageScroll[1];

	document.body.onscroll = move_preload;
}

function move_preload()
{
	pageScroll = getPageScroll();
	pageSize = getPageSize();
	overlay = document.getElementById("pageOverlay");
	preload = document.getElementById("preloader");
	if (!overlay || !preload) return;
	overlay.style.top = pageScroll[1];
	preload.style.top = (parseFloat(pageSize[1])/2) + pageScroll[1];
}

function hide_preload()
{
	if (document.getElementById("preloader"))
	{
		document.body.removeChild(document.getElementById("preloader"));
	}
	if (document.getElementById("pageOverlay"))
	{
		document.body.removeChild(document.getElementById("pageOverlay"));
	}
	document.body.onscroll = null;
}


//function updateFile(fileName)
//{
//	//fileName = **.php
//	if(confirm(_removeprd))
//	{
//		var url = "scripts/ajax_events.php?action=updateFromDevelop"+"&fileName=" + fileName;
//		var htmlResponse = LoadHTML(url);
//		if(htmlResponse)
//			alert(htmlResponse);
//		else
//			alert("אירעה שגיאה בעדכון.");
//	}
//}

function updateMnfFrame(value,frameId,field)
{
	var frameObj = document.getElementById(frameId);
	frameObj.style.display = "block";
	var url = "scripts/ajax_events.php?field="+field+"&value="+value;
	var htmlResponse = LoadHTML(url);
	if(htmlResponse)
	alert(htmlResponse);
//		frameObj.innerHTML = htmlResponse;
	else
		frameObj.innerHTML = "אירעה שגיאה.";
	
}

function close_autocomplete()
{
	kac.close();
	document.getElementById(txtSearchId).focus();
}