/*
function makeDoubleDelegate(function1, function2) {
    return function() {
        if (function1)
            function1();
        if (function2)
            function2();
    }
} 
*/
var imgPressedButton=new Image;
imgPressedButton.src='../images/Butten_doun.gif';
var imgReleasedButton=new Image;
imgReleasedButton.src='../images/Butten_up.gif';

var imgPressedSearch=new Image;
imgPressedSearch.src='../images/look_for_but_doun.gif';
var imgReleasedSearch=new Image;
imgReleasedSearch.src='../images/look_for_but_up.gif';

function WindowURL(url, frame)
{
	window.open(url,frame,'width=700, height=550, scrollbars=1, resizable=1')
}

function PressButton(sID)
{
	var sName='img'+sID;
	document.images[sName].src=imgPressedButton.src;	
}

function ReleaseButton(sID)
{
	var sName='img'+sID;
	document.images[sName].src=imgReleasedButton.src;	
}

function PressSearch()
{	
	document.images['SearchButton'].src=imgPressedSearch.src;	
}

function ReleaseSearch()
{	
	document.images['SearchButton'].src=imgReleasedSearch.src;	
}

function PressButton(sImage, sButton)
{
	document.images[sImage].src='../images/button/pressed/'+sButton+'.gif';
}

function ReleaseButton(sImage, sButton)
{
	document.images[sImage].src='../images/button/normal/'+sButton+'.gif';
}

function PressCategory(sImage, sCategory)
{
	document.images[sImage].src='../images/category/pressed/'+sCategory+'.gif';
}

function ReleaseCategory(sImage, sCategory)
{
	document.images[sImage].src='../images/category/normal/'+sCategory+'.gif';
}

function PressSale(sImage, sSale)
{
	document.images[sImage].src='../images/general/pressed/'+sSale+'.gif';
}

function ReleaseSale(sImage, sSale)
{
	document.images[sImage].src='../images/general/normal/'+sSale+'.gif';
}

function IsEmptyString(sString)
{
	var bEmpty=true;
	for (var i=0;bEmpty&&(i<sString.length);i++) if (sString.substr(i,1)!=' ') bEmpty=false;
	return (bEmpty);
}

function SubmitIncSearchForm()
{
	if (IsEmptyString(document.frmIncSearch.Product.value))
	{
		alert('חסרים נתונים לחיפוש');
		document.frmIncSearch.Product.value='';
		document.frmIncSearch.Product.focus();
		return;
	}
	document.frmIncSearch.submit();
}

function SubmitPrinterSearchForm()
{
	if (IsEmptyString(document.frmPrinterSearch.SearchPrinter.value))
	{
		alert('חסרים נתונים לחיפוש');
		document.frmPrinterSearch.SearchPrinter.value='';
		document.frmPrinterSearch.SearchPrinter.focus();
		return;
	}
	document.frmPrinterSearch.submit();
}

function ChangeComboSearchDomain()
{
	return ChangeComboSearchDomain_jq()
	if (document.frmComboSearch.SearchDomain.value=='Printer')
	{
		createAutoComplete(saPrinter, "SearchText", "SearchChoices", 15, "");
	}
	else
	{
		createAutoComplete(saProducts, "SearchText", "SearchChoices", 15, "/shop/fulltext.asp");
	}
}

function ChangeComboSearchDomain_jq()
{
	if (document.frmComboSearch.SearchDomain.value=='Printer')
	{
		$("#SearchText").unautocomplete().autocomplete(saPrinter, {
			  //autoFill: true,
			  selectFirst: false,
			  cacheLength: 1,
			  //max: 0,
			  scroll: true,
			  matchContains: true
			}
		);
	}
	else
	{
		$("#SearchText").unautocomplete().autocomplete("/shop/fulltext_jq.asp", {
			  //autoFill: true,
			  selectFirst: false,
			  cacheLength: 1,
			  //max: 0,
			  scroll: true,
			  matchContains: true
			}
		);
	}
}

function elementTop(node)
{
	var top = node.offsetTop;
	while (node.parentNode != undefined && node.parentNode != null)
	{
		node = node.parentNode;
		var ntop = 0;
		if (node.offsetTop != undefined && node.offsetTop != null)
			ntop = node.offsetTop;
		top += ntop;
	}
	return top;
}

function elementLeft(node)
{
	var left = node.offsetLeft;
	while (node.parentNode != undefined && node.parentNode != null)
	{
		node = node.parentNode;
		var nleft = 0;
		if (node.offsetLeft != undefined && node.offsetLeft != null)
			nleft = node.offsetLeft;
		left += nleft;
	}
	return left;
}

function SubmitComboSearchForm()
{
	if (IsEmptyString(document.frmComboSearch.SearchProduct.value))
	{
		alert('חסרים נתונים לחיפוש');
		document.frmComboSearch.SearchProduct.value='';
		document.frmComboSearch.SearchProduct.focus();
		return;
	}
	document.frmComboSearch.submit();
}

function createXMLHttpRequest()
{
	if(typeof ActiveXObject != "undefined") {
		try {return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
		try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	}
	else try { return new XMLHttpRequest(); } catch (e) {}
	alert("XMLHttpRequest not supported");
	return null;
}

function synchronousXMLHttpRequest(url)
{
	var xhReq = new createXMLHttpRequest();
	if (xhReq != null)
	{
		xhReq.open("GET", url, false);
		xhReq.send(null);
		return xhReq.responseText;
	}
	else {
		return null;
	}
}

function getlastelement(HTMLstring)
{
	var d = document.createElement('div');
	d.innerHTML = HTMLstring;
	try {return d.lastChild.nodeValue; } catch (e) {return "";}
}

function divPrinter(divid, dir, width, height, title)
{
	width = typeof(width) != 'undefined' ? width : 450;
	height = typeof(height) != 'undefined' ? height : 450;
	var left = (screen.width-width) / 2;
	var top = (screen.height-height) / 2;
	var Print=window.open('../include/divprinter.asp?type=1&divPrint='+divid+'&dir='+dir+'&title='+title+'',
	                      'fraOrderPrint',
	                      ' width='+width+', height='+height+', scrollbars=0, menubar=1, resizable=0, top='+top+', left='+left+'');
}

function cart_popup()
{
	var doExit = function() {
		//close the dialog
		$("#myDialog").dialog("close");
		$("#myDialog").dialog("destroy").remove();
	};
	var goKupa = function() {
		doExit();
		location.href='../cash/cart.asp';
	};
    var _width = 380;
    var _height = 180;
    $('<iframe id="myDialog" class="myDialog" src="http://www.officer.co.il/cash/product_added.asp"/>').dialog({
		buttons: {"חזרה לחנות": doExit, "לקופה": goKupa},
        title: "עגלת הקניות שלך",
        autoOpen: true,
		closeOnEscape: true,
        width: _width,
        height: _height,
        modal: true,
        resizable: false,
        draggable: false,
        autoResize: true,
        overlay: {
            opacity: 0.0,
            background: "black"
        },
        bgiframe: true
    }).width(_width).height(_height);            
}

function cart_popup0()
{
	var cid = 'cart_popup_div';
	var buttons = {
		"חזרה לחנות":"hidebox('cart_popup_div');",
		"לקופה":"location.href='../cash/cart.asp';"
	};
	var elem = document.getElementById(cid+'_b')
	if (elem == null)
	{
		call_popup2("עגלת הקניות שלך", cid, "info", "../cash/cart_bg.gif", buttons);
	}
}

function call_popup2(title, div, div2, bg, buttons, width, height)
{
	width = typeof(width) != 'undefined' ? width : 350;
	height = typeof(height) != 'undefined' ? height : 240;
	var left = (screen.width-width) / 2;
	var top = (screen.height-height) / 2;
	var tablestyle = "style='background:url(\""+bg+"\") no-repeat;'";
	var tmptext = "";
	tmptext += "<form name='popup_form' height='170px'>";
	tmptext += "<table align='center' dir='rtl' height='170px' width='100%' "+tablestyle+">";
	nbuttons = 0;
	for (var button in buttons)
	{
		++nbuttons;
	}
	tmptext += "<tr height='120px'><td colspan='"+nbuttons+"'>&nbsp;</td></tr>";
	tmptext += "<tr height='50px'>";
	for (var button in buttons)
	{
		tmptext += '<td id="info"><div="info"><a class="button2" align="center" onmouseover="return true;" onclick="' + buttons[button] + '">' + button + '</a></div></td>';
	}
	tmptext += "</tr></table>";
	tmptext += "</form>";
	new popUp(left, top, width, height, div, tmptext, "white", "black", "bold 10pt sans-serif", title, "navy", "white", "#dddddd", "gray", "black", true, true, true, true, false);
}

function call_popup0(title, text, div, div2, img, buttons, width, height)
{
	width = typeof(width) != 'undefined' ? width : 350;
	height = typeof(height) != 'undefined' ? height : 210;
	var left = (screen.width-width) / 2;
	var top = (screen.height-height) / 2;
	var tmptext = "<table align='center' dir='rtl'><tr>";
	tmptext += "<td><img src='" + img + "' /></td>";
	tmptext += "<td style='text-align: center; vertical-align: middle;'><h4>" + text + "</h4></td>";
	tmptext += "</tr></table>";
	tmptext += "<form name='popup_form'><table align='center' dir='rtl'><tr>";
	for (var button in buttons)
	{
		tmptext += '<td id="info"><div="info"><a class="button2" onmouseover="return true;" onclick="' + buttons[button] + '">' + button + '</a></div></td>';
	}
	tmptext += "</tr></table></form>";
	new popUp(left, top, width, height, div, tmptext, "white", "black", "bold 10pt sans-serif", title, "navy", "white", "#dddddd", "gray", "black", true, true, true, true, false);
}

/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/
 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


