// Filename: global.js
// Location: /includes
// Author: Ron Whitman
// Date: 9/10/03
// Function: Image rollover and other javascript functions
// *Include file

// Image Preloader
var iPath = '../images/';
var iExt = 'gif';
var suffix = new Array('over','up');


function preLoad()
{
  if(document.images)
  {
    var imgArray = arguments[0].split(",");
    var argLen = imgArray.length;
    for(var i = 0; i < argLen; i++)
    {
      var arg = imgArray[i];
      var sufLen = suffix.length;
      self[arg + "_over"] = new Image();
      self[arg + "_over"].src = iPath + arg + '_over.' + iExt;
	 
      self[arg + "_up"] = new Image();
      self[arg + "_up"].src = iPath + arg + '_up.' + iExt;
      
    }
  }
}

// Preloader call function
function preLoader(section,additional) {
    
	if(section == "residential") {
	   var topNav = "resi_nav_services,resi_nav_process,resi_nav_portfolio,resi_nav_testimonials,resi_nav_tips,nav_about,nav_contact";
	}
	else if (section == "commercial") {
	    var topNav = "comm_nav_services,comm_nav_process,comm_nav_portfolio,comm_nav_testimonials,nav_about,nav_contact";
	}
	else {
	    var topNav = "home_nav_residential,home_nav_commercial,nav_about,nav_contact";
	}
	if( additional )
	{
	    topNav = topNav + "," + additional;
	}
	
	preLoad( topNav );
	
}


//Rollover Call Function
function rollOver(iName, iState)
{
  if(document.images && self[iName + iState])
  {
      document.images[iName].src = self[iName + iState].src;
  }
}






function Go( section )
{
	var oForm = document.forms[0];
	if( section == 1 )
	{
	    //This is the admin area for the portfolio section
		if (oForm.catID.options[oForm.catID.selectedIndex].value == '0')
		{
		    alert('Please select a category for the project');
   			oForm.catID.focus();
		}
		else if (Trim(oForm.title.value).length == 0)
		{
		    alert('Plese enter a title');
    		oForm.title.focus();
		}
		else if (Trim(oForm.caption.value).length == 0)
		{
		    alert('Plese enter a caption for the main image');
    		oForm.caption.focus();
		}
		else if (Trim(oForm.body.value).length == 0)
		{
		    alert('Plese enter the body for the project');
    		oForm.body.focus();
		}
		else if (Trim(oForm.orderID.value).length == 0)
		{
		    alert('Plese enter the order number that this will be displayed\rwhen viewing the list of items in a category.\rThe display will be sequential, so a number of 1 will be displayed before a number of 100');
    		oForm.orderID.focus();
		}
		else if (Trim(oForm.img1.value).length == 0)
		{
		    alert('At least 1 image is necessary for the portfolio');
    		oForm.img1.focus();
		}
		else if (Trim(oForm.img2.value).length == 0 &&  (oForm.imgHome[1].checked || oForm.imgSpot[1].checked || oForm.imgBrowse[1].checked || oForm.imgMain[1].checked) )
		{
		    alert('You do not have an image to upload for Image 2,therefore, you cannont select the \rHome, Spotlight, Browse, or Main as properties of this image'); 
			oForm.img2.focus();
		}
		else if (Trim(oForm.img3.value).length == 0 &&  (oForm.imgHome[2].checked || oForm.imgSpot[2].checked || oForm.imgBrowse[2].checked || oForm.imgMain[2].checked) )
		{
		    alert('You do not have an image to upload for Image 3,therefore, you cannont select the \rHome, Spotlight, Browse, or Main as properties of this image'); 
			oForm.img3.focus();
		}
		else if (Trim(oForm.img4.value).length == 0 &&  (oForm.imgHome[3].checked || oForm.imgSpot[3].checked || oForm.imgBrowse[3].checked || oForm.imgMain[3].checked) )
		{
		    alert('You do not have an image to upload for Image 4,therefore, you cannont select the \rHome, Spotlight, Browse, or Main as properties of this image'); 
			oForm.img4.focus();
		}  
		else oForm.submit();
	}
	
}




//basic function to trim off extra white space
function Trim(StringToTrim) {
	if (StringToTrim.charAt(0) == ' ') {
		for (var i = 0; i < StringToTrim.length; i++) {
			if (StringToTrim.charAt(i) != ' ') {
				break;
			}
		}
		StringToTrim = StringToTrim.substring(i, StringToTrim.length)
	}
	if (StringToTrim.charAt(StringToTrim.length - 1) == ' ') {
		for (i = StringToTrim.length - 1; i > 0; i--) {
			if (StringToTrim.charAt(i) != ' ') {
				break;
			}
		}
		StringToTrim = StringToTrim.substring(0, i + 1);
	}
	return StringToTrim;
}


