/*
	CommonFunctions.js
	----------------------------------------------------------
	A place for any function that is used on more than 1 page,
	and any constants needed for JavaScripts. 
*/


/* ------------------------------
JavaScript constants
------------------------------ */

function formatCurrency(num,printDollarSign) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	{
		num = "0";
	}
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
	if(cents<10)
	{
		cents = "0" + cents;
	}
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
    
    num.substring(num.length-(4*i+3));
	if ( printDollarSign )
	{
		return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
	else
		return (((sign)?'':'-') + num + '.' + cents);
}


function setTodaysDate(textBoxToPopulate)
{
	if ( textBoxToPopulate ) 
	{
		var ut=new Date();
		var dateString=(ut.getMonth()+1)+'/'+ut.getDate()+'/'+ut.getFullYear()

		textBoxToPopulate.value=dateString;
	}
}
function OpenPageInNewWindow(PageName, Height, Width, PrintToolBar, scroll)
{
	window.open(PageName, '_blank', 'width='+Width+', height='+Height+', status=no,toolbar='+PrintToolBar+',menubar=no,location=no,scrollbars='+scroll);
}

// Purpose: KMN's attempt to eliminate the flickering of the screen
function OpenWindowCentered(URLToOpen, nWidth, nHeight, PrintToolBar)
{
	var lLeft = (screen.width/2)-(nWidth/2);
	var lTop = ((screen.height/2)-(nHeight/2))-25;
	
	window.open(URLToOpen, 'modifyWindow', 'fullscreen=no,toolbar='+PrintToolBar+',status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width='+nWidth+',height='+nHeight+',top='+lTop+',left='+lLeft);
}

function collapser(elName, imgName) 
{
	var dsplStat = elName.style.display;
	var imgName;
	
	if (dsplStat == 'none') 
	{
		imgName.src = 'http://www.AGAdjusting.net/Images/MenuMinus.gif';
		elName.style.display = 'block';
	} 
	else 
	{
		imgName.src = 'http://www.AGAdjusting.net/Images/MenuPlus.gif';
		elName.style.display = 'none';
	}
}


// FUNCTION DisplayPropertyNames(object)
// Purpose:	Display all of the properties of this object in an alert box.
//			Used only at dev time.  Should need to use anymore when we 
//			are able to do client side debugging of JavaScript.
function DisplayPropertyNames(obj)
{
	var names="";
	for(var name in obj) names += name + '- -';
			alert(names);
}


function OpenPrintableInNewWindow(printableID, secondBilling, invoiceNumber)
{	
	OpenWindowCentered('http://www.AGAdjusting.net/remote/Printables/default.asp?printableID='+printableID+'&secondBilling='+secondBilling+'&invNumber='+invoiceNumber, 700, 500, 'no', 'yes');	
}

function OpenPrintableInNewWindow2(printableID, secondBilling, invoiceNumber, queryString)
{	
	OpenWindowCentered('http://www.AGAdjusting.net/remote/Printables/default.asp?printableID='+printableID+'&secondBilling='+secondBilling+'&invNumber='+invoiceNumber+queryString, 700, 500, 'no', 'yes');	
}

function showCalander(inputBox)
{
	alert (inputBox.name);
	// show the calander

}

function LaunchModifyInsRep(invNumber, InsCoI, invoiceType, currentRepI)
{
	OpenWindowCentered('http://www.AGAdjusting.net/remote/modifyInsuranceRep.asp?pg=modIRForm&invNumber='+invNumber+'&InsCoI='+InsCoI+'&invoiceType='+invoiceType+'&currentRepI='+currentRepI, 500, 250, 'no', 'yes');
}

function LaunchModifyAGAAdjuster(invNumber, currentAGAAdjusterI, invoiceType)
{
	OpenWindowCentered('http://www.AGAdjusting.net/remote/modifyAGAAdjuster.asp?pg=modAGAAdjForm&invNumber='+invNumber+'&currentAGAAdjusterI='+currentAGAAdjusterI+'&invoiceType='+invoiceType, 500, 250, 'no', 'yes');
}

function BGChange(color, rowToChange, cursorType, invNumber)
{
	rowToChange.bgColor=color;
	// DisplayPropertyNames(rowToChange);
	rowToChange.style.cursor=cursorType;
	rowToChange.title='invoice '+invNumber;
	//alert(rowToChange.style.cursor);
	
}
