//Standard fuctions JavaScript file

//	If the user right clicks anywhere on the page, a Copyright message will appear.

//	Change this variable (between the quotes) to change the message that is displayed to the user.
var CopyrightMessage="This page is copyrighted by\nConstruction Resource Inc."; 

//	Capture the mouse click event and then find out which mouse button was pressed.
function DisableRightClick()
{
	if (document.layers) 
	{
		document.captureEvents(Event.MOUSEDOWN);
	}
	document.onmousedown=click;
}

function click(e) 
{
	if (document.all) 
	{
		if (event.button == 2) 
		{
			alert(CopyrightMessage);
			return false;
		}
	}
	if (document.layers) 
	{
		if (e.which == 3) 
		{
			alert(CopyrightMessage);
			return false;
		}
	}
}

//	Set the focus to a specified field on the page.
function Set_Focus(formField)
{
	document.getElementById(formField).focus();
}

//	Closes a browser window without asking for confirmation.
function Close_Window()
{
	if (document.all)
	{
		window.opener='';
		window.close();
	}
	else
	{
		window.close();
	}
}

//	Generic function for creating a popup window.
//	There are several arguments that can be passed into this:
//	Passed_URL = url that you want to display in the popup window
//	Width = width (in pixels) of the popup window.  Since the optimized resolution is 1024x768, this value should be less than 1024.
//	Height = height (in pixels) of the popup window.  Since the optimized resolution is 1024x768, this value should be less than 768.
//	Left = the position of the window (in pixels) relative to the left side of the screen.
//	Top = the position of the window (in pixels) realteive to the top of the screen.
//	Resizable = if yes, the window can be resized.  If no, the window size will be locked.
//	Scrollbars = if yes, scrollbars will appear when need (the resolution is below 1024x768).  If no, scrollbars will never appear.
function Pop_Window(Passed_URL, width, height, left, top, resizable, scrollbars)
{
    var Window_Width = width;
    var Window_Height = height;
    var Window_Left = left;
    var Window_Top = top;
    var Window_Scrollbars = scrollbars;
    var Window_Resizable = resizable;
	var URL = Passed_URL;
    var Window_String = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=" + Window_Scrollbars + ",status=no,copyhistory=no,resizable=" + Window_Resizable + ",width="+Window_Width+";,height="+Window_Height+",left="+Window_Left+",top="+Window_Top;
	
 	// this will generate a random name for the pop up window.  Otherwise, popup windows will overwrite other popups.
    var Now = new Date();
    var GenericWindowName = "Window_" + (Now.getHours()).toString() + (Now.getMinutes()).toString() + (Now.getSeconds()).toString();
    
    msgWindow = open(URL, GenericWindowName, Window_String);
    msgWindow.opener = window;
    msgWindow.focus();
}

//	Function to show the Privacy Policy.  It is passed the same parameters as the popup window function.
function ShowPrivacy(PASSED_URL, Width, Height, Left, Top, Resizable, Scrollbars)
{
	var Window_Width = 965;
    var Window_Height = 670;
    var Window_Left = 30;
    var Window_Top = 15;
    var Target_Width = Width;
    var Target_Height = Height;
	var Target_Left = Left;
	var Target_Top = Top;
	var Target_Resizable = Resizable;
	var Target_Scrollbars = Scrollbars;
	var URL = PASSED_URL;
	var PRIVACY_URL = "http://www.crinc.org/privacy_popup.htm";
	var Window_String;
   	var Now = new Date();
   	var RandomWindowName = "Window_" + (Now.getHours()).toString() + (Now.getMinutes()).toString() + (Now.getSeconds()).toString();

	if (document.all)
	{
		//IE browser detected
        Window_String = "dialogLeft: " + Window_Left + "px; dialogTop: " + Window_Top + "px; dialogWidth:" + Window_Width + "px; dialogHeight:" + Window_Height + "px; help: no; scroll: yes; status: no; edge: sunken; unadorned: no";
 		window.showModalDialog(PRIVACY_URL + "?link=" + PASSED_URL + "&height=" + Target_Height + "&width=" + Target_Width + "&=left" + Target_Left + "&top=" + Target_Top + "&resizable=" + Target_Resizable + "&scrollbars=" + Target_Scrollbars, RandomWindowName, Window_String);
	}
	else
	{
		//Netscape browser detected
    	Window_String = "toolbar=no,modal=yes,location=no,directories=no,menubar=no,scrollbars=yes,status=no,copyhistory=no,resizable=no,width="+Window_Width+";height="+Window_Height+",left="+Window_Left+",top="+Window_Top;
	    window.open(PRIVACY_URL + "?link=" + PASSED_URL + "&height=" + Target_Height + "&width=" + Target_Width + "&=left" + Target_Left + "&top=" + Target_Top + "&resizable=" + Target_Resizable + "&scrollbars=" + Target_Scrollbars, RandomWindowName, Window_String);
	}
}

//	Used for the privacy policy.  The SetupQueryString will create two array used to store the query string values.
function SetupQueryString()
{
	QueryString.keys = new Array();
	QueryString.values = new Array();
}

//	Assigns variables to the query string values.
function OpenQueryString()
{
	QueryString_Parse();
	var link = QueryString("link");
	var width = QueryString("width");
	var height = QueryString("height");
	var left = QueryString("top");
	var top = QueryString("left");
	var resizable = QueryString("resizable");
	var scrollbars = QueryString("scrollbars");
	Pop_Window(link, width, height, left, top, resizable, scrollbars);
	Close_Window();
}

function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}
}

//function makeHiddenFrame() 
//{
//	var parentlocation = parent.location.href;
//	alert(parentlocation);
//	ifrm = document.createElement("IFRAME");
//	ifrm.setAttribute("src", "/test.asp");
//	ifrm.style.width = 640+"px";
//	ifrm.style.height = 480+"px";
//	document.body.appendChild(ifrm);
//}