
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function popup(url, height, width)
{
	var dimensions = "location=1,status=1,scrollbars=1,resizable=1,width=" + width + ",height=" + height
	window.open(url,"popwindow",dimensions); 
}

function isValidText(fieldId,fieldName) {	
	var f = document.getElementById(fieldId);
	if (!f || !f.value) { return true; }
	var str = f.value.match(/\<.*\>/g);
	if (!str || str.length == 0) {
		return true;
	}
	alert('No HTML is allowed in '+fieldName+'.');
	return false;
}

function ReplaceImage(sImgName,sImgFile)
{ 
	document.images[sImgName].src = sImgFile; 
} 

function toggleCVVHint(hintId, typeId)
{
	var d = document.getElementById(hintId);
	if (d && d != null && d != 'undefined')
	{
		d.style.display = (d.style.display == '' ? 'none' : '');
		if (d.style.display == 'none') { return; }
	}
	d = document.getElementById(typeId);
	if (d && d != null && d != 'undefined')
	{
		var t = d.value;
		d = document.getElementById('imgCvv');
		if (d && d != null && d != 'undefined')
		{
			switch (t)
			{
				case '3':
					d.src = '/images/amex-cvv2.gif';
					break;
				default:
					d.src = '/images/visa-cvv2.gif';
					break;
			}
		}
	}
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); }

function copyPrototype(descendant, parent)
{
	var sConstructor = parent.toString();
	var aMatch = sConstructor.match(/\s*function (.*)\(/);
	if (aMatch != null) { descendant.prototype[aMatch[1]] = parent; }
	for (var m in parent.prototype)
	{
		descendant.prototype[m] = parent.prototype[m];
	}
}

function enableOnlyEnterKey(e)
{	
	var key = getKeyCode(e);
	return (key == 0x0d);
}

function getKeyCode(e)
{
	if (window.event) { return window.event.keyCode; }
	return e.which;
}

function getTargetElement(e)
{
	var el;
	if (window.event) { el = window.event.srcElement; }
	else { el = e.target; }
	if (!el || el == 'undefined') { el = null; }
	return el;
}

function disableEnterKey(e)
{
	var key = getKeyCode(e);
	return (key != 13);
}

function allowNumbersOnly(e)
{
	var key = getKeyCode(e);
	if (key >= 0x30 && key <= 0x39) { return true; }
	switch (key)
	{
		case 0x08: case 0x00:
			return true;
	}
	return false;
}

function allowCurrencyOnly(e)
{
	var key = getKeyCode(e);
	var el = getTargetElement(e);
	var v = null;
	if (el != null)
	{
		v = el.value;
		if (!v || v == 'undefined') { v = null; }
	}
	if (key >= 0x30 && key <= 0x39) { return true; }
	switch (key)
	{
		case 0xbe: case 0x08: case 0x00:
			return true;
		case 0x2e: 
			if (v == null) { return true; }
			return v.indexOf('.') == -1;
	}
	return false;
}

document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}

function showAjaxLoader()
{
	$('page-gray-out').style.display = 'block';
}

function hideAjaxLoader()
{
	$('page-gray-out').style.display = 'none';
}

function getRefToDivMod(divID) 
{
	oDoc = document; 
  	if(document.layers) 
	{
	    	if (oDoc.layers[divID]) { return oDoc.layers[divID]; } 
		else 
		{
			for(var x = 0, y; !y && x < oDoc.layers.length; x++) 
			{
			        y = getRefToDivMod(divID, oDoc.layers[x].document); 
			}
			return y; 
		} 
	}
	if (document.getElementById) { return oDoc.getElementById(divID); }
  	if (document.all) { return oDoc.all[divID]; }
	return document[divID];
}

function openPerfectPopup(oW) 
{
	var x = window;
	if (!x) { return true; }
	var oH = getRefToDivMod('container', x.document); 
	if (!oH) { return false; }
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight; 
	if (!oH) { return false; }
	x.resizeTo(oW + 200, oH + 200);
  	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
	if (x.innerWidth) { myW = x.innerWidth; myH = x.innerHeight; }
	else if (d && d.clientWidth) { myW = d.clientWidth; myH = d.clientHeight; }
	else if (b && b.clientWidth) { myW = b.clientWidth; myH = b.clientHeight; }
	if (window.opera && !document.childNodes) { myW += 16; }
	//x.resizeTo(oW + ((oW + 200) - myW), oH + ((oH + 200) - myH));
	x.resizeTo(oW = oW + ((oW + 200) - myW), oH = oH + ((oH + 200) - myH));
	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	x.moveTo(Math.round((scW - oW) / 2), Math.round((scH - oH) / 2));
	if (x.focus) { x.focus(); }
	return false;
}

function openPerfectPopupX(divId)
{
	var x = window;
	if (!x) { return true; }
	var oH = getRefToDivMod(divId, x.document); 
	if (!oH) { return false; }
	var oW = oH.clip ? oH.clip.width : oH.offsetWidth; 
	if (!oW) { return false; }
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight; 
	if (!oH) { return false; }
	x.resizeTo(oW + 200, oH + 200);
  	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
	if (x.innerWidth) { myW = x.innerWidth; myH = x.innerHeight; }
	else if (d && d.clientWidth) { myW = d.clientWidth; myH = d.clientHeight; }
	else if (b && b.clientWidth) { myW = b.clientWidth; myH = b.clientHeight; }
	if (window.opera && !document.childNodes) { myW += 16; }
	//x.resizeTo(oW + ((oW + 200) - myW), oH + ((oH + 200) - myH));
	x.resizeTo(oW = oW + ((oW + 200) - myW), oH = oH + ((oH + 200) - myH));
	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	x.moveTo(Math.round((scW - oW) / 2), Math.round((scH - oH) / 2));
	if (x.focus) { x.focus(); }
	return false;
}
