/* 
Global External JavaScript Functions 
Version 0.9
Copyright (c) 2005 Data Partners, Inc. All Rights Reserved.
*/
//Generating Pop-up Print Preview page
function getPrint(print_area, w, h)
{	
	//debugger;

	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";
	
	// Creating new page
	var pp = window.open(null, "Popup", windowprops);
	
	//Adding HTML opening tag with <HEAD> … </HEAD> portion 
	pp.document.writeln('<HTML><HEAD><TITLE>BrandNewMovers.com</TITLE><LINK href=Styles/main.css  type="text/css" rel="stylesheet">')
	pp.document.writeln('<LINK href=Styles/PrintStyle.css  type="text/css" rel="stylesheet" media="print"><base target="_self"></HEAD>')
	
	//Adding BODY Tag
	pp.document.writeln('<BODY bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">');
	
	//Adding FORM Tag
	pp.document.writeln('<FORM  method="post">');
	
	//Creating two buttons Print and Close within a table
	pp.document.writeln('<DIV class="AlignElementCenter"><TABLE width=100%><TR><TD></TD></TR><TR><TD align=center><INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();" width="100px" class="ButtonWebNormal"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();" width="100px" class="ButtonWebNormal"></TD></TR><TR><TD></TD></TR></TABLE>');
	
	var html = document.getElementById(print_area).innerHTML.replace('PageBorder','PageBorderPrint');
	
	pp.document.writeln(html);
	
	//Ending Tag of </FORM>, </BODY>, and </HTML>
	pp.document.writeln('</DIV></FORM></BODY></HTML>');
}		

function printReport(print_area, w, h)
{	
	//debugger;

	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";
	
	// Creating new page
	var pp = window.open('PrintReport.htm', "_blank", windowprops);
	
	var html = document.getElementById(print_area).innerHTML.replace('PageBorder','PageBorderPrint');
	
	//debugger;
	
	if (pp.document.getElementById('PRINT_DIV'))
	{
		pp.document.getElementById('PRINT_DIV').innerHTML = "<IMG src=\"Images/report_logo.jpg\">" + html;
	}
}

//******************************************************************************
// 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;
}


