// JavaScript Document



	/*for testing purpose on live panel

	fullURL = parent.document.URL;

	testURL=fullURL.split('loc=en_')[1];

	*/

	  country="uk";	

      URLpath="http://";   

      path="/view/images/185/"; //images server path.   

      adImages = new Array("logoSmall.gif","logoSmall1.gif","logoSmall2.gif","logoSmall3.gif","logoSmall4.gif","logoSmall5.gif","logoSmall6.gif","logoSmall7.gif");//array of images, in case we want to use more images we need to add the name of the file here

      adURL= "/?action=Main.lobbyGeneral&myContent=REWARD";//new Array("");this is the related url of the images !important the position in the array needs to be the same of the image

      thisAd=0;

      imgL=adImages.length;

      timerID=0;

      nImages= new Array(imgL);

	//here we load the images, so when the are called by js they are already in the cache

     for(i=0;i<imgL;i++ ){

     nImages[i]=new Image;

     nImages[i].src=path+adImages[i];	

      }

     var mobileGroup= new Array("");	

	 var i2=-1;

	 errcount=0;

	 var nectarDropDown="NECTAR_NO_0";

	

    

window.onload=function(){



banner();

if(!NiftyCheck())

    return;



//script for the smooth edges (element that needs to have smooth edges, position inner color,out color, type)

Rounded("div.topCornerR","top","#FCF4F5","#fff","border #cccccc");

Rounded("div.smallBox_L","all","transparent","#fff","big border #cccccc");

Rounded("div.smallBox_R","all","transparent","#fff","big border #cccccc");

Rounded("div#bottomEdgeQ","bottom","#FCF4F5","#fff","border  #cccccc");

Rounded("div.generalUP","tr","transparent","#fff","big border #cccccc");

Rounded("div.generalDOWN","bottom","transparent","#fff","big border #cccccc");

Rounded("div#researchShow","tl bl br","#FCF4F5","#fff","big border #cccccc");

Rounded("div.GreyHeader","top","#FCF4F5","#cc0000","big  border #cccccc");

Rounded("div.top_log","top","#FCF4F5","#fff","big border #cccccc");

Rounded("div.bottom_log","bottom","#FCF4F5","#fff","big border #cccccc");

Rounded("div#topCornerQ","tl tr","transparent","#cc0000","border #cccccc");

Rounded("div#bottomCornerQ","bottom","#FCF4F5","#fff","border  #cccccc");

Rounded("div#tlogo","tl tr","#FCF4F5","#fff","big border  #cccccc");

Rounded("div#blogo","bl br","#FCF4F5","#fff","big border  #cccccc");

Rounded("div#bottomCornerR","bl br","#FCF4F5","#fff","border  #cccccc");

Rounded("div.topL","tl tr","#FCF4F5","#fff","border #cccccc");

Rounded("div.bottomL","bottom","#FCF4F5","#cccccc","big");

Rounded("div.topT","tl tr","#FCF4F5","#fff","border #cccccc");

Rounded("div.bottomT","bottom","#FCF4F5","#cccccc","border #cccccc");





	


hideBox();

hideQuestions();

hideRefer();

}









/*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&NECTARNR_T&"+nectarDropDown,"h&NECTAR_AUTO_PROCESS_T&"+nectarDropDown,"h&NECTAR_ACCEPTANCE_T&"+nectarDropDown,"h2&PENSION_0_T&EMPL_0","h2&PENSION_CIE_0_T&EMPL_CIE_0","h3&STUDYTYPE_T&EMPL_0","h3&STUDYTYPE_CIE_T&EMPL_CIE_0","h4&UNEMPLOYED_0_T&EMPL_0","h4&UNEMPLOYED_CIE_0_T&EMPL_CIE_0","h&OCCUPATION_T&EMPL_0","h&OCCUPATION_CIE_T&EMPL_CIE_0","h&OCCUPATION_T&PENSION_0","h&OCCUPATION_CIE_T&PENSION_CIE_0","h&OCCUPATION_T&UNEMPLOYED_0","h&OCCUPATION_CIE_T&UNEMPLOYED_CIE_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 ...

				var key;//var to block the function 0  if 1 is ok

				var element;// this is the variable used to store the value of the element that needs to be checked in order to set the key.

				switch(arrays[2])

				{

					case "PENSION_0":

					element=document.getElementById("EMPL_0").value;

					if((element=="4_h2"))

				    {key=1;}else{key=0;}

					break;

					case "PENSION_CIE_0":

					element=document.getElementById("EMPL_CIE_0").value;

					if((element=="4_h2"))

				    {key=1;}else{key=0;}

					break;

					case "UNEMPLOYED_0":

					element=document.getElementById("EMPL_0").value;

					if((element=="9_h4"))

				    {key=1;}else{key=0;}

					break;

					case "UNEMPLOYED_CIE_0":

					element=document.getElementById("EMPL_CIE_0").value;

					if((element=="9_h4"))

				    {key=1;}else{key=0;}

					break;

					

					

					default:

					key=1;

				}

				

				

	

				

				

				if((key==1)&&(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){}

			

		

        }



	



    }

}// banner, next and prev are just rolling over the images and the url

function banner(){

    





     if(document.getElementById){

                

                    

                

                if(thisAd >= imgL-4){thisAd=0;}

                

                document.getElementById("iad1").src=path+adImages[thisAd];

                

                document.getElementById("iad2").src=path+adImages[thisAd+1];

                

                document.getElementById("iad3").src=path+adImages[thisAd+2];

                document.getElementById("iad4").src=path+adImages[thisAd+3];

				document.getElementById("iad5").src=path+adImages[thisAd+4];

                document.getElementById("ad1").href=adURL;

                document.getElementById("ad2").href=adURL;

                document.getElementById("ad3").href=adURL;

                document.getElementById("ad4").href=adURL;

				document.getElementById("ad5").href=adURL;

                thisAd++;

                  

                            }

        

        timerID=setTimeout("banner()",6*1000);

         

}



function next()

{

     if(document.getElementById){

                

                    

                

                

                if(thisAd >= imgL-4){thisAd=0;}

               

                document.getElementById("iad1").src=path+adImages[thisAd];

                

                document.getElementById("iad2").src=path+adImages[thisAd+1];

                

                document.getElementById("iad3").src=path+adImages[thisAd+2];

                

                document.getElementById("iad4").src=path+adImages[thisAd+3];

                document.getElementById("iad5").src=path+adImages[thisAd+4];

				

                document.getElementById("ad1").href=adURL;

                document.getElementById("ad2").href=adURL;

                document.getElementById("ad3").href=adURL;

                document.getElementById("ad4").href=adURL;

				document.getElementById("ad5").href=adURL;

                thisAd++;

                

                }

            

        clearTimeout(timerID);

        

}





function prev()

{

     if(document.getElementById){

                

                    

                

                

                

                if(thisAd <= 4){thisAd=imgL;}

                document.getElementById("iad1").src=path+adImages[thisAd];

                document.getElementById("iad2").src=path+adImages[thisAd-1];

                document.getElementById("iad3").src=path+adImages[thisAd-2];

                document.getElementById("iad4").src=path+adImages[thisAd-3];

                document.getElementById("iad5").src=path+adImages[thisAd-4];

                document.getElementById("ad1").href=adURL;

                document.getElementById("ad2").href=adURL;

                document.getElementById("ad3").href=adURL;

                document.getElementById("ad4").href=adURL;

				document.getElementById("ad5").href=adURL;

                thisAd--;

                

            }

        clearTimeout(timerID);

        

}













function Validate(theForm){



	if (theForm.username.value == ''){



		alert("Please enter a valid user name.");



		theForm.username.focus();



		return false;



	}//end if



	if (theForm.userPassword.value == ''){



		alert("Please enter a valid password.");



		theForm.userPassword.focus();



		return (false);



	}//end if







	return true;



}//end function







function Submit(theForm){



	if(Validate(theForm)){



		document.formLogin.submit();



	}//end if



}//en dfunction





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 "testimonials":

	var index = Math.round(2*Math.random());

	var testArray = new Array(3);

	testArray[0]=new String("&quot;Thank you for taking the time to reply in such a detailed manner. I'm a member of several survey panels[...] but your e-mail is the first reply I've received. A good sign, which means I'll be pleased to complete the application process with MySurvey UK and become a regularly contributing member. It's the little things in life, like your personal response, which make a big difference to me in this increasingly impersonal world!&quot; <br /><em>Colin B, Cumbria</em>");

	testArray[1]=new String("&quot;I just wanted to say a big <br /><br /><strong>THANK YOU</strong><br/><br /> for the prize of 10,000 MySurvey points!<br /><br />Greetings from Bielefeld.&quot;<br /><br /><em>Mike M, Germany<br />Winner in the Participant's Prize Draw</em>");

	testArray[2]=new String("&quot;I always enjoy doing Mysurvey surveys as they're very user friendly. Keep up the good work!<br /><br />Thank you for your help!&quot;<br /><br /><em>Maria P, Leigh-on-Sea</em>");

	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 "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;

	

	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 r_NECTAR_NR() {



acceptance=document.getElementById(nectarDropDown).value;

if(acceptance==2){ 

					

					selectOption('2','NECTAR_AUTO_PROCESS');

	                

					

					selectOption('0','NECTAR_ACCEPTANCE');

	             

					

					changeValue('','NECTARNR');

	               

					

					return true;

				  }

else{

	

field=document.getElementById("NECTARNR")	;

 strNectarNumber=field.value;

 strNectarNumber = "98263000" + strNectarNumber;



 if (strNectarNumber.length != 19) {

	field.focus();

	field.select();

	document.getElementById('uerror').style.display="inline";

	field.style.backgroundColor="#cc0000";

	field.value="Enter your nectar number";

	field.style.color="#fff";

  return false;

 }

 var intSum = 0;

 var intMulti = 2;

 var intLength = strNectarNumber.length;

 for (i = 1; i < 19; i++) {

 intDigit = strNectarNumber.substring(intLength-i-1, intLength-i);

  intProduct = parseInt(intDigit, 10) * intMulti;

  if (intProduct >= 10) {

   intSum += (intProduct % 10) + 1;

  } else {

   intSum += intProduct;

  }

  if (intMulti == 1) {

  intMulti++;

 } else {

  intMulti--;

 }

 }

 var intCheckDigit = strNectarNumber.substring(intLength-1, intLength);

 if ((intSum % 10) !=0){

       if (10 - (intSum % 10) == intCheckDigit) {

	   document.getElementById('uerror').style.display="none";

	   field.style.backgroundColor="#fff";

	   

	   field.style.color="#777777";

        return true;

       } else {

	

	field.focus();

	field.select();

	document.getElementById('uerror').style.display="inline";

	field.value="Enter your nectar number";

	field.style.backgroundColor="#cc0000";

	field.style.color="#fff";

        return false;

       }

 }

 else{

        if ((intSum % 10) == intCheckDigit){

			document.getElementById('uerror').style.display="none";

			

		field.style.backgroundColor="#fff";

		field.style.color="#777777";

        return true;

  } else {

	 

  	field.focus();

	field.select();

	document.getElementById('uerror').style.display="inline";

	field.value="Enter your nectar number";

	field.style.backgroundColor="#cc0000";

	field.style.color="#fff";

	

        return false;

		

  }

 }

}

}

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 "";

}

//don t used

// 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;

		}

	}

}

//function used to hide and show tables on the refer a friend page check that the first hiderefer is on the onload function

function hideRefer()

{

	try{

	document.getElementById('buttons').style.display='none';

	refervariable=document.getElementsByTagName('table');

	for(i=0;i<refervariable.length;i++){

		if(refervariable[i].className=="fields"){ refervariable[i].style.display='none'}

	}}catch(e){}

}

function showref(value)

{

	if((value!="")||(value>=2)){

		refervariable=document.getElementsByTagName('table');

		

	for(j=0;j<value;j++){

		

		if(refervariable[j].className=="fields"){

			

			refervariable[j].style.display='block';document.getElementById('buttons').style.display='block';}

	   }

	}

}



function createCookie(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 readCookie(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 false;

}



function eraseCookie(name) {

	createCookie(name,"",-1);

}

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 clearField(identificator)
{
	/*test if the element has an id or not*/
	if($(identificator))
	{
	var el=$(identificator);	
	/*test what kind of type is the element*/
	
	switch(el.type)
	{
		case "select-one": 
		el.selectedIndex=0;
  		break;
		default:
		el.value="";
		break;
	}
			
	}else{
			
			var el=$$("."+identificator);
			el.each(function(item){
							 	item.checked = false;
							 	});
				
		}
		
}
