function changeDiv(rowID)
{
  var thisRow = parseInt(rowID);
  var objRow = document.getElementById('menu_'+thisRow);

  objRow.style.background = "url(images/parts/navbuttonandbullet_over.jpg)";
}

function changeDivBack(rowID)
{
  var thisRow = parseInt(rowID);
  var objRow = document.getElementById('menu_'+thisRow);

  objRow.style.background = "url(images/parts/navbuttonandbullet.jpg)";
}

function changeDivSewer(rowID)
{
  var thisRow = parseInt(rowID);
  var objRow = document.getElementById('menu_'+thisRow);

  objRow.style.background = "url(images/parts/navbuttonandbullet.jpg)";
}

function changeDivBackSewer(rowID)
{
  var thisRow = parseInt(rowID);
  var objRow = document.getElementById('menu_'+thisRow);

  objRow.style.background = "url(images/parts/navbuttonandbullet_over.jpg)";
}


function changeDivBottom(rowID)
{
  var thisRow = parseInt(rowID);
  var objRow = document.getElementById('menu_'+thisRow);

  objRow.style.background = "url(images/parts/navbarbottomfilled.jpg)";
}

function changeDivBackBottom(rowID)
{
  var thisRow = parseInt(rowID);
  var objRow = document.getElementById('menu_'+thisRow);

  objRow.style.background = "url(images/parts/navbuttonandbulletbottom_ov.jpg)";
}

function changeDivTop()
{
  var objRow = document.getElementById('navtop');

  objRow.style.background = "url(images/parts/navbatopfilledover.jpg)";
}

function changeDivBackTop()
{
  var objRow = document.getElementById('navtop');

  objRow.style.background = "url(images/parts/navbatopfilled.jpg)";
}



function checkTerms(f)
{

	if(f.read.checked)
	{
		return true;
	}
	else
	{
		alert("You must read and agree to the Ant Hire Ltd terms and conditions of sale to complete your order.");
		return false;
	}
}


function copyAddress(f)
{
		f.shipping_line1.value = f.billing_line1.value;
		f.shipping_line2.value = f.billing_line2.value;
		f.shipping_town.value = f.billing_town.value;
		f.shipping_county.value = f.billing_county.value;
		f.shipping_country.value = f.billing_country.value;
		f.shipping_postcode.value = f.billing_postcode.value;
		f.shipping_tel.value = f.billing_tel.value;
}


/*
 * validate email address, check for illegal characters, check there is one
 * @ sign and at least one . after it. return true or false
 */
function validateEmail(tempEmail)
{

   var valid = true;
   len = tempEmail.length;

   if(len==0){
        valid = false;
   }


   spaces = tempEmail.indexOf(' ');
        // check for spaces
        if(spaces != -1)
                valid = false;

   ampers = tempEmail.indexOf('&');
        // check for ampersands
        if(ampers != -1)
                valid = false;

   at = tempEmail.indexOf('@');
        // check there is a at sign
        if(at == -1)
                valid = false;

   atmore = tempEmail.indexOf('@',(at+1));
        // check for more at signs
        if(atmore != -1)
                valid = false;

   dot = tempEmail.indexOf('.',at);
        // check for a dot after the at sign
        if(dot== -1)
                valid = false;

   if((at == 0)||(at== len))
   {
        // check where the at sign is
        valid = false;
   }

   return valid;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


function changeImages(v1,v2)
{
	document[v1].src = v2;
}

function openWin(strFile, strName, intWidth, intHeight)
{
    var strProperties = 'toolbar=no,width=' + Math.round(intWidth) + ',height=' + Math.round(intHeight) + ',left=30,top=150,' + 'status=no,scrollbars=no,resizable=no,menubar=no';
    tmpWin = window.open(strFile,strName,strProperties);
    tmpWin.focus();
    
}

function openSignup(email)
{
	var u = "signup.php?email=" + email;
	openWin(u,"prodtype","400","400");
}

function openScrollingWin(strFile, strName, intWidth, intHeight)
{
    var strProperties = 'toolbar=no,width=' + Math.round(intWidth) + ',height=' + Math.round(intHeight) + ',left=30,top=150,' + 'status=yes,scrollbars=yes,resizable=yes,menubar=no';
    tmpWin = window.open(strFile,strName,strProperties);
    tmpWin.focus();
    
}

function checkSignup(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.first_name.value == "")
    {
        errors += "- First Name must be completed.\n";
        valid = false;
    }

  if (f.last_name.value == "")
    {
        errors += "- Last Name must be completed.\n";
        valid = false;
    }

    if (f.company.value == "")
    {
        errors += "- Company must be completed.\n";
        valid = false;
    }
        
    if (f.email.value == "")
    {
        errors += "- Email must be completed.\n";
        valid = false;
    }
    else
    {
    	if(!validateEmail(f.email.value))
    	{
        	errors += "- Invalid email address.\n";
       		valid = false;    	
    	}
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
}

/*function checkSignup(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contactname.value == "")
    {
        errors += "- Name must be completed.\n";
        valid = false;
    }
    
    if (f.address.value == "")
    {
        errors += "- Address must be completed.\n";
        valid = false;
    }

    if (f.email.value == "")
    {
        errors += "- Email must be completed.\n";
        valid = false;
    }
    else
    {
    	if(!validateEmail(f.email.value))
    	{
        	errors += "- Invalid email address.\n";
       		valid = false;    	
    	}
    }
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
}
*/

function checkBrochure(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.first_name.value == "")
    {
        errors += "- First Name must be completed.\n";
        valid = false;
    }

    if (f.last_name.value == "")
    {
        errors += "- Last Name must be completed.\n";
        valid = false;
    }

    if (f.company.value == "")
    {
        errors += "- Company must be completed.\n";
        valid = false;
    }
    
     if (f.email.value == "")
    {
        errors += "- Email must be completed.\n";
        valid = false;
    }
    else
    {
    	if(!validateEmail(f.email.value))
    	{
        	errors += "- Invalid email address.\n";
       		valid = false;    	
    	}
    }
    

    if (f.street.value == "")
    {
        errors += "- Address must be completed.\n";
        valid = false;
    }    

    if (f.city.value == "")
    {
        errors += "- Town / City must be completed.\n";
        valid = false;
    }    
    
    if (f.zip.value == "")
    {
        errors += "- Postcode must be completed.\n";
        valid = false;
    }    
    
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
}

/*function checkBrochure(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contactname.value == "")
    {
        errors += "- Name must be completed.\n";
        valid = false;
    }
    
    if (f.company.value == "")
    {
        errors += "- Company must be completed.\n";
        valid = false;
    }    

    if (f.address.value == "")
    {
        errors += "- Address must be completed.\n";
        valid = false;
    }      

    if (f.email.value == "")
    {
        errors += "- Email must be completed.\n";
        valid = false;
    }
    else
    {
    	if(!validateEmail(f.email.value))
    	{
        	errors += "- Invalid email address.\n";
       		valid = false;    	
    	}
    }

    if (f.query.value == "")
    {
        errors += "- Query must be completed.\n";
        valid = false;
    }    
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
}*/


function checkContact(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.first_name.value == "")
    {
        errors += "- First Name must be completed.\n";
        valid = false;
    }

    if (f.last_name.value == "")
    {
        errors += "- Last Name must be completed.\n";
        valid = false;
    }

    if (f.company.value == "")
    {
        errors += "- Company must be completed.\n";
        valid = false;
    }
    
     if (f.email.value == "")
    {
        errors += "- Email must be completed.\n";
        valid = false;
    }
    else
    {
    	if(!validateEmail(f.email.value))
    	{
        	errors += "- Invalid email address.\n";
       		valid = false;    	
    	}
    }
    
    if (f.description.value == "")
    {
        errors += "- Enquiry must be completed.\n";
        valid = false;
    }    
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
}


/*function checkContact(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contactname.value == "")
    {
        errors += "- Name must be completed.\n";
        valid = false;
    }
    
    if (f.address.value == "")
    {
        errors += "- Address must be completed.\n";
        valid = false;
    }

    if (f.email.value == "")
    {
        errors += "- Email must be completed.\n";
        valid = false;
    }
    else
    {
    	if(!validateEmail(f.email.value))
    	{
        	errors += "- Invalid email address.\n";
       		valid = false;    	
    	}
    }

    if (f.query.value == "")
    {
        errors += "- Query must be completed.\n";
        valid = false;
    }    
    
    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
}*/

function checkOrderDetails(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.contact_name.value == "")
    {
        errors += "- contact_name must be completed.\n";
        valid = false;
    }

    if (f.email_address.value == "" || f.email_address_conf.value == "")
    {
        errors += "- email_address and email confirmation must be completed.\n";
        valid = false;
    }
    else
    {
    	if(f.email_address.value != f.email_address_conf.value)
    	{
         	errors += "- email_address and email confirmation do not match.\n";
        	valid = false;   	
    	}
    	else
    	{
    		if(!validateEmail(f.email_address.value))
			{
				errors += "- Invalid email address.\n";
				valid = false;    	
    		}
    	}
    }
    
    if (f.billing_line1.value == "")
    {
        errors += "- billing_line1 must be completed.\n";
        valid = false;
    }
    
    if (f.billing_town.value == "")
    {
        errors += "- billing_town must be completed.\n";
        valid = false;
    }
    
    if (f.billing_country.value == "")
    {
        errors += "- billing_country must be completed.\n";
        valid = false;
    }
    
    if (f.billing_postcode.value == "")
    {
        errors += "- billing_postcode must be completed.\n";
        valid = false;
    }

    if (f.billing_tel.value == "")
    {
        errors += "- billing_tel must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_line1.value == "")
    {
        errors += "- shipping_line1 must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_town.value == "")
    {
        errors += "- shipping_town must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_country.value == "")
    {
        errors += "- shipping_country must be completed.\n";
        valid = false;
    }
    
    if (f.shipping_postcode.value == "")
    {
        errors += "- shipping_postcode must be completed.\n";
        valid = false;
    }

    if (f.check_other_info.value == "1")
    {
    	if (f.other_info.value == "")
    	{
    		errors += "- hire dates and length of hire must be completed.\n";
        	valid = false;
        }
    }
    
    if (!valid && f.checkall.value == "1")
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	 return valid;
}
