/* 
Global External JavaScript Functions 
Version 0.9
Copyright (c) 2006 Data Partners, Inc. All Rights Reserved.
*/

function MM_swapImgRestore() 
{ //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ //v3.0
	var d=document; 
	
	if(d.DebtRecovery/images)
	{ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		
		for(i=0; i<a.length; i++)
		{
			if (a[i].indexOf("#")!=0)
			{ 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

function MM_findObj(n, d) 
{ //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() 
{ //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; 
	
	document.MM_sr=new Array; 
	
	for(i=0;i<(a.length-2);i+=3)
	{
		if ((x=MM_findObj(a[i]))!=null)
		{
			document.MM_sr[j++]=x; 
			
			if(!x.oSrc) 
				x.oSrc=x.src; 
			
			x.src=a[i+2];
		}
	}
}

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function toggleAdminMenu()
{
	toggleLayer('SubMenu');
}

//******************************************************************************
// Purpose:  
//			 
//			 
// Receives: 
//			 
//			 
// Returns:  
//			 
//			 
// Remarks:  
//			 
//			 
//******************************************************************************
function checkValues(source, arguments) 
{
	var ctrlid = source.controltovalidate;
	var ctrl2chk = document.getElementById(ctrlid);
	var val2chk = ctrl2chk.value;
	var i = 1;

	while (i < 31) 
	{
		var currElem = "txtGeoData"+i;
		var meCtrl = document.getElementById(currElem);
		var meCtrlID = meCtrl.id;
		if (meCtrlID != ctrlid && val2chk == meCtrl.value) 
		{
			//alert("You got a duplicate value! The duplicate value is: " + meCtrl.value);
			arguments.IsValid = false;
			return false;
		}
		i++;
	}
	arguments.IsValid = true;
}

//******************************************************************************
// Purpose:  Takes a number and returns it with commas.
//			 
// Receives: A string representation of a number.
//			 
// Returns:  The string representation of the number with commans.
//******************************************************************************
function addCommasToNumber(stringNumber)
{
	stringNumber += '';
	x = stringNumber.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

//******************************************************************************
// Purpose:  Automatically tabs to the destination control 
//			 when the length of the input reaches its maxlength.
//			 
// Receives: 
//			 
//			 
// Returns: 
//			 
//			 
// Remarks: 
//			 
//			 
//******************************************************************************
function autotab(original,destination)
{
	if (original.getAttribute && original.value.length == original.getAttribute("maxlength"))
	{
		if (destination)
		{
			destination.focus();
		}
	}
}

//******************************************************************************
// Purpose:  Returns false if the user entered a keyboard value that is not a number.
//			 
//			 
// Receives: 
//			 
//			 
// Returns:  
//			 
//			 
// Remarks:  
//			 
//			 
//******************************************************************************
function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
		
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))  
		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
		return false;
}

//******************************************************************************
// Purpose:  Checks the textboxes on the zip codes and area codes page to make
//			 sure there are no duplicates in the other textboxes.
//			 
// Receives: The textbox to check the duplicate value for. 
//			 Any arguments to pass in.
//			 
// Returns:  false if any duplicates are found, otherwise true.
//			 
//******************************************************************************
function chk4dupes(source, arguments) 
{
	var ctrlid = source.controltovalidate;
	var ctrl2chk = document.getElementById(ctrlid);
	var val2chk = ctrl2chk.value;
	var i = 1;

	while (i < 31) 
	{
		var currElem = "txtGeoData"+i;
		var meCtrl = document.getElementById(currElem);
		var meCtrlID = meCtrl.id;
		if (meCtrlID != ctrlid && val2chk == meCtrl.value) 
		{
			//alert("You got a duplicate value! The duplicate value is: " + meCtrl.value);
			arguments.IsValid = false;
			return false;
		}
		i++;
	}
	arguments.IsValid = true;
}

//
// Displays a popup window specified by the URL that's centered.
//
function popUp(URL, w, h) 
{
	//var w = 500;
	//var h = 500;
	
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	windowprops = 
		"height=" + h + 
		",width=" + w + 
		",top=" + wint + 
		",left=" + winl + 
		",location=no," + 
		"scrollbars=yes," + 
		"menubars=no," + 
		"toolbars=no," + 
		"resizable=no," + 
		"status=yes";
	
	window.open(URL, "Popup", windowprops);
}

//
// Change the CSS class based on a previous class name.
//
function ChangeColor(item) 
{ 
	if (item.className == "ButtonWebNormal")
	{
		item.className = "ButtonWebHover"
	}

	if (item.className == "ButtonMenuNormalBIG")
	{
		item.className = "ButtonMenuHoverBIG"
	}

	if (item.className == "ButtonMenuNormalMedium")
	{
		item.className = "ButtonMenuHoverMedium"
	}

	if (item.className == "ButtonMenuNormalSmall")
	{
		item.className = "ButtonMenuHoverSmall"
	}

	return true; 
} 

//
// Return the class name to it's original value.
//
function ReturnColor(item) 
{
	if (item.className == "ButtonMenuHoverBIG")
	{
		item.className = "ButtonMenuNormalBIG"
	}

	if (item.className == "ButtonMenuHoverMedium")
	{
		item.className = "ButtonMenuNormalMedium"
	}

	if (item.className == "ButtonMenuHoverSmall")
	{
		item.className = "ButtonMenuNormalSmall"
	}

	if (item.className == "ButtonWebHover")
	{
		item.className = "ButtonWebNormal"
	}
	
	return true; 
}

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
		
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))  
		return true;
	else if ((("0123456789").indexOf(keychar) > -1)) // numbers
		return true;
	else
		return false;
}

