function rowHighlight(rID) {
	if (!gE(rID)) return;
	gE(rID).className += " rowH";
}
function rowUnHighlight(rID) {
	if (!gE(rID)) return;
	gE(rID).className = gE(rID).className.replace(" rowH", "");
}

function gE(eID) {
	return document.getElementById(eID);
}

function toggleHidden(hiddenID) {
	if (!document.getElementById) return;
	el = document.getElementById(hiddenID);
	if (el)
		el.style.display = (el.style.display=='none') ?  'block' : 'none';
}

function vardump(obj) {
            var t = '';
			s=1;
            for (i in obj) {
//				if (obj[i]) {
					t += i + ": " + obj[i] + " - - - - - - - - - ";
					if (s==5) {
						t += "\n";
						s=1;
					}
					s ++;
///				}
			}
//            for (i in obj) t += i + ": " + obj[i] + "<br>"
//			document.write(t);
            alert(t);
}

var arImages=new Array();
function Preload() {
	var temp = Preload.arguments; 
	for(x=0; x < temp.length; x++) {
		arImages[x]=new Image();
		arImages[x].src=Preload.arguments[x];
	}
}

function clearPeriod(stField, endField, theForm) {
	clearCalendarField(stField, theForm);
	clearCalendarField(endField, theForm);
}

function clearCalendarField(field, theForm) {
	if (theForm[field])
		theForm[field].value='';
	if (gE('view' + field))
		gE('view' + field).innerHTML='';
}

// tabs management functions
var curTab=0;
function jumpToTab(tabID) {
	if (curTab) {
		setTabImgs('off', curTab);
		switchInfoTable('none', curTab);
	}
	setTabImgs('on', tabID);
	switchInfoTable('block', tabID);
	curTab = tabID;
	if (setValueOfJumpToTab)
		setValueOfJumpToTab();
}
function setTabImgs(way, tabID) {
	tabsPath = '/adm_pnl/images/tabs/';
	if (gE('leftTab' + tabID))
		gE('leftTab' + tabID).src=tabsPath + way + '_left.gif';
	if (gE('rightTab' + tabID))
		gE('rightTab' + tabID).src=tabsPath + way + '_right.gif';
	if (gE('tab' + tabID))
		gE('tab' + tabID).style.backgroundImage='url(' + tabsPath + way + '_back.gif)';
}
function switchInfoTable(setVl, tableID) {
	if (gE('tabTable' + tableID))
		gE('tabTable' + tableID).style.display=setVl;
}
// end of tabs management functions

function bookmarksite(title, url){
	if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
	else if (document.all)
		window.external.AddFavorite(url, title);
}

function switchAreaVsPhoneRequiry(el) {
	if (el) {
		theForm = el.form;
		if (theForm) {
			setVl = (el.value) ? 'NO' : 'YES'; //if there is a value - set to OPTIONAL='NO', otherwise - OPTIONAL='YES'
			elNameLen = el.name.length;
			setFld = (el.name.substring(elNameLen-4)=='area') ? el.name.substring(0, elNameLen-4) : el.name + 'area';
			if (theForm[setFld]) {
				theForm[setFld].setAttribute('OPTIONAL', setVl);
				if (!el.value)
					theForm[setFld].value='';
			}
	}	}
}

var XmlHttp;
var curRequest="";
var responseTexts = new Array();
function createXMLHttp(txtURL) {
	var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp"];
    for (var i = 0; i < aVersions.length; i++) {
		try {
			if (navigator.appName!="Netscape") {
				var oXmlHttp = new ActiveXObject(aVersions[i]);
		    } else {
				var oXmlHttp = new XMLHttpRequest(); 
	    	}
			return oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
    }
//	window.frames['ajaxLegacySupport'].location.href=txtURL;
//	id = window.setTimeout("afterBirksLegacy()",1000);
}

function send(txtURL, runFunction) {
	XmlHttp = createXMLHttp(txtURL);
	if (runFunction) {
		XmlHttp.onreadystatechange = eval(runFunction);
		XmlHttp.open("GET", txtURL);
	}
	XmlHttp.send(null);
}
function sendBrowser(txtURL, runFunction) {
	window.location = txtURL;
	return false;
}
function validateAjaxResponse() {
	var result = '';
	if (XmlHttp.readyState==4) {
		result = XmlHttp.responseText;
		XmlHttp=null;
	}
	return result;
}

function nothingDone(){
}
function validateRadioButton(theFld) {
	found = false;
	var thCounter=0;
	for (thCounter=0; thCounter<theFld.length && !found; thCounter++)
		if (theFld[thCounter].checked)
			found=true;
	if (found)
		res = thCounter;
	else
		res = -1;
	return res;
}

// IE flash activation workaround
function showflash(fileName, w, h, container, objname)
{
	if (objname==undefined)
		objname = 'myFlash';
	var html = '	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  style="z-index:-100;"'+
	'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" '+
	'width="'+w+'" height="'+h+'" id="'+objname+'" align="middle"> ' +
	'<param name="allowScriptAccess" value="sameDomain" />' +
	'<param name="movie" value="'+fileName+'" />' +
	'<param name="quality" value="high" />' +
	'<param name="bgcolor" value="#000000" />' +
	//'<param name="WMODE" value="transparent" />' +
	'<embed src="' + fileName + '" quality="high"  width="'+w+'" height="'+h+'" ' +
	'name="'+objname+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" '+
	'pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
	'</object>';
	if (container==undefined)
		document.body.innerHTML = html;
	else
		document.getElementById(container).innerHTML = html;
}


function topMenuHighlight(el, ev) {
	switch(ev.type) {
	case 'mouseover': removeClass=""; setClass="Hover"; break;
	default: removeClass="Hover"; setClass=""; break;
	}
	if ($(el.id+'left')) {
		$(el.id+'left').removeClassName('left' + removeClass);
		$(el.id+'left').addClassName('left' + setClass);
	}
	if ($(el.id+'right')) {
		$(el.id+'right').removeClassName('right' + removeClass);
		$(el.id+'right').addClassName('right' + setClass);
	}
}

function updateListing(el) {
	theForm = el.form;
	var catUrl = (theForm['searchCat'].selectedIndex) ? theForm['searchCat'].value : '';
	var bandUrl = (theForm['searchBand'].selectedIndex) ? theForm['searchBand'].value : '';
	url = WEB_ROOT + catUrl + bandUrl;
	window.location = url;
}

function stringSearch(theForm) {
	if (!theForm['searchStr']) return false;
	if (theForm['searchStr'].value!='<?=addslashes($dict["searchStrDef"])?>')
		window.location=WEB_ROOT + 'ss-' + theForm['searchStr'].value + '/';
}

function updateShoppingCartBox() {
	if (!$('cartContent')) return false;
	send(AJAX_PATH + 'do=updateShoppingCartBox', 'updateShoppingCartBoxResponse');
}

function updateShoppingCartBoxResponse() {
	if (result = validateAjaxResponse()) {
		if ($('cartContent')) {
			if ($('cartContent').innerHTML.length>0) {
				$('cartContent').update(result);
				if ($('checkoutRightArrow')) {
					$('checkoutRightArrow').appear({ duration: 0.8 });
					setTimeout('if ($(\'checkoutRightArrow\')) { $(\'checkoutRightArrow\').fade({ duration: 0.8 }); }', 5300);
				}
			} else {
				$('cartContent').hide().update(result);
				Effect.BlindDown('cartContent', { duration: 0.5 });
			}
		}
	}	
}

function getHomePageListing(objectId, listType, listWay) {
	if (!$(objectId)) return false;
	ajaxReady = 0;
	tmpAjaxVar = objectId
	send(AJAX_PATH + 'do=getHomeListing&listType=' + listType + '&listWay=' + listWay, 'nwArrvlResponse');
}
function nwArrvlResponse() {
	if (!$(tmpAjaxVar)) return false;
	if (result = validateAjaxResponse()) {
		$(tmpAjaxVar).update(result);
	}
	ajaxReady=1;
}

function number_format(number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands  
    // 
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}
function confirmApply(promoCode, urlToGo) {
	if (confirm('Are you sure you want to apply this promotion to your order?\nNote: if your order already has a promocode assigned, it will be overwritten.\n\nContinue?')) {
		window.location='/actions.php?do=applyPromoToOrder&promocode=' + promoCode + '&urlToGo=' + urlToGo;
	}
	return false;
}

