/*
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Module:		Common.js
	Written:	May 2005
	Author:		Jeffrey Eyck
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Function:	Javascript utility routines used by all pages.  				
				
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
*/

//~~~~ Open Window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
	function OpenWindow(sURL, sName, iHeight, iWidth, iTop, iLeft, bToolBar, bMenu)
	{
		var sAttrib = "";
		sName = "";
		//set default height and width
		if (!iHeight)
			{iHeight = screen.availHeight;}
		if (!iWidth)
			{iWidth = screen.availWidth;}    		
		
		sAttrib = "height=" + iHeight.toString();		
		sAttrib += ",width=" + iWidth.toString(); 			
		
		if (!iLeft)
			{iLeft = (screen.availWidth - iWidth)/2;}
			
		sAttrib += ",left=" + iLeft.toString();  		
		
		if (!iTop)
			{iTop = (screen.availHeight - iHeight)/2;}			
			
		 sAttrib += ",top=" + iTop.toString();
			
		if (!bToolBar)
			{
			if (sAttrib != ""){sAttrib += ",";}
			sAttrib += "toolbar=0";
			}
			
		if (sAttrib != ""){sAttrib += ",";}	
		
		if (!bMenu)
			{			
			sAttrib += "menubar=0";
			} 
		else
			{
			 sAttrib += "menubar=1";
			}			
		 			
		
		sAttrib += ",scrollbars=1,resizable=1";	
		
		window.open(sURL, sName, sAttrib);
	}
	
//~~~~ Show Popup Window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function ShowPopupWindow(sPage, sName) {
		var oDialogData  = new Object();
		var sFeatures = "resizable:no;scrollbars:no;status:no;dialogHeight:420px;dialogWidth:592px;";
		var sReturnValue ="";		
								
		oDialogData.URL = sPage;
		oDialogData.title = sName;
				
		sReturnValue = window.showModalDialog("../Main/Popup.aspx",oDialogData,sFeatures);
	}
	
//~~~~ Reload Frame ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	function ReloadFrame(oFrame, sURL)
	{
		oFrame.location.href = sURL;	
	}
	
//~~~~ Reload Window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function ReloadWindow(oWindow, sURL)
	{
		oWindow.location.href = sURL;	
	}
	
//~~~~ Reload Adjacent Frame ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function ReloadAdjacentFrame(sFrameName, sURL)
	{
	
	try
		{
		window.parent.frames[sFrameName].location.href = sURL;
		}
	catch(e)
		{
		alert("The requested frame " + sFrameName + " could not be found.");
		}				
	}
	
//~~~~ Open Product In A Frame ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function OpenProductInFrame(psPageToOpen)
	{
		window.parent.frames['BoardsFrame'].location.href = psPageToOpen
	}
	
/**********************************
 function ShowProgress()
	displays a progress bar, as defined in the file ../common/ProgressBar.htm
***********************************/
	
function ShowProgress(sText)
{		
	document.all["ProgressText"].innerText = sText;
	ProgressBar.fgColor = "silver";		
	ProgressBar.style.zIndex = 50000;
	ProgressBar.style.display = "block";						
}
		
function HideProgress()
{		
	ProgressBar.style.display = "none";		
}

function ValidateEmail(pEmail)
{
	//Now ensure the email is valid 
	if ((pEmail.value.indexOf('@') < 1) ||                     								// '@' cannot be in first position
	    (pEmail.value.lastIndexOf('.') <= pEmail.value.indexOf('@')+1) ||     // Must be at least one valid char btwn '@' and '.'
	    (pEmail.value.lastIndexOf('.') == pEmail.value.length - 1 ) ||        // Must be at least one valid char after '.'
	    (pEmail.value.indexOf(' ') != -1))                    								// No empty spaces permitted
	{
		return false;
	}
	else{
		return true;
	}	
}

//--------------------------------------------------------	
function OpenGRDesign()
{
	var oDialogData = new Object();
	var sFeatures = "resizable:no;scrollbars:no;center:yes;status:no;help:no;dialogHeight:375px;dialogWidth:506px;";
	var sReturnValue = new String("");
	
	oDialogData.URL = "../Common/GRDesign.aspx";
	oDialogData.title = "GunRider Designs - Websites for small business"
	
	sReturnValue = window.showModalDialog("../Common/GenericModalDialog.aspx",oDialogData,sFeatures);
	
	if (sReturnValue=="REFRESH") {
	}
	window.status = "";
}			

		
function popImage(imageURL,imageTitle)
{
// Set the horizontal and vertical position for the popup

var PositionX = 100;
var PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

var defaultWidth  = 500;
var defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=yes,width=150,height=100,left='+PositionX+',top='+PositionY;

	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		//IE code
		writeln('if (isIE){');
		writeln('window.resizeTo(300,300);');
		writeln('width=300-(document.body.clientWidth-document.images[0].width);');
		writeln('height=300-(document.body.clientHeight-document.images[0].height);');
		
		writeln('if(height>600){height=635;');
		writeln('document.images[0].height=600;');
		writeln('width=document.images[0].width + 10;');
		
		writeln('if(width>document.images[0].width)');
		writeln('{');
		writeln('document.images[0].width=width;');
		writeln('}');
		
		writeln('if(document.images[0].width>600){width=700;');
		writeln('document.images[0].width=700;}}');
		//writeln('}');
		
		writeln('window.resizeTo(width,height);}');
		
		//Netscape code
		writeln('if (isNN){'); 
		writeln('width=document.images["pop"].width;');
		writeln('height=document.images["pop"].height;');
		writeln('if(height>600){height=600;');
		writeln('document.images["pop"].height=600;');
		writeln('if(width>600){width=700;');
		writeln('document.images["pop"].width=700;}}');
		writeln('window.innerWidth=document.images["pop"].width;');writeln('window.innerHeight=document.images["pop"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		
	if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
	
	writeln('<img name="pop" src='+imageURL+' style="display:block"></body></html>');
	close();		}
}

function loadlink(pName) {
	var load = window.open(pName,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
}

