/*------------------------------------------------------------------------------
List of functions:

		 fnPopup(mypage,myname,w,h,pos,infocus)
		 fnLinkPopup(mypage,myname,w,h,pos,infocus)
		 fnCheckForm(form)
		 fnClearQuickMessageDefaults(strName)
		 fnShowMessage()
		 fnWrapText(strTxtString, iLineLength)
		 fnSetNavbarColor()
		 fnDrawNavBar(strActivePage)

------------------------------------------------------------------------------*/
/********************************************
AUTHOR:WWW.CGISCRIPT.NET.LLC
URL:http://www.cgiscript.net
Use the code for FREE but leave this message intact
Download your FREE CGI/Perl Scripts today!
( http://www.cgiscript.net/scripts.htm )
****************************************************/
 
function fnPopup(mypage, myname, w, h, pos, infocus)
{
/****************************************
Popup window with scrollbars & resizable
****************************************/
	var DWWindow= null;
	if(pos=='random')
	{
    iLeftPosition= (screen.width)? Math.floor(Math.random()* (screen.width- w)): 100;
    iTopPosition= (screen.height)? Math.floor(Math.random()* ((screen.height- h)- 75)): 100;
	} // end if
  if(pos== 'center')
	{
    iLeftPosition= (screen.width)? (screen.width-w)/2: 100;
    iTopPosition= (screen.height)? (screen.height-h)/2: 100;
	} // end if
  else if((pos!= 'center' && pos!= 'random') || pos== null)
	{
  	iLeftPosition= 0;
  	iTopPosition= 0;
	} // end else if
	settings= 'width='+ w + ',height='+ h + ',top=' + iTopPosition + ',left=' + iLeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,dependent=no';
	DWWindow= window.open('', myname, settings);
	if(infocus== 'front')
	{
  	DWWindow.focus();
  	DWWindow.location= mypage;
	} // end if
} // end fnPopup()
//------------------------------------------------------------------------------
// popup window for links to other websites
function fnLinkPopup(mypage, myname, w, h, pos, infocus)
{
/****************************************
Popup window with location, menubar, toolbar,
statusbar, scrollbars & resizable
****************************************/
	var DWWindow= null;
	if(pos== 'random')
	{
    iLeftPosition= (screen.width)? Math.floor(Math.random()* (screen.width- w)): 100;
    iTopPosition= (screen.height)? Math.floor(Math.random()* ((screen.height- h)- 75)): 100;
	} // end if
  if(pos== 'center')
	{
    iLeftPosition= (screen.width)? (screen.width-w)/2: 100;
    iTopPosition= (screen.height)? (screen.height-h)/2: 100;
	}// end if
  else if((pos!= 'center' && pos!= 'random') || pos== null)
	{
  	iLeftPosition= 0;
  	iTopPosition= 0;
	} // end else if
	settings= 'width='+ w + ',height='+ h + ',top=' + iTopPosition + ',left=' + iLeftPosition + ',location=yes,directories=no,menubar=yes,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,dependent=no';
	DWWindow= window.open('', myname, settings);
	if(infocus== 'front')
	{
  	DWWindow.focus();
  	DWWindow.location= mypage;
	}// end if
} // end fnLinkPopup()
//------------------------------------------------------------------------------
// script to check the form has valid data
function fnCheckForm(form)
{
/****************************************
All required_ fields are identified and
first checked for a nil value, and any
required_email fields checked for a '@'
and a '.' character.
****************************************/
  var bPass=true;
  if (document.images)
  {
    for (i=0; i< form.length; i++)
    {
      var strTempobj= form.elements[i];
      // search form elements name field that start with "required"
      if (strTempobj.name.substring(0,8)== "required")
      {
        // check text input type fields are not blank, default and input is not a submit button
        if (((strTempobj.type== "text" || strTempobj.type== "textarea") && (strTempobj.value== ""
        		||strTempobj.value== "Your message here"))
        		||(strTempobj.type.toString().charAt(0)== "s" && strTempobj.selectedIndex== 0))
        {
        	bPass= false;
        	break;
        } // end if
        // identify e-mail fields and look for '@' character & '.'
        if ((strTempobj.name== "required_email") && (strTempobj.value.indexOf("@")== -1))
        {
        	alert ("Your address appears incorrect.\n\n" + 
        				 "Please check you have an '@' character.\n");
        	strTempobj.select();
        			return false;
        } // end if
        if ((strTempobj.name== "required_email") && (strTempobj.value.indexOf(".")== -1))
        {
        	alert ("Your address appears incorrect.\n\n" + 
        				 "Please check you have an '.' character.\n");
        	strTempobj.select();
        			return false;
        } // end if				 
      } // end if
    } // end for
  } // end if
	if (!bPass)
  {
		// get the text after 'required_' & convert to upper case
    strFieldName= strTempobj.name.substring(9,30).toUpperCase();
    alert("The "+ strFieldName+ " field has not been completed.");
		strTempobj.select();
    return false;
  }
	else
		return true;
}// end fnCheckForm()
//------------------------------------------------------------------------------
// function to clear the fields in the send message boxes
function fnClearQuickMessageDefaults(strName)
{
  (strName.value== "Your e-mail address here" || strName.value== "Your message here")?
	  strName.value= "": strName.select();
}
//------------------------------------------------------------------------------
// function to show message if query string with URL
function fnShowMessage()
{
	// test if there is a query string in the URL
	if (document.URL.indexOf("?")!= -1)
	{
	 	// get position of the =
		var iEqualsPos= document.URL.indexOf("=");
		// get the value of the query string
		var iMessageValue= parseInt(document.URL.substring(iEqualsPos+ 1, document.URL.length));
		// set the message acording the the query string value
		if (iMessageValue== 1)
		{
		 	// message to confirm an email message is sent
			var strMessage= "Your message has been sent to Decorative Wheels.";
		} // end if
		else if (iMessageValue== 2)
		{
		 	// message to confirm an order has been sent
			var strMessage= "Your order details have been sent to Decorative Wheels,\nand copied to your email address.";
		} // end else if
		else if (iMessageValue== 3)
		{
		 	// message to confirm an estimate has been sent
			var strMessage= "Your estimate details have been sent to Decorative Wheels,\nand copied to your email address.";
		} // end else if
		else if (iMessageValue== 4)
		{
		 	// message to confirm payment has been accepted
			var strMessage= "Your payment has been accepted.\nThank you for placing your order with Decorative Wheels.";
		} // end else if
		else if (iMessageValue== 5)
		{
		 	// message to confirm order has been cancelled
			var strMessage= "Your order payment has been cancelled.";
		} // end else if
	alert(strMessage);
	} // end if
	return;
} // end fnShowMessage()
// -----------------------------------------------------------------------------
// function to wrap a string of text
function fnWrapText(strTxtString, iLineLength)
{
  var strRuturnVal= "";
  var iEnd= strTxtString.length;
  var iLineEnd= 0;
  var iMaxCount= iLineLength;
  var iLineStart= 0;
  var iStart= 0;
  var iSpacePos= 0;
  // search for first space after iLineLength
  while (iSpacePos< iEnd)
  {
    iSpacePos= strTxtString.indexOf("\u0020", iStart);
  	if ((iSpacePos== -1) || (iSpacePos== iEnd))
  	{
  	 	// this is the last part of the text line
  		strRuturnVal+= strTxtString.substring(iLineStart, iEnd)+ "\n";
  		break;
  	} // end if
  	else if (iSpacePos> iMaxCount)
  	{
  	  iLineEnd= iStart- 1;
  		strRuturnVal+= strTxtString.substring(iLineStart, iLineEnd)+ "\n";
  		iMaxCount= iLineEnd+ 1+ iLineLength;
  		iLineStart= iStart= iLineEnd+ 1;
  	} // end else if
  	else
  	{
  	  iStart= iSpacePos+ 1;
  	} // end else
  } // end while
	return strRuturnVal;
} // end fnWrapText()
//------------------------------------------------------------------------------
// function to set the background colour of active navbar item
function fnSetNavbarColor()
{
	// generate a random number integer
  var fNavNo= Math.random();
  // set colour according to fNavNo value
  if (fNavNo <= 0.3)
  {
  	var strNavbarColor= '#ffcc00';
  } // end if
  else if (fNavNo> 0.3 && fNavNo<= 0.5)
  {
  	var strNavbarColor= '#ffd54b';
  } // end else if
  else if (fNavNo> 0.5 && fNavNo<= 0.65)
  {
  	var strNavbarColor= '#ffe376';
  } // end else if
  else
  {
  	var strNavbarColor= '#ffffcc';
  } // end else
  // return navbar colour
  return strNavbarColor;
  
} // end fnSetNavbarColor()
// -----------------------------------------------------------------------------
// function to draw the navigation bar
function fnDrawNavBar(strActivePage)
{
	// variable to hold the text for writing to the  web page
	var strNavBarText= "";
	// variable for the nav bar wheel
	var strNavBarWheel= '<td align="center"><img src="graphics/navbar_wheel.gif" width="25"'+
											'height="30" border="0" alt="small wooden wheel" /></td>';
	// start the nav bar table
	strNavBarText+= '<table class="navbar" align="center" valign="middle"><tr>';
	// check each nav bar page to see if its the active page
	// home page?
	strNavBarText+= (strActivePage== "home")?
										'<td align="center"><img src="graphics/home.gif" width="60" height="30"'+
										'border="0" alt="home page" /></td>':
										
										'<td align="center"><a href="index.html" target="_top" title="home page">'+
										'<img src="graphics/home.gif" width="60" height="30" border="0" alt="home page"'+
										'onmouseover="this.style.backgroundColor= fnSetNavbarColor();"'+
										'onmouseout="this.style.backgroundColor= \'#688e32\';"/>'+
										'</a></td>';
	// nav bar wheel
	strNavBarText+= strNavBarWheel;
	// products page?
	strNavBarText+= (strActivePage== "products")?
									'<td align="center"><img src="graphics/products.gif" width="100" height="30" border="0"'+
									'alt="products page" /></td>':
									
									'<td align="center"><a href="products.html" target="_top" title="products page">'+
									'<img src="graphics/products.gif" width="100" height="30" border="0"'+
									'alt="products page" onmouseover="this.style.backgroundColor= fnSetNavbarColor();"'+
									'onmouseout="this.style.backgroundColor= \'#688e32\';" /></a></td>';
	// nav bar wheel
	strNavBarText+= strNavBarWheel;
	// information page?
	strNavBarText+= (strActivePage== "information")?
									'<td align="center"><img src="graphics/information.gif" width="120" height="30" border="0"'+
									'alt="information page" /></td>':
									
									'<td align="center"><a href="information.html" target="_top" title="information page">'+
									'<img src="graphics/information.gif" width="120" height="30" border="0"'+
									'alt="information page" onmouseover="this.style.backgroundColor= fnSetNavbarColor();"'+
									'onmouseout="this.style.backgroundColor= \'#688e32\';" /></a></td>';
	// nav bar wheel
	strNavBarText+= strNavBarWheel;
	// links page?
	strNavBarText+= (strActivePage== "links")?
									'<td align="center"><img src="graphics/links.gif" width="60" height="30" border="0"'+
									'alt="links page" /></td>':
									
									'<td align="center"><a href="links.html" target="_top" title="links page">'+
									'<img src="graphics/links.gif" width="60" height="30" border="0"'+
									'alt="links page" onmouseover="this.style.backgroundColor= fnSetNavbarColor();"'+
									'onmouseout="this.style.backgroundColor= \'#688e32\';" /></a></td>';
	// nav bar wheel
	strNavBarText+= strNavBarWheel;
	// gallery page?
	strNavBarText+= (strActivePage== "gallery")?
									'<td align="center"><img src="graphics/gallery.gif" width="80" height="30" border="0"'+
									'alt="gallery page" /></td>':
									
									'<td align="center"><a href="gallery.html" target="_top" title="gallery page">'+
									'<img src="graphics/gallery.gif" width="80" height="30" border="0"'+
									'alt="gallery page" onmouseover="this.style.backgroundColor= fnSetNavbarColor();"'+
									'onmouseout="this.style.backgroundColor= \'#688e32\';" /></a></td>';
	// nav bar wheel
	strNavBarText+= strNavBarWheel;
	// contacts page?
	strNavBarText+= (strActivePage== "contacts")?
									'<td align="center"><img src="graphics/contacts.gif" width="100" height="30" border="0"'+
									'alt="contacts page" /></td>':
									
									'<td align="center"><a href="contacts.html" target="_top" title="contacts page">'+
									'<img src="graphics/contacts.gif" width="100" height="30" border="0"'+
									'alt="contacts page" onmouseover="this.style.backgroundColor= fnSetNavbarColor();"'+
									'onmouseout="this.style.backgroundColor= \'#688e32\';" /></a></td>';
	// end nav bar table
	strNavBarText+= '</tr></table>';
	// write to the web page
	document.write(strNavBarText);
	// close output stream
	document.close();

} // end fnDrawNavBar()
// -----------------------------------------------------------------------------