// JavaScript Document
function checkBrowser(){
	var ua = navigator.userAgent.toLowerCase();
	if(ua.indexOf("msie 8.0")>=0){
		return "ie8";
		}
	if(ua.indexOf("msie 7.0")>=0){
		return "ie7";
		}
	if(ua.indexOf("msie 6.0")>=0){
		return "ie6";
		}
	if(ua.indexOf("firefox")>=0){
		return "firefox";
		}
	if(ua.indexOf("chrome")>=0){
		return "chrome";
		}
	if(ua.indexOf("safari")>=0){
		return "safari";
		}
	}
	
function scrollUp(){
	var target = document.getElementById("pt_scroll_imgs");
	type=checkBrowser();
	//alert(target.offsetTop);
	switch (type){
		case "ie6" :
		//target.style.marginTop=(target.offsetTop -81)+"px"
		if(target.offsetHeight+target.offsetTop>567){
		  target.style.marginTop=(target.offsetTop -81)+"px";
		  }else{
			  target.style.marginTop=target.offsetTop+"px";
			  }0
		break;
		case "ie7" :
		//target.style.marginTop=(target.offsetTop -81)+"px";
		if(target.offsetHeight+target.offsetTop>567){
		  target.style.marginTop=(target.offsetTop -81)+"px";
		  }else{
			  target.style.marginTop=target.offsetTop+"px";
			  }
		break;
		case "ie8" :
		//target.style.marginTop=(target.offsetTop-460 -81)+"px";
		if(target.offsetHeight+target.offsetTop-460 -81>567){
		  target.style.marginTop=target.offsetTop-460 -81+"px";
		  }else{
			  target.style.marginTop=target.offsetTop-460+"px";
			  }		
		break;
		case "firefox" :
		//target.style.marginTop=(target.offsetTop-460 -81)+"px";
		if(target.offsetHeight+target.offsetTop-460 -81>567){
		  target.style.marginTop=target.offsetTop-460 -81+"px";
		  }else{
			  target.style.marginTop=target.offsetTop-460+"px";
			  }			
		break;
		case "chrome" :
		//target.style.marginTop=(target.offsetTop-462 -79)+"px";
		if(target.offsetHeight+target.offsetTop-462 -81>567){
		  target.style.marginTop=target.offsetTop-462 -81+"px";
		  }else{
			  target.style.marginTop=target.offsetTop-462+"px";
			  }			
		break;
		default :
		//target.style.marginTop=(target.offsetTop-460 -81)+"px";
		if(target.offsetHeight+target.offsetTop-460 -81>567){
		  target.style.marginTop=target.offsetTop-460 -81+"px";
		  }else{
			  target.style.marginTop=target.offsetTop-460+"px";
			  }			
		break;
		}

	}
function scrollDown(){
	var target = document.getElementById("pt_scroll_imgs");
	type=checkBrowser();
	//alert(target.offsetTop+"/"+target.scrollHeight);
	switch (type){
		case "ie6" :
		if(target.offsetTop<0){
			target.style.marginTop=(target.offsetTop +81)+"px";
			}else{
				target.style.marginTop=target.offsetTop;
				}
		break;
		case "ie7" :
		if(target.offsetTop<0){
			target.style.marginTop=(target.offsetTop +81)+"px";
			}else{
				target.style.marginTop=target.offsetTop;
				}
		break;
		case "ie8" :
		if(target.offsetTop<460){
		  target.style.marginTop=(target.offsetTop-460 +81)+"px";
		  }else{
			  target.style.marginTop=target.offsetTop-460;
			  }
		break;
		case "firefox" :
		if(target.offsetTop<460){
		  target.style.marginTop=(target.offsetTop-460 +81)+"px";
		  }else{
			  target.style.marginTop=target.offsetTop-460;
			  }
		break;
		case "chrome" :
		if(target.offsetTop<462){
		   target.style.marginTop=(target.offsetTop-462 +81)+"px";
		   }else{
			   target.style.marginTop=target.offsetTop-462;
			   }
		break;
		default :
		if(target.offsetTop<460){
		  target.style.marginTop=(target.offsetTop-460 +81)+"px";
		  }else{
			  target.style.marginTop=target.offsetTop-460;
			  }
		break;
		}

	}	
	//target.style.marginTop=(target.offsetTop -81)+"px";//IE6,IE7
	//target.style.marginTop=(target.offsetTop-460 -81)+"px";//IE8,ff
	//target.style.marginTop=(target.offsetTop-462 -81)+"px";//Chrome

function checkRadioChecked(){
	result = checkAllAnswered();
	if(result !=-1){
		document.getElementById("result"+ result).style.display="block";
		document.getElementById("submitbutton").style.display="none";
		}
	else showPopupLayer('layerForm', Alert.Message.Question);
}	


function checkAllAnswered(){
	anscnt=0;lastans='';
	var answers = new Array; var votes = new Array;
	for(var i=1; i<100; i++){
		if((document.getElementById(i)) != null){
			if(lastans != document.getElementById(i).name){ //only save question to array once
				lastans = answers[anscnt] = document.getElementById(i).name;
				anscnt++;
			}
		}
	}
	//alert(document.getElementsByName("test1").length);
	A=0; B=0; C=0;
	for(var i=0;i<answers.length;i++){
		thisanswer = testfunc(answers[i]);
		if (thisanswer ==-1){
			//nothing selected for a value so return false
				return -1;
			}
		else{
				//add to selected value
				switch(thisanswer){
					case 'A': A++; break;
					case 'B': B++; break;
					case 'C': C++; break;
				}
		}
	}
	//get average
	//alert("A="+A+" B="+B+" C="+C);
	var returnval = -1; //just in case!
	
	result = Math.max(Math.max(A,B),C);
	if(A == result)
		returnval = (C == result)? 2 : 0; //C stronger than A
	else if (B == result)
		returnval = (A == result)? 0 : 1; //A stronger than B
	else if (C == result)
		returnval = (B == result)? 1 : 2; // B stronger than C
	
	
	return returnval;
}

function testfunc(target){
		for(var j=0;j<document.getElementsByName(target).length;j++){
			if(document.getElementsByName(target)[j].checked==true)
				return document.getElementsByName(target)[j].className; //return vote val A B or C
		}
		return -1; //nothing selected
}


function checkanswer(target){
	for(var j=0;j<document.getElementsByName(target).length;j++){
		if(document.getElementsByName(target)[j].checked==true){
			return true;
		}
		else{
				//return false;
		}
	}
}

	
function showhint(obj,obj2,index){
	var  correctAnswer = new Array();
	for(var i=0; i<$(".testsblock").length;i++){
		correctAnswer.push($(".testsblock").eq(i).find("input").val());
	}
	var target = document.getElementById(obj);
	target.className="cir_showhint";
	
	var target2 = document.getElementById(obj2+"_"+(correctAnswer[index]));
	target2.className="cir_radio_label_on";
	}

	
	
	
	
	
//for FAQ1.html

function faq_showdiv(obj,obj2,obj3){
	var targets= ["faq","faq2","faq3","faq4","faq5"];
	var bars=["faq_con_01","faq_con_02","faq_con_03","faq_con_04","faq_con_05"];
	var imgs = ["faq_img_01","faq_img_02","faq_img_03","faq_img_04","faq_img_05"];
	var target = document.getElementById(obj);
	var target2 = document.getElementById(obj2);	
	for(var j=0;j<bars.length;j++){
		if(obj3!="faq_con_01"){
			document.getElementById("faq_con_01").className="faq_con_01";
			document.getElementById(bars[j]).className="faq_con_02";
			}
		else{
		  document.getElementById("faq_con_01").className="faq_con_01_focus";
		  document.getElementById(bars[j]).className="faq_con_02";
		   }
		}
	for(var i=0;i<imgs.length;i++){
		  document.getElementById(imgs[i]).className="faq_btn";
		}
	for(var i=0;i<targets.length;i++){
		document.getElementById(targets[i]).style.display="none";
		}		
	if(obj3=="faq_con_01"){
		document.getElementById(obj3).className="faq_con_01_focus";
		}else{
			document.getElementById(obj3).className="faq_con_02_focus";
			}
	target2.className="faq_btn_down";
	target.className="faq_per";
	target.style.display="block";
}
/********************************jQuery******************************************/




function itemLoadCallbackFunction(){
	var car = $("#mycarousel").get(0);
	var itemcount = $("#mycarousel").find("li").length;
	car.clientHeight<car.scrollHeight ? getBtnHidden():getBtnShow();
	}
    
function getBtnShow(){
	var $next=$("#wrap").find(".jcarousel-next-vertical");
	var $prev=$("#wrap").find(".jcarousel-prev-vertical");
	$next[0].style.visibility="visible";
	$prev[0].style.visibility="visible";
	}
function getBtnHidden(){
	var $next=$("#wrap").find(".jcarousel-next-vertical");
	var $prev=$("#wrap").find(".jcarousel-prev-vertical");
	$next[0].style.visibility="hidden";
	$prev[0].style.visibility="hidden";	
	}
/********************************Slide Down Menu*************************************************/	
function createSlideDownMenu(){
	$("#menu>ul>li>.nav_down_menu").hide();
	var index=0;
	var indexArray = new Array();
	$("#menu>ul>li").hover(function(){
									index= $("#menu>ul>li").index($(this));
									$("#menu>ul>li").eq(index).find(".nav_down_menu").show();
									$(this).addClass("hover_conseils");
									indexArray.push(index);
									},function(){
										var innerArray = new Array();
										for(var j=0;j<indexArray.length;j++){
											innerArray[j]=indexArray[j]
											}
										$("#menu>ul>li").eq(index).find(".nav_down_menu").hide();
										for(var i=0;i<innerArray.length;i++){
											 setTimeout(function(){$("#menu>ul>li").eq(innerArray[i-1]).removeClass("hover_conseils");},0);
										}
									
										
										indexArray= new Array();;
									
										});
	
	
	$("#nav_down_img_container").corner("5px");
	$("#nav_down_img_container2").corner("5px");
	$("#nav_down_img_container3").corner("5px");
	changeImageURL1();
	changeImageURL2();
	changeImageURL3();
	}

function changeImageURL1(){
	var imgurls=$("#nav_down_img_container>img");
	$("#m_menu_01>div>div>div>p>a").mouseover(function(){
													   $("#nav_down_img_container>img").hide();
													 	$("#nav_down_img_container>img").eq($("#m_menu_01>div>div>div>p>a").index($(this))).show();
													   })
	}
function changeImageURL2(){
	var imgurls=$("#nav_down_img_container2>img");
	$("#m_menu_02>div>div>div>p>a").mouseover(function(){
													   $("#nav_down_img_container2>img").hide();
													   $("#nav_down_img_container2>img").eq($("#m_menu_02>div>div>div>p>a").index($(this))).show();
													   })
	}
function changeImageURL3(){
	var imgurls=$("#nav_down_img_container3>img");
	$("#m_menu_03>div>div>div>p>a").mouseover(function(){
													   $("#nav_down_img_container3>img").hide();
													   $("#nav_down_img_container3>img").eq($("#m_menu_03>div>div>div>p>a").index($(this))).show();
													   })
	}
/*********************************ROUND CORNER**************************************************/
function round2(imgCLass, option, parentPath){
	
	var img = $("img." + imgCLass);	
	img.css({
			"cursor" : "pointer"
			})
	if(img.length > 0){
		if(img.height()==61){
		var img_con=$('<div class="s_'+imgCLass+'" style="height:'+img.height()+'px; margin-right:10px; width:'+img.width()+'px; background:url(images/blank.gif);overflow:hidden;"></div>')}else{
		var img_con=$('<div class="s_'+imgCLass+'" style="height:'+img.height()+'px; width:'+img.width()+'px; background:url(images/blank.gif);overflow:hidden;"></div>')	
			};
		img.wrap(img_con);
		$(".s_"+imgCLass).corner(option);		
	}
}

function roundCorner(){
	
	round2('roundCorners2', '10px cc:#F1DDE6', '.lestest_body_left');
	//round2('roundCorners2', '10px');
	round2('roundRightBottom', 'round br 30px');
	round2('roundTop', 'round tl tr 10px');
	round2('roundTop2', 'round tl tr 15px');
	round2('roundedCorner', 'round 10px');
	round2('roundRightBottom2', 'round br 25px');
	round2('roundLeft', 'round bl 25px');
	round2('roundCircle', 'round');

}
//fix the link can't be clicked in IE6 and IE7
function fixLink(n){
	if(checkBrowser()=="ie6"||checkBrowser()=="ie7"){
	    window.open($(n).parent().parent().attr("href"));
	  }
	}
	
//tab funtions
tabViews("#ccd_viewStacks","#ccd_imgs");
tabViews2("#czm_viewStacks","#czm_middle_imglinks");
function tabViews(target,tab){

	var tabNum= $(tab+">a").length;
	$(target+">div").hide();
	$(target+">div").eq(0).show();
	$(tab+">a").click(function(){
									for(var i=0;i<tabNum;i++){
										$(target+">div").eq(i).hide();
										$(tab+">a>span").eq(i).removeClass("ccd_current");
										}
									$(target+">div").eq($(tab+">a").index($(this))).show();
									$(tab+">a>span").eq($(tab+">a").index($(this))).attr("className","ccd_current");
									return false;
									})
	}
function tabViews2(target,tab){

	var tabNum= $(tab+">a").length;

	$(target+">div").hide();
	$(target+">div").eq(0).show();
	$(tab+">a").click(function(){
									for(var i=0;i<tabNum;i++){
										$(target+">div").eq(i).hide();
										$(tab+">a>p").eq(i).removeClass("ccd_current");
										}
									$(target+">div").eq($(tab+">a").index($(this))).show();
									$(tab+">a>p").eq($(tab+">a").index($(this))).attr("className","ccd_current");
									return false;
									})
	}	