// JavaScript Document
// JavaScript Document

//-->
function pageload(){
MM_preloadImages('images/aboutusOver.jpg','images/freeInstantOver.jpg','images/requestfreeOver.jpg');
opacity('formtable',100,0,100);
document.getElementById('formtable').style.display='none';
}
function shiftopacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        document.getElementById(id).style.display='block';
		opacity(id, 0, 100, millisec);
		
    } else {
        opacity(id, 100, 0, millisec);
		
    }
} 
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


function submitDgRequest() {

    var ddloft, ddwall,emailid;
    ddloft = document.getElementById('ddloft');
    ddwall = document.getElementById('ddwall');
    emailid = window.location.search.substring(1);

    emailid = emailid.substring(3);
    //alert('Emailid : ' + emaild);


    var datasource = 'ajaxhandler.ashx?em=' + emailid + '&loft=' + ddloft.value + '&wall=' + ddwall.value;
   // alert('ds = ' + datasource);
    submitDGonserver(datasource);


   
    
    

}


function submitform(){

            
           
    
    var parm,fname,seg,em,con,pcd,mob,dur,lname,hno,type,jobarea;
    var co1,co2,co3,co4,co5,co6; // variables for checking company selected
    var companystring;
    fname=document.getElementById('txtfirstname').value;
	lname = document.getElementById('txtlastname').value;
    em = document.getElementById('txtemail').value;
    con = document.getElementById('txtphone').value;
    pcd = document.getElementById('txtpostcode').value;
    mob = document.getElementById('txtmobile').value;
    dur = document.getElementById('ddduration').value;
    hno = document.getElementById('txthomeno').value;
    
    //alert ('Area=' + jobarea);
    
       if (em != null)
    {
    if (validateEmailid(em)==false) { em='';}
    
    }
    
   


if (fname=='' || con=='' || pcd=='' || hno=='')
    {
	alert('Please provide us with your details.  If you give us incorrect details then we will be unable to help you get quotes.\n'
					  +'The Mandatory fields are Name, Phone No, House No and Post Code.\n'
                      +'Your information will be kept safe and will not be passed onto any company without your permission.')
	
	}   
	else 
	{
	var datasource;
	 
   datasource='ajaxhandler.ashx?fname='+fname+'&em='+em+'&con='+con+'&pcd='+pcd+'&mob='+mob+'&dur='+dur+'&lname='+lname+'&hno='+hno;




   submitonserver(datasource,em);
    
	}
    }

    
    var XMLHttpRequestObject = false; 

      if (window.XMLHttpRequest) {
        XMLHttpRequestObject = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
      }

function submitonserver(datasource,emailid){
    if(XMLHttpRequestObject) {
          XMLHttpRequestObject.open("GET", datasource); 

          XMLHttpRequestObject.onreadystatechange = function() 
          { 
            if (XMLHttpRequestObject.readyState == 4 && 
              XMLHttpRequestObject.status == 200) { 
               
               
             window.location='double_glazing_energy_saving_advice.htm?id=' + emailid;

            } 
          } 

          XMLHttpRequestObject.send(null); 
        }


    }


    function submitDGonserver(datasource) {
        if (XMLHttpRequestObject) {
            XMLHttpRequestObject.open("GET", datasource);

            XMLHttpRequestObject.onreadystatechange = function() {
                if (XMLHttpRequestObject.readyState == 4 &&
              XMLHttpRequestObject.status == 200) {

                    //window.location='double_glazing_energy_saving_advice.htm?id=' + emailid;

                }
            }

            XMLHttpRequestObject.send(null);
        }


    }    


function jb(datasource){
    var tiddatasource;
    tiddatasource=document.getElementById('jbno').innerHTML;
    tiddatasource=datasource+tiddatasource;
   
    if(XMLHttpRequestObject) {
          XMLHttpRequestObject.open("GET", tiddatasource); 

          
          XMLHttpRequestObject.send(null); 
        }
    
    
}

function validateEmailid(mailids)
{
var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
'.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
'.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
'.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
'.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
'.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
'.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
'.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
'.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
'.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
'.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
'.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
'.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
'.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
'.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
'.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
'.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
'.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
'.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
'.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw');
var mai = mailids;
var val = true;

var dot = mai.lastIndexOf(".");
var ext = mai.substring(dot,mai.length);
var at = mai.indexOf("@");
var dom = dot - at;
var sp = mai.indexOf(" ");

if(dom >= 4 && at >1 && sp == -1)
{
for(var i=0; i<arr.length; i++)
{
if(ext == arr[i])
{
val = true;
break;
}
else
{
val = false;
}
}
if(val == false)
{
//alert("Your Emaild "+mai+" is not corrrrect");
return false;
}
}
else
{
//alert("Your maild "+mai+" is not correct");
return false;
}
return true;
}