function removePopup() { if ($('popupBack')) { $('popupBack').remove(); $('popupBox').remove(); } }
function closePopup() { $('popupBack').hide();  $('popupBox').hide(); }
function showAddInfo(infoCode) { 

	if(typeof(popups)=='object') {
		if(popups.length) {
			for (i=0; i<popups.length; i++) {
				var el = popups[i];
				if (el.bCode==infoCode) {
					i = popups.length+1;
//					var tTitle = '<div class="popupClose"><img src="/images/buttons/popup_close.gif"></div>' + el.title;
					var tTitle = el.title;
					var dialog = new Element('div');
					var closeBox = new Element('div', {'class' : 'hand popupClose'} ).insert('[close]');
					Event.observe(closeBox, 'click',  function(event) { overlay.hide(); });
//					closeBox.observe('click', function() { CampMan.Confirm.hide(); });
					dialog.insert(closeBox);
					dialog.insert(new Element('div', {'class' : 'popupTitle'} ).insert(tTitle));
					dialog.insert(new Element('div', {'class' : 'popupText'} ).insert(el.txt));
					var overlay = new DialogOverlay(dialog);
					overlay.show();
				}
			}
		}
	}
}

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 (!XmlHttp) return false;
	if (runFunction) {
		XmlHttp.onreadystatechange = eval(runFunction);
		XmlHttp.open("GET", txtURL);
	}
	XmlHttp.send(null);
}

function nothingDone(){
}
function validateRadioButton(theFld) {
	found = false;
	var thCounter=0;
	if (!theFld.length) {
		if (theFld.checked) {
			found=true;
			thCounter = 99;
		}
	} else {
		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 manageDefaultFldTxt(ev, el, defTxt) {
 	switch(ev.type) {
	case 'focus': if (el.value==defTxt) el.value=''; break;
	case 'blur': if (!el.value) el.value=defTxt; break;
 	}
}

	//Disable right mouse click Script
	//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
	//For full source code, visit http://www.dynamicdrive.com

	/*
	var message="Samsāra Handbags, Clutches and Wallets For Women and Men.";
	
	///////////////////////////////////
	function clickIE4(){
		if (event.button==2){
			alert(message);
			return false;
		}
	}
	
	function clickNS4(e){
		if (document.layers||document.getElementById&&!document.all){
			if (e.which==2||e.which==3){
				alert(message);
				return false;
			}
		}
	}
	
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	}else if (document.all&&!document.getElementById){
		document.onmousedown=clickIE4;
	}
	
	document.oncontextmenu=new Function("alert(message);return false")
	*/


// X-Browser isArray(), including Safari
function isArray(obj)
{
  return obj.constructor == Array;
}

//mimic php empty function
function empty(obj)
{
	//check if the object is null, undefined, empty string, empty array or 0
	if(null==obj || "undefined"==obj || ""==obj || (isArray(obj) && 0==obj.length) || 0==obj)
	{
		return true;
	}

	return false;
}

/*
 * Pass the file name and file types as an array.
 * Returns false if the file type does not match.
 */
function validFileType(fileName, fileTypes)
{
	var fileNameString = new String(fileName);
	var fileExtension = fileNameString.split(".");
	var isValid = false;

	fileExtension = fileExtension[fileExtension.length-1];

	for(var i=0; i < fileTypes.length; i++)
	{	
		if(fileTypes[i] == fileExtension)
		{
			isValid = true;
			break;
		}
	}

	return isValid;
}

function clone(inObj)
{
    for (i in inObj)
    {
        this[i] = inObj[i];
    }
}
