// 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/62/"; //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","#ffffff","#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","#ffffff","#fff","border  #cccccc");
Rounded("div.generalUP","top","transparent","#fff","big border #cccccc");
Rounded("div.generalDOWN","bottom","transparent","#fff","big border #cccccc");
Rounded("div#researchShow","tl bl br","#ffffff","#fff","big border #cccccc");
Rounded("div.GreyHeader","top","#ffffff","#cccccc","big  border #cccccc");
Rounded("div.top_log","top","#ffffff","#fff","big border #cccccc");
Rounded("div.bottom_log","bottom","#ffffff","#fff","big border #cccccc");
Rounded("div#topCornerQ","tl tr","transparent","#cccccc","border #cccccc");
Rounded("div#bottomCornerQ","bottom","#ffffff","#fff","border  #cccccc");
Rounded("div#tlogo","tl tr","#ffffff","#fff","big border  #cccccc");
Rounded("div#blogo","bl br","#ffffff","#fff","big border  #cccccc");
Rounded("div#bottomCornerR","bl br","#ffffff","#fff","border  #cccccc");
Rounded("div.topL","tl tr","#ffffff","#fff","border #cccccc");
Rounded("div.bottomL","bottom","#ffffff","#cccccc","big");
Rounded("div.topT","tl tr","#ffffff","#fff","border #cccccc");
Rounded("div.bottomT","bottom","#ffffff","#cccccc","border #cccccc");


	

hideBox();
hideQuestions();

}




/*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("NECTARNR_T&"+nectarDropDown+"&1&true","NECTAR_AUTO_PROCESS_T&"+nectarDropDown+"&1&true","NECTAR_ACCEPTANCE_T&"+nectarDropDown+"&1&true");

gr=hidden;
if(document.getElementById)
    {
        
	  
        for(i=0;i<gr.length;i++)
        {
					
			try{
				
				arrays=gr[i].split("&");
				hide=document.getElementById(arrays[0]);//the table to be hidden
				hideElement=document.getElementById(arrays[0].substring(1,arrays[0].length));//substring of table id that gives the element
				checked=document.getElementById(arrays[1]);// the drop down that begin the event
				if(arrays[3]=="true"){
					if((checked.value!=arrays[2]))
					{
						hide.style.display="none"; 
						
						
					}
					else{
						
						hide.style.display="inline"; 
						
						}
						}else{
							if((checked.value!=arrays[2]))
							{
								hide.style.display="inline";
								
							}
							else{
								 if((hideElement.value=="")||(hideElement.value=="999"))
								 {hide.style.display="none";
								  hideElement.options[(hideElement.options.length)-1].selected=true;}

								 
								 
								}
							}
			}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("I have been a member of TNS for over a year now, I always find the surveys interesting and often quite insightful.{...}<br />The best part is spending the points, its amazing how quickly they add up. Being a mother treats are few and far between for myself so all my TNS points are mine to spend as I choose, clothes one month from Debenhams or perfume another from Argos, GREAT!!!! <br /><br /><em>Zoe H.- UK</em>");
	testArray[1]=new String("The best survey has been the one on Health care, some time ago. <br /><br />Regards,<br /><br /><em>Enrico D.- Italy</em>");
	testArray[2]=new String("I am a panel member for quite some time now. This is one of the rare sites that shows professionalism and is quick rewarding members without having to claim anything as with most of the other survey web sites.<br />I always find the surveys interesting and easy to complete [...]. I am very satisfied with this panel and encourage web surfers to subscribe. <br /><br /><em>Joelle H.- France</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 r_NECTAR_NR() {

acceptance=document.getElementById(nectarDropDown).value;
if(acceptance==1){
field=document.getElementById("NECTARNR")	;
 strNectarNumber=field.value;
 strNectarNumber = "98263000" + strNectarNumber;

 if (strNectarNumber.length != 19) {
	field.focus();
	field.select();
	field.style.backgroundColor="#cc0000";
	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) {
	   field.style.backgroundColor="#fff";
	   field.style.color="#777777";
        return true;
       } else {
	
	field.focus();
	field.select();
	field.style.backgroundColor="#cc0000";
	field.style.color="#fff";
        return false;
       }
 }
 else{
        if ((intSum % 10) == intCheckDigit){
		field.style.backgroundColor="#fff";
		field.style.color="#777777";
        return true;
  } else {
	 
  	field.focus();
	field.select();
	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 fade(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);
						}
		 			}
				}
}

