// JavaScript Document

	/*for testing purpose on live panel
	fullURL = parent.document.URL;
	testURL=fullURL.split('loc=en_')[1];
	*/
	 
	
	 
	
    
window.onload=function(){





try{

hideBox();
hideQuestions();
}catch(e){}
}




/*this function check if the browser understand DOM than it hide all the element of the hidden array the names needs to start with B see XSL file*/
function hideBox() {
 var hidden= new Array("h&OCCUPATION_T&EMPL_0","h&CIE_0_T&HHSIZE16_0","h&CIEOCCUPATION_T&CIE_0","h&ETHNIC_EASTERN_T&ETHNIC_0");

gr=hidden;

if(document.getElementById)
    {
        
	  
        for(i=0;i<gr.length;i++)
        {
					
			try{
				
				arrays=gr[i].split("&");
				expr=new RegExp("\_"+arrays[0]+"$")/*this is to check if the value contain a 'h' if so we need to hide it */
				
				hide=document.getElementById(arrays[1]);//the table to be hidden
				//if those elements exists than ...
				if(hide){
				
				 	
					/*First check if is not a radio, if so than get the elemen that trigger the event by his id*/	
					if(document.getElementById(arrays[2]).type!="radio")
					{		
							checked=document.getElementById(arrays[2]);
							value=checked.value;}
					else{
						checked=document.getElementsByName(arrays[2]);
						value=getCheckedValue(checked);}
					
					if((value.search(expr)==-1)||(value==""))// if _h is not present in the value selected or is empty
					{
						
						
						hide.style.display="none"; 
						
						if(arrays[1].search("\NECTAR")==-1){
					
						l=(arrays[1].length)-2;
						elementToHide=document.getElementsByName(arrays[1].substring(0,l));
							if(getCheckedValue(elementToHide)=="")
							{selectOption('0',arrays[1].substring(0,l));/*change the selectet value of the hidden question to ""	*/}
							else{unCheckRadio(elementToHide);}
						
						}
					}
					else{
						
						hide.style.display="inline"; 
						
						}
				}
			}catch(e){}
			
		
        }

	

    }
}






function detect()
{
if (typeof document.body.style.maxHeight != "undefined") {
  					// IE 7, mozilla, safari, opera 9
					return true; 
					} else {
  						// IE6, older browsers
						return false;
						}
	  			
}

/*function errore(lang)
{
	msg="";
	if(lang=="ru")
	{
		msg="Произошла ошибка, пожалуйста,  проверьте указанное ниже красное сообщение об ошибке!";
	}
	else{msg="An error occurred, please check the red error message down  below!";}
	if(errcount==0){
	err=document.getElementById("errore");
	err.appendChild(document.createTextNode("* "+msg));}
	errcount++;
	
}*/

function changeTxt(id,idTxt,testo,height)
{
	var i2=-1;
	
	
	switch(testo){
		
	
	case "research":
	var index = Math.round(2*Math.random());
	var testArray = new Array(3);
	testArray[0]=new String("34% of our UK members aged 18 years and more are currently trying to quit smoking");
	testArray[1]=new String("56% of our UK members aged 50 years or more consider their health is excellent.");
	testArray[2]=new String("53% of our UK members look up information on the internet when it comes to health related decisions or treatments");

	
	while(i2==index){index=Math.round(2*Math.random());}
	document.getElementById(id).style.height=height;
	document.getElementById(idTxt).innerHTML =testArray[index] ;
	i2=index;
	break;
	
	case "winners":

	var testArray = new Array("Carrie-Anne H., Brighton<br />Capital Incentives Experience Voucher","Lisa S., Newcastle<br />Capital Incentives Experience Voucher","Amanda K., Milton Keynes<br />£40 gift voucher","nna M., Manchester<br />£40 gift voucher","Kristina G., Cramlington<br />£40 gift voucher","Martine P., Gloucester<br />£40 gift voucher","Julie Y., Biringham<br />£20 gift voucher","Kay W., Gravesend<br />£20 gift voucher","Caroline A., Lincoln<br />£20 gift voucher","Dorothy P., Knaresborough<br />£20 gift voucher","Sian K., Fareham<br />£20 gift voucher","Peter W., Eastbourne<br />£20 gift voucher","Gary T., Carluke<br />£20 gift voucher","Lyn W., Southampton<br />£20 gift voucher","Lynsey C., Liverpool<br />£10 gift voucher","Barbars M., Wolverhampton<br />£10 gift voucher","Angela A., Hull<br />£10 gift voucher","Stephanie B., Aston, Bampton<br />£10 gift voucher","Annette D., Leeds<br />£10 gift voucher","David M., Ellesmere Port<br />£10 gift voucher","Gemma M., Leeds<br />£10 gift voucher","Gill A., Long Eaton<br />£10 gift voucher","Cain F., Glasgow<br />£10 gift voucher","Caroline H, Bradford<br />£10 gift voucher","James G., Wigan<br />£10 gift voucher");
		var index = Math.round((testArray.length-1)*Math.random());
	

	
	while(i2==index){index=Math.round((testArray.length-1)*Math.random());}
	var duration = 1000;  /* 1000 millisecond fade = 1 sec */
      	var steps = 20;       /* number of opacity intervals   */
		y=document.getElementById("winnersbox");
		for (j = 0; j <= 1; j += (1 / steps)) {
          					setTimeout("setOpacity(y," + j + ")", j * duration);
        	}
	document.getElementById(id).style.height=height;
	document.getElementById(idTxt).innerHTML =testArray[index] ;
	i2=index;
	setTimeout('changeTxt("winnersbox","winnersbox","winners","auto")', 3000);
	
	break;
	
	
	case "testimonials":

	var testArray = new Array("When they were asked about which profession they think is most worthwhile, 59% of our panel said Doctors and Nurses.");
		var index = Math.round((testArray.length-1)*Math.random());
	

	
	while(i2==index){index=Math.round((testArray.length-1)*Math.random());}
	var duration = 1000;  /* 1000 millisecond fade = 1 sec */
      	var steps = 20;       /* number of opacity intervals   */
		x=document.getElementById("testimonalTxt");
		for (j = 0; j <= 1; j += (1 / steps)) {
          					setTimeout("setOpacity(x," + j + ")", j * duration);
        	}
	document.getElementById(id).style.height=height;
	document.getElementById(idTxt).innerHTML =testArray[index] ;
	i2=index;
	setTimeout('changeTxt("testimonalTxt","testimonalTxt","testimonials","auto")', 10000);
	
	break;
	
	
	default:
	document.getElementById(id).style.height=height;
	document.getElementById(idTxt).innerHTML =testo ;
	}

	

	
}
/*function to select a value by default in a list*/
function selectOption(num,fieldname)
{
	var selObj = document.getElementById(fieldname);
	selObj.selectedIndex = num;
}
function changeValue(val,fieldname)
{
	var selObj = document.getElementById(fieldname);
	selObj.value = val;
}
/*same as above for a check list
function selectMultipleOptions(num,fieldname,chk0,chk1)
{
	var selObj = document.getElementById(fieldname);
	selObj.options[0].selected = document.getElementById(chk0).checked;
	selObj.options[1].selected = document.getElementById(chk1).checked;

}
*/

function hideQuestions()
{
	if(document.getElementsByTagName)
	{
		arr=document.getElementsByTagName("p");
		for(i=0;i<arr.length;i++){
			if(arr[i].className=="faqP")	
			{
				arr[i].style.display="none";
	

				
			}
		}
	}
}

function questionShow(field,check)
{
				
				
					
	for(i=0;i<field.childNodes.length;i++){
		
		if((field.childNodes[i].nodeName=="P")&&(field.childNodes[i].className=="faqP")){
						
						if(check==0)
						{	
						
						field.childNodes[i].style.display="none";
					

							
						}else{field.childNodes[i].style.display="inline"; 


							}
		}
	}
}

/* set the opacity of the element (between 0.0 and 1.0) */
function setOpacity(element,level) {
        element.style.opacity = level;
        element.style.MozOpacity = level;
        element.style.KhtmlOpacity = level;
        element.style.filter = "alpha(opacity=" + (level * 100) + ");";
		
}
/*check if the field has been hidden or not and than it calls the setOpacity function for each step.*/
function faded(field){
					
		var duration = 1000;  /* 1000 millisecond fade = 1 sec */
      	var steps = 20;       /* number of opacity intervals   */
		for(i=0;i<field.childNodes.length;i++){
		
		 if((field.childNodes[i].nodeName=="P")&&(field.childNodes[i].className=="faqP")){
					
						x=field.childNodes[i];
						if(x.style.display=="none"){
							
							x.style.display="inline"; 
							for (j = 0; j <= 1; j += (1 / steps)) {
          					setTimeout("setOpacity(x," + j + ")", j * duration);
        					}
						}else{       		
						
							for (j = 0; j <= 1; j += (1 / steps)) {
          						setTimeout("setOpacity(x ," + (1 - j) + ")", j * duration);
        					}
         					setTimeout("x.style.display='none'",500);
						}
		 			}
				}
}
//this function uncheck Radio buttons
function unCheckRadio(or) {
	  
	
      for (var i = 0; i < or.length; i++) {
         or[i].checked = false;
		 
     }
}
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";// if is not a radio button
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
		{
			return radioObj.value;}
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			
			return radioObj[i].value;
			
		}
	}
	return "";
}


// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

//check if asda checkboxes are checked as 1 or 3
function asdaCheckedBoxValue(checkObj) {

	var Length = checkObj.length;
	 var chk=0;
	 var blank=0;
	 if(Length==0){return true;}
	for(var i = 0; i < Length; i++) {
		if(checkObj[i].checked)
		{
			
			if((checkObj[i].value==1)||(checkObj[i].value==3))
			{chk++;}
			
		}else{blank++;}
		

	}
	
	if(chk>0){return true;}else{if(blank==Length){return true;}else{return false;}}
}
function timeDifference(laterdate,earlierdate) {
    var difference = laterdate.getTime() - earlierdate.getTime();

    var daysDifference = Math.floor(difference/1000/60/60/24);
    difference -= daysDifference*1000*60*60*24
    /*var hoursDifference = Math.floor(difference/1000/60/60);
    difference -= hoursDifference*1000*60*60
    var minutesDifference = Math.floor(difference/1000/60);
    difference -= minutesDifference*1000*60
    var secondsDifference = Math.floor(difference/1000);*/

    return daysDifference ;
}
//this function is used to check the data that user entered are allowed or not 
function datacheck()
{
	var data = new Array("PGS","SUPERMARKETSMOSTOFTEN","SUPERMARKETSOCCASIONALLY","SUPERMARKETSTOPUP","ASDA_IND","ASDA_OFTEN","EMAIL");
	var chackASDA1,chackASDA2,chackASDA3;
	//start retriving the data
	day=document.getElementsByName("DATE_OF_BIRTH_S2_day")[0].value;
	month=document.getElementsByName("DATE_OF_BIRTH_S2_month")[0].value;
	year=document.getElementsByName("DATE_OF_BIRTH_S2_year")[0].value;
		if((day!="")&&(month!="")&&(year!=""))
	{
	
	 var now=new Date();
     var d= now.getDay();
	 var m= now.getMonth();
	 var y = now.getFullYear();
	 var diff = y-year;
	
	 if(diff <16){
		location.replace("http://asdapulse.co.uk/?action=Main.lobbyGeneral&myContent=what&text=6");return false;
		 }
	 if(diff  >=70){
		  location.replace("http://asdapulse.co.uk/?action=Main.lobbyGeneral&myContent=what&text=6");return false;
		 }
         
	 }
	for (var i = 0; i < data.length; i++)
	{

		var dataField = document.getElementById(data[i]);
		if(dataField){
		
		
		
		
		switch(data[i])
		{
			case data[0]:
			var val= getCheckedValue(document.getElementsByName(data[i]));
			
			if((val == 3))
			{location.replace("http://asdapulse.co.uk/?action=Main.lobbyGeneral&myContent=what&text=6");return false;}
			
			break;
			case data[1]:
			chackASDA1= asdaCheckedBoxValue(document.getElementsByName(data[i]));		
	
			
			break;
			case data[2]:
			chackASDA2= asdaCheckedBoxValue(document.getElementsByName(data[i]));
			
			
			case data[3]:
			chackASDA3= asdaCheckedBoxValue(document.getElementsByName(data[i]));
			
	
			break;
			case data[4]:
			var val= getCheckedValue(document.getElementsByName(data[i]));
			
			if((val < 9))
			{if(val!=""){location.replace("http://asdapulse.co.uk/?action=Main.lobbyGeneral&myContent=what&text=6");return false;}}
			
			break;
			case data[5]:
			var val= getCheckedValue(document.getElementsByName(data[i]));
			
			if((val == 6))
			{location.replace("http://asdapulse.co.uk/?action=Main.lobbyGeneral&myContent=what&text=6");return false;}
			
			break;
			case data[6]:
			var unvalidEmails =new Array("@asda","@tesco","@morrisons","@sainsburys","@somerfield","@netto","@lidl","@next","@currys","@m&s","@MarksandSpencer","@boots","@spar","@budgens","@jackson","@argos","@co-op","@iceland");
			for (var j = 0; j < unvalidEmails.length; j++)
			{
			if(dataField.value.search(unvalidEmails[j])!=-1) 
			{location.replace("http://asdapulse.co.uk/?action=Main.lobbyGeneral&myContent=what&text=6");return false;}
				
			}
			break;
		}
		
	  }
	}
	if((chackASDA1!=true)&&(chackASDA2!=true)&&(chackASDA3!=true)){location.replace("http://asdapulse.co.uk/?action=Main.lobbyGeneral&myContent=what&text=6");return false;}
}

