
// Detect if browser is Netscape 3 + or IE 4 +.
function detectBrowser()
{
	var retValue = '';
	var bName = navigator.appName;
	//var bVer = parseInt(navigator.appVersion);
    if (bName == "Netscape")
    {
    	return ('NS');
    }
    else if (bName == "Microsoft Internet Explorer")
    {
    	return ('IE');
    }
    else
    {
    	return ('null');
    }
}

function detectBrowserVersion()
{

	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4)
	{
    	return ("IE4+");
	}

	if ( (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 && parseInt(navigator.appVersion) < 5))
	{
	    return ("NS4+");
	}

	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5)
	{
	    return("NS5+");
	}

}


function setCookieSession(session_id, session_val)
{
	document.cookie = session_id + "=" + session_val;
}


function printOut(textToPrint)
{
	document.write(textToPrint);
}

function getCookieSession(session_id)
{
	var sessionParam = session_id + "="
	var allCookies = document.cookie;
	var pos = allCookies.indexOf(sessionParam);
	if (pos != -1)
	{
		var start = pos + sessionParam.length;
		var end = allCookies.indexOf(";", start);
		if (end == -1)
		{
			end = allCookies.length;
		}
		var cookieValue = allCookies.substring(start,end);
		return (cookieValue);
	}
	return ("null");
}

function isValidUser()
{
	var isLoggedIn = getCookieSession("isLoggedIn");
	if (isLoggedIn != 'true')
	{
		window.location.href = "asm_invalidAccess.html";
	}
}

function getQueryStringArgs()
{
	//The limitation with using an object to store the qString arguments
	//is that you cannot have multiple arguments with the same name. no
	//collection functionality
	var args = new Object();

	var query = location.search.substring(1); //get query string
	//alert("queryString = " + query);
	var pairs = query.split("&");

	for(var i = 0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');  //Look for name=value pair
		if (pos != -1)					  //if not found then skip and go to the next one
		{
			var argName 	= pairs[i].substring(0,pos);  //Extract the name
			var argValue 	= pairs[i].substring(pos + 1); //Extract the value
			args[argName] 	= unescape(argValue);		 //Stort as a property.
		}

	}
	return args;  //return the object
}




function openDialog(url,name,height,width,edge,center,help,resizable,status)
{
	var netscape = (navigator.appName.indexOf('Netscape') >= 0) ? 1 : 0;
	var iexplorer = (document.all) ? 1 : 0;
	var features = '';
	var top = 0;
	var left = 0;

	if ( netscape == 1 ) {
		if ( height < screen.availHeight ) 	{
			top = Math.round( ( screen.availHeight - height ) / 2 );
			}
		if ( width < screen.availWidth )	{
			left = Math.round( ( screen.availWidth - width ) / 2 );
			}
		features = 'height=' + height + ',width=' + width + ',screenY=' + top + ',screenX=' + left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location + ',alwaysRaised=' + alwaysraised + ',dependent=' + dependent;
	}
	else if ( iexplorer == 1 )	{
		if ( height < screen.height )	{
			top = Math.round( ( screen.height - height ) / 2 );
			}
		if ( width < screen.width )		{
			left = Math.round( ( screen.width - width ) / 2 );
			}		
		features = 'dialogHeight: ' + height + 'px; dialogWidth: ' + width + 'px; dialogTop: ' + top + 'px; dialogLeft=' + left + 'px; edge: sunken; center: Yes; help: No; resizable: No; status: No; unadorned: Yes;';
	}
	return (window.showModalDialog(url,name,features));
}


function openWindow(url,name,height,width,toolbar,location,status,menubar,scrollbars,resizable,alwaysraised,dependent)
 {
	/* The following features are available in most browsers: toolbar=0|1  Specifies whether to display the toolbar in the new window.  
	location=0|1  Specifies whether to display the address line in the new window.  
	directories=0|1  Specifies whether to display the Netscape directory buttons.  
	status=0|1  Specifies whether to display the browser status bar.  
	menubar=0|1  Specifies whether to display the browser menu bar.  
	scrollbars=0|1  Specifies whether the new window should have scrollbars.  
	resizable=0|1  Specifies whether the new window is resizable.  
	width=pixels  Specifies the width of the new window.  
	height=pixels  Specifies the height of the new window.  
	top=pixels  Specifies the Y coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)  
	left=pixels  Specifies the X coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)  
	*/
	
	var netscape = (navigator.appName.indexOf('Netscape') >= 0) ? 1 : 0;
	var iexplorer = (document.all) ? 1 : 0;
	var features = '';
	var top = 0;
	var left = 0;

	if ( netscape == 1 ) {
		if ( height < screen.availHeight ) 	{
			top = Math.round( ( screen.availHeight - height ) / 2 );
			}
		if ( width < screen.availWidth )	{
			left = Math.round( ( screen.availWidth - width ) / 2 );
			}
		features = 'height=' + height + ',width=' + width + ',screenY=' + top + ',screenX=' + left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location + ',alwaysRaised=' + alwaysraised + ',dependent=' + dependent;
	}
	else if ( iexplorer == 1 )	{
		if ( height < screen.height )	{
			top = Math.round( ( screen.height - height ) / 2 );
			}
		if ( width < screen.width )		{
			left = Math.round( ( screen.width - width ) / 2 );
			}
		if (scrollbars==1) { scrollbars = "auto"; }
		features = 'height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location;
	}
	return open(url,name,features);
}

// Open window with Privacy Policy
function openPrivacy() {
	var tmpState = openWindow("privacy_policy.asp","Privacy",600,600,1,0,1,1,"yes",1,0,1)
}

// Modification made to page show div
function modMade() {
    document.getElementById('FormModifiedDiv').style.visibility = "visible";
	return true;
}

// Format currency out of number
function formatCurrency(num) {
	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 ));
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

//check if this is a valid date
function isValidDate(dateexp)
{
	var matchArr = dateexp.match(/^[0-9]{2}\/+[0-9]{2}\/+[0-9]{4}$/i);
	if (matchArr == null){
		return false;
	}
	else{
		return true;
	}
}

//check if this is a valid number
function isValidNumber(vNum)
{
	var matchArr = vNum.match(/^\d+$/i);
	if (matchArr == null){
		return false;
	}
	else{
		return true;
	}
}

function isValidCurrency(vCur)
{
	var matchArr = vCur.match(/^\d+(\.\d{2})?$/i);
	if (matchArr == null){
		return false;
	}
	else{
		return true;
	}
}

// get current year
function getCurrentYear()
{
	var d = new Date();
	return (d.getFullYear());
}
