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);
}

function addRecordToList(question, fldName, newFldName) {
	var cName = prompt(question, '');
	if (cName) {
		cNameSm = cName.toLowerCase();
		pEl = gE(fldName);
		selectT=0;
		for (i=0; i<pEl.options.length; i++) {
			el = pEl.options[i];
			if (el.text.toLowerCase()==cNameSm) {
				selectT = el.value;
				i = pEl.options.length++;
			}
		}
		if (selectT===0) {
			nEl = document.createElement("option");
			switch (fldName) {
			case "city":
			case "region":
				nEl.value=cName;
				selectT = cName;
				break;
			default:
				nEl.value=9999999;
				selectT = 9999999;
			}
			nEl.text=cName;
			pEl.add(nEl);
			gE(newFldName).value=cName;
		}
		pEl.value=selectT;
	}
}

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

/* dropdowns on shopBy top bar */
dropLPshown=0;
function displayDropDown(dropLPid) {
	if (gE('lp' + dropLPid + 'drop')) {
		gE('lp' + dropLPid + 'drop').style.display='block';
		dropLPshown=dropLPid;
	}
}
function hideDropDown(dropLPid) {
	if (gE('lp' + dropLPshown + 'drop')) {
		gE('lp' + dropLPshown + 'drop').style.display='none';
		dropLPshown=0;
	}
}

// this is being used on MouseOver at Features menu
function toggleFeaturesStar(starNum, imgPath, imgSuffix) {
	if (gE('featuresStar' + starNum))
		gE('featuresStar' + starNum).src=imgPath + 'star' + imgSuffix + '.gif';
}

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 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;
}

function uncheckFields(fieldName) {
	var fields = document.getElementsByName(fieldName);
	
	if (fields) {
		$A(fields).each(function(el) { el.checked = false; } );
	}
}

// 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" wmode="transparent" />' +
	'</object>';
	if (container==undefined)
		document.body.innerHTML = html;
	else
		gE(container).innerHTML = html;
}


function number_format(number, decimals, dec_point, thousands_sep) {
  // http://kevin.vanzonneveld.net
  // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +     bugfix by: Michael White (http://getsprink.com)
  // +     bugfix by: Benjamin Lupton
  // +     bugfix by: Allan Jensen (http://www.winternet.no)
  // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  // +     bugfix by: Howard Yeend
  // +    revised by: Luke Smith (http://lucassmith.name)
  // +     bugfix by: Diogo Resende
  // +     bugfix by: Rival
  // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
  // +   improved by: davook
  // +   improved by: Brett Zamir (http://brett-zamir.me)
  // +      input by: Jay Klehr
  // +   improved by: Brett Zamir (http://brett-zamir.me)
  // +      input by: Amir Habibi (http://www.residence-mixte.com/)
  // +     bugfix by: Brett Zamir (http://brett-zamir.me)
  // +   improved by: Theriault
  // *     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);
}

/**
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*/
function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }

    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}