
if (typeof(gE)=='undefined')
{
	function gE(eID) {
		return document.getElementById(eID);
	}
}

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 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;
}
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

/*

Copyright (C) 2001 John Weir www.smokinggun.com

This code is free for use.  If possible include the copyright.

*/

if (typeof(swapNode)!='function') {
	function swapNode(objA,objB)
	{
	if (objA != null && objB != null)
		{
		tempObjB = objB.cloneNode(true);
		tempObjA = objA.cloneNode(true);
	
		objB.parentNode.insertBefore(tempObjA,objB);
		objA.parentNode.insertBefore(tempObjB,objA);
	
		objA.parentNode.removeChild(objA);
		objB.parentNode.removeChild(objB);
		
		return tempObjA;
		}
	
	//else handle error
	}
}

function getPosition(e) {
     e = e || window.event;
     var cursor = {x:0, y:0};
     if (e.pageX || e.pageY) {
         cursor.x = e.pageX;
         cursor.y = e.pageY;
     }
     else {
         cursor.x = e.clientX +
             (document.documentElement.scrollLeft ||
             document.body.scrollLeft) -
             document.documentElement.clientLeft;
         cursor.y = e.clientY +
             (document.documentElement.scrollTop ||
             document.body.scrollTop) -
             document.documentElement.clientTop;
     }
     return cursor;
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

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 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 validateExpressCheckout(theForm) {
	if (Summit.Form.ValidateForm(theForm)) {
		send(AJAXPATH + '?' + $(theForm.id).serialize(), 'validateExpressCheckoutResponse');
	}
	return false;
}
function validateExpressCheckoutResponse() {
	if (XmlHttp.readyState==4){
		result = XmlHttp.responseText;
		XmlHttp=null;
		if (result==2) {
			$('expressCheckoutFrm_emailExist').show();
		} else if (result==1) {
			var email = '';
			if (document.forms['expressCheckoutFrm'])
				if (document.forms['expressCheckoutFrm']['EMail'])
					if (document.forms['expressCheckoutFrm']['EMail'].value)
						email = document.forms['expressCheckoutFrm']['EMail'].value;
			if (email)
				window.location='/actions.php?do=continueWithoutLogin&email=' + email;
			else
				alert('Error processing the request.');
		} else {
			alert('Error processing the request.');
		}
		return false;
	}
}
function validateMembersCheckout(theForm) {
	if (Summit.Form.ValidateForm(theForm)) {
		send(AJAXPATH + '?' + $(theForm.id).serialize(), 'validateMembersCheckoutResponse');
	}
	return false;
}
function validateMembersCheckoutResponse() {
	if (XmlHttp.readyState==4){
		result = XmlHttp.responseText;
		XmlHttp=null;
		if (result>0) {
			window.location='/actions.php?do=validateMemberCheckout&EMail=' + document.forms['membersCheckoutFrm']['EMail'].value + '&c=' + result;
		} else {
			$('membersCheckoutFrm_userNotFound').show();
		}
		return false;
	}
}

function validateCCnumber(el) {
	if (!el) return false;
	if (!$('CC_typeNumIcon')) return false;
	var num = el.value;
	var setClass = 'CC_typeUnknown';
	if (!num.length) setClass = 'CC_typeNo';
	var setCCtype = '';
	if (((num.substring(0, 2)==34) || (num.substring(0, 2)==37)) && ((num.length==15))) {
		setClass = 'CC_typeAM';
		setCCtype = 'AM';
	} else if (((num.substring(0, 2)==55) || (num.substring(0, 2)==54) || (num.substring(0, 2)==53) || (num.substring(0, 2)==52) || (num.substring(0, 2)==51)) && ((num.length==19) || (num.length==16))) {
		setClass = 'CC_typeMC';
		setCCtype = 'MC';
	} else if (((num.substring(0, 1)==4)) && ((num.length==13) || (num.length==16))) {
		setClass = 'CC_typeVI';
		setCCtype = 'VI';
	}
	if (setCCtype) {
		if (!Summit.Form.ValidateCC(num)) {
			setClass = 'CC_typeUnknown';
			setCCtype = '';
		}
	}
	$('CC_typeNumIcon').className = setClass;
	if (el.form)
		if (el.form['CC_type'])
			el.form['CC_type'].value = setCCtype;
}
