	// JavaScript Document
	function bookmark(){
	var url="http://www.governmentdebtassistance.co.uk";
	var title="Government Debt Assistance";
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function trim( instr ) {

    	var reFirst = /\S/;		// regular expression for first non-white char
    	var reLast = /\s+$/;	// regular expression for first white char after last non-white char
    	var firstChar = instr.search(reFirst);
    	var lastChar = instr.search(reLast);
    	
    	if( lastChar == -1 ) 
			lastChar = instr.length;    	
    	outstr = instr.substring( firstChar, lastChar );
    	return outstr;
}
function postalcode(val)
{
alert("post");
   if (val.match(/^[a-zA-Z0-9\s]+$/))
   {
    alert("yes");
      return true;
   }
   else
   {
   	    alert("false");
      return false;
   }   
}
function isNumber(val)
{

   if (val.match(/^[0-9.\s]+$/))
   {
      return true;
   }
   else
   {
      return false;
   }   
}
function checkBlank(field)
{
	if(trim(field.value) == "" ||(trim(field.value)=="Please Select...") ||(trim(field.value)=="Please Select") ||(trim(field.value)=="Please Select.."))
	{			
//		field.focus();
//		if(name != null)
//			alert(name+" cannot be left blank.");
//		else
//			alert("This field cannot be left blank.");

//		field.value = "";
//		field.focus();
		return false;
	}

	return true;
}
function isValidEmail (emailIn){

	var isEmailOk = false;
//	var filter = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9-]+(\.[a-zA-Z][a-zA-Z-]+)+$/
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;


	if(emailIn.search(filter) != -1)
		isEmailOk = true;
	if(emailIn.indexOf("..") != -1)
		isEmailOk = false;
	if(emailIn.indexOf(".@") != -1)
		isEmailOk = false;
	if(emailIn.indexOf("'") != -1 || emailIn.indexOf("''") != -1 || emailIn.indexOf("\"") != -1 || emailIn.indexOf("\"\"") != -1 || emailIn.indexOf("(") != -1  || emailIn.indexOf(")") != -1 || emailIn.indexOf("[") != -1 || emailIn.indexOf("]") != -1 || emailIn.indexOf("{") != -1  || emailIn.indexOf("}") != -1 || emailIn.indexOf(",") != -1 || emailIn.indexOf(",,") != -1 || emailIn.indexOf(":") != -1 || emailIn.indexOf(";") != -1 || emailIn.indexOf("#") != -1 || emailIn.indexOf("mailto:") != -1)
		isEmailOk = false;

	return isEmailOk;
} // Ends 
function CheckValidation(objValue,strError)
{
   if(eval(objValue.value.length) == 0) 
   { 
      if(!strError || strError.length ==0) 
      { 
        strError =  "Required Field"; 
      } 
      alert(strError); 
      return false; 
   }
   return true;
}
function checkmail(email)
{

// a very simple email validation checking. 
/* you can add more complex email checking if it helps */
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false; 
}
function validateemail(o)
{
	var strError;
	
	email=o.value;
			   if(!checkmail(email)) 
               { 
                    alert("Enter valid Email address "); 
                    o.focus();
	                return false; 
               }
               return true;
}

function validatehphone(field)
{
	 var val=field.value;
	 var hphone=val.split(' ').join('');
     
	 if(isNaN(hphone))
	 {
		return false;
	 }
	 else
	 {
	   var len=hphone.length;	 
	   if(len == 10 || len == 11)
	   {
		 return true;
	   }
	   else
	   {
	     return false;
	   }
	 }
}

function validateMe(){

	var frm	= document.forms['0'];
	if(checkBlank(frm.firstname)==false)
	{
		alert("First Name is compulsory");
		frm.firstname.focus();
		return false;
	
	}
	else if(checkBlank(frm.lastname)==false)
	{
		alert("Enter Last Name");
		frm.lastname.focus();
		return false;
	}
	if (checkBlank(frm.homephone)==false && checkBlank(frm.mobilephone)==false)
	{
		alert("Please Enter Homephone or Mobilephone");
		frm.homephone.focus();
		return false;
		
	}
	else
	{
		if(checkBlank(frm.homephone)!=false)
		{
			if(validatehphone(frm.homephone)==false)
			{
				alert("Enter Valid Homephone");
				frm.homephone.focus();
				return false;
			}
		}
		if(checkBlank(frm.mobilephone)!=false)
		{
			if(validatehphone(frm.mobilephone)==false)
			{
				alert("Enter Valid Mobilephone");
				frm.mobilephone.focus();
				return false;
			}
		}
		
	}
	
	/*if(checkBlank(frm.mobilephone)!=false)
	{
		if(validatehphone(frm.mobilephone)==false)
		{
			alert("Enter Valid Mobile No");
			frm.mobilephone.focus();
			return false;
		}
	}*/
	if(checkBlank(frm.email)==false)
	{
		alert("Enter Email address");
		frm.email.focus();
		return false;
	}	
	else if (!validateemail(frm.email))
	{
		return false;
	}
	else if(checkBlank(frm.houseno)==false)
	{
		alert("Enter House Number or Address");
		frm.houseno.focus();
		return false;
	}
	else if(checkBlank(frm.postcode)==false)
	{
		alert("Enter Postal Code");
		frm.postcode.focus();
		return false;
	}
	else if(checkBlank(frm.resitype)==false)
	{
		alert("Please Select Residence Type");
		frm.resitype.focus();
		return false;

	}
	else if(checkBlank(frm.incometype)==false)
	{
		alert("Please Select Income Type");
		frm.incometype.focus();
		return false;
	}
	else if(checkBlank(frm.monthlyincome)==false)
	{
		alert("Please Select Monthly Income.");
		frm.monthlyincome.focus();
		return false;
	}
	else if(checkBlank(frm.noofdebts)==false)
	{
		alert("Please Select No Of Debts Total Owed");
		frm.noofdebts.focus();
		return false;
	}
	else if(checkBlank(frm.totalowed)==false)
	{
		alert("Please Select total owed");
		frm.totalowed.focus();
		return false;

	}
	else if(CheckNumber(frm.totalmonthlybills)==false)
	{		
		alert("Total Monthly bill shoould be Numeric");
		frm.totalmonthlybills.focus();
		frm.totalmonthlybills.value="";
		return false;		
	}
	else if(checkBlank(frm.contacttime)==false)
	{
		alert("Please Select Contact Time");
		frm.contacttime.focus();
		return false;
		
	}
	
	/*else if(checkBlank(frm.mobilephone)==false)
	{
		alert("Enter Mobile No");
		frm.homephone.focus();
		return false;
	}*/
	/*else if(checkBlank(frm.maritalstatus)==false)
	{
		alert("Please Select Martial status");
		frm.maritalstatus.focus();
		return false;

	}*/
	fnm=frm.firstname.value;
	createCookies('name',fnm);
	//alert(document.forms['0'].affid.value);
	//alert("test");
	return true;
	
}
function CheckNumber()
{
	
var frm=document.forms['0'];
var val=frm.totalmonthlybills.value;
   if (val.match(/^[0-9.\s]+$/))
   {
	   
      return true;
   }
   else
   {
	  
      return false;
   }   
}

function calldiv(val)
{
  if(val=='1')
  {
    setVisible('layer1')
  }
  else
  {
    setInvisible('layer1');
  }
}
function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function setInvisible(obj)
{
	obj = document.getElementById(obj);
	//document.getElementById("name").value="";
	//document.getElementById("email").value="";
	
	//document.getElementById("result1err").innerHTML="";
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'hidden';
}


function createCookies(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookies(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

