function toggle_visibility(id, name)
{
  var e = document.getElementById(id);
  var f = document.getElementById(name);
  if(e.style.display == 'none')
  {
     e.style.display = 'block';
	 f.innerHTML = 'Hide';
  }
  else
  {
    e.style.display = 'none';
	f.innerHTML = 'Show';
  }
}

function addFavourite() {
	title = "Compare DVD Rental";  
	url = "http://www.compare-dvd-rental.co.uk";
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,""); } 
	else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); } 
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
	else { alert("Sorry! Your browser doesn't support this function."); } // Other
 }


function checkEmail(mail)
{
  var email = mail;
  invalidChars = " /:,;?()"
  incorrect ='';
  var errormessage="";

  for (i=0; i<invalidChars.length; i++) 
  {
    badChar = invalidChars.charAt(i)

    if (email.indexOf(badChar,0) > -1) 
    {
      incorrect += '   - Invalid Email Address\n';
      break;
    }
  }
  atPos = email.indexOf("@",1)

  if (atPos == -1)
  {
    incorrect += '   - Invalid Email Address\n';
  }

  if (email.indexOf("@",atPos+1) > -1)
  {
    incorrect += '   - Invalid Email Address\n';
  }
  periodPos = email.indexOf(".",atPos)

  if (periodPos == -1)
  {
    incorrect += '   - Invalid Email Address\n';
  }

  if (periodPos+3 > email.length)
  {
    incorrect += '   - Invalid Email Address\n';
  }           

  if (incorrect != '')
  {
    errormessage += '   - Invalid Email Address\n';
  }
 return errormessage;
}

function checkNewsletterForm()
{

 alertmessage = "";
 
  if(document.newsletterFrm.newsletter_name.value == "")
  {
    alertmessage += '   - Your Name\n';
  }
    
  if(document.newsletterFrm.newsletter_email.value == "")
  {
    alertmessage += '   - Your Email\n';
  }

  if(document.newsletterFrm.newsletter_email.value!="")
  {
    alertmessage+= checkEmail(document.newsletterFrm.newsletter_email.value);
  }
  
  if(alertmessage == "")
  {
     return true;
  }
  else
  {
    TopMessage = "You have not entered the following form elements correctly: \n\n";
    BottomMessage = "\nPlease correct these fields to continue";
    alertmessage = TopMessage + alertmessage + BottomMessage;

    alert(alertmessage);
    return false;
  }
}

function populateName()
{
  if(document.newsletterFrm.newsletter_name.value == "")
  {
    document.newsletterFrm.newsletter_name.value = "Enter name...";
  }
}

function populateEmail()
{
  if(document.newsletterFrm.newsletter_email.value == "")
  {
    document.newsletterFrm.newsletter_email.value = "Enter email...";
  }
}

function populatePostCode()
{
  if(document.getElementById('postcode').value == "")
  {
    document.getElementById('postcode').value = "Enter Postcode...";
  }
}

function clearName()
{
  if(document.newsletterFrm.newsletter_name.value == "Enter name...")
  {
    document.newsletterFrm.newsletter_name.value = "";
  }
}

function clearEmail()
{
  if(document.newsletterFrm.newsletter_email.value == "Enter email...")
  {
    document.newsletterFrm.newsletter_email.value = "";
  }
}

function clearPostCode()
{
  if(document.getElementById('postcode').value == "Enter Postcode...")
  {
    document.getElementById('postcode').value = "";
  }
}

function CheckEnquiryForm()
{

 alertmessage = "";
 
  if(document.EnquiryForm.reason.value == "")
  {
    alertmessage += '   - type of query\n';
  }

  if(document.EnquiryForm.name.value == "")
  {
    alertmessage += '   - Name\n';
  }
  
  if(document.EnquiryForm.enquiry.value == "")
  {
    alertmessage += '   - Enquiry\n';
  }

  if(document.EnquiryForm.mail.value=="")
  {
    alertmessage += '   - Email\n';
  }

  if(document.EnquiryForm.mail.value!="")
  {
    alertmessage+= checkEmail(document.EnquiryForm.mail.value);
  }
  
  if(alertmessage == "")
  {
    if(document.EnquiryForm.reason.value=="products")
    {
      alert("Broadband Finder does not offer an internet broadband service we merely show a comparision of current offers. please contact the appropriate merchant");
      return false;
	}
	else
	{
      return true;
	}
  }
  else
  {
    TopMessage = "You have not entered the following form elements correctly: \n\n";
    BottomMessage = "\nPlease correct these fields to continue";
    alertmessage = TopMessage + alertmessage + BottomMessage;

    alert(alertmessage);
    return false;
  }
}

function gonow(u) 
{
	//window.location.href=u;
	window.open(u);
}


function jumper()
{
	var url = '';
	for (i = 0; i < arguments.length; i++)
	{
		url = url + arguments[i];
	}
	
	gonow(url);
}
