// JavaScript Document

tabscrolling=false
tabpos=1;

function update_recent_from_checkbox(cbox){
		document.forms["admin_form"].s.value=0;
		if(document.getElementById(cbox).value==1) document.getElementById(cbox).value=0; else document.getElementById(cbox).value=1;
		new Ajax.Updater("recent_activity","scripts_from_remote/full_check_admin_pass.php", {asynchronous:true, onComplete:redrawPNGs, parameters:Form.serialize(document.forms["admin_form"])});
	}
	
	function checkAll(num){
		document.forms["admin_form"].s.value=0;
		document.forms["admin_form"].web_videos_watched.value=num;
        document.forms["admin_form"].web_videos_shared.value=num;
        document.forms["admin_form"].media_line_called.value=num;
        document.forms["admin_form"].zyte_avatar_used.value=num;
        document.forms["admin_form"].click_to_call_used.value=num;
        document.forms["admin_form"].click_to_text_used.value=num;
        document.forms["admin_form"].newsletter_requested.value=num;
		new Ajax.Updater("recent_activity", "scripts_from_remote/full_check_admin_pass.php", {asynchronous:true, onComplete:redrawPNGs, parameters:Form.serialize(document.forms["admin_form"])});
	
	}
	
	function update_recent(s){
		document.forms["admin_form"].s.value=s;
		new Ajax.Updater("recent_activity", "scripts_from_remote/full_check_admin_pass.php", {asynchronous:true, onComplete:redrawPNGs, parameters:Form.serialize(document.forms["admin_form"])});
	}
	
	function resetPanelLinks(){
		document.getElementById("activity_detail").style.color="#0000FF";
		document.getElementById("overall_chart").style.color="#0000FF";
		document.getElementById("weekly_graphs").style.color="#0000FF";
	}
	
	function redrawPNGs(){
		
	
		writeImageToDiv("http://www.smartsite.tv/client_sites/shared/panelbottom.png", 227, 11, 0, 0, "panelbottom", 0);
		writeImageToDiv("http://www.smartsite.tv/client_sites/shared/paneltop.png", 227, 11, 0, 0, "paneltop", 0);	
		writeImageToDiv("http://www.smartsite.tv/client_sites/shared/images/panel2_top.png",532, 26, 0, 0, "panel2div", 0);	
	}
	
	function showChart(num, chartURL){
		resetPanelLinks();
		if(num==1) {
			document.getElementById("overall_chart").style.color="#666666";
			document.getElementById("activitydiv").style.display="none";
			document.getElementById("chartsdiv1").style.display="block";
			document.getElementById("chartsdiv2").style.display="none";
			document.getElementById("chartsdiv3").style.display="none";
			document.getElementById("chartsdiv4").style.display="none";
			if(document.getElementById("chartsframe1").src=='') document.getElementById("chartsframe1").src=chartURL;
			
	
		}else if (num==2){
			document.getElementById("weekly_graphs").style.color="#666666";
			document.getElementById("activitydiv").style.display="none";
			document.getElementById("chartsdiv1").style.display="none";
			document.getElementById("chartsdiv2").style.display="block";
			document.getElementById("chartsdiv3").style.display="none";
			document.getElementById("chartsdiv4").style.display="none";
			if(document.getElementById("chartsframe2").src=='') document.getElementById("chartsframe2").src=chartURL;
			
	
		}else if (num==3){
			document.getElementById("referral_graph").style.color="#666666";
			document.getElementById("activitydiv").style.display="none";
			document.getElementById("chartsdiv1").style.display="none";
			document.getElementById("chartsdiv2").style.display="none";
			document.getElementById("chartsdiv3").style.display="block";
			document.getElementById("chartsdiv4").style.display="none";
			if(document.getElementById("chartsframe3").src=='') document.getElementById("chartsframe3").src=chartURL;
			
	
		}else if (num==4){
			document.getElementById("referral_graph").style.color="#666666";
			document.getElementById("activitydiv").style.display="none";
			document.getElementById("chartsdiv1").style.display="none";
			document.getElementById("chartsdiv2").style.display="none";
			document.getElementById("chartsdiv3").style.display="none";
			document.getElementById("chartsdiv4").style.display="block";
			if(document.getElementById("chartsframe4").src=='') document.getElementById("chartsframe4").src=chartURL;
			
	
		}else {
			document.getElementById("activity_detail").style.color="#666666";
			document.getElementById("activitydiv").style.display="block";
			document.getElementById("chartsdiv1").style.display="none";
			document.getElementById("chartsdiv2").style.display="none";
			document.getElementById("chartsdiv3").style.display="none";
			document.getElementById("chartsdiv4").style.display="none";
		}
		
		
		
	
	}
	
	function send_pass(){
		document.forms["admin_form"].s.value=0;	
		document.getElementById("admin2").style.display="none";
		document.getElementById("admin1").style.display="block";
		new Ajax.Updater("recent_activity", "scripts_from_remote/full_check_admin_pass.php", {asynchronous:true, parameters:Form.serialize(document.forms["admin_form"]), onComplete:showAdmin});
		
	
	}
	
	function open_admin_pass(){
		document.getElementById("admin2").style.display="block";
		document.getElementById("admin1").style.display="none";
	}
	
	function stripWhitespace(word){
	  word= word.replace(/ /g, "");
	   word= word.replace(/\n/g, "");
	  return word.replace(/\r/g, "");
     }
	 
	 function slide_tab_left(){
		 if(tabscrolling==true || tabpos==1) return;
		 tabscrolling=true;
		 
		 tabpos--;
		
		 if(tabpos==1 && document.getElementById("tab_arrow_left")!=null){ document.getElementById("tab_arrow_left").src="http://www.smartsite.tv/client_sites/shared/images/gray_arrow_left.jpg";}
		 else if (document.getElementById("tab_arrow_left")!=null){ document.getElementById("tab_arrow_left").src="http://www.smartsite.tv/client_sites/shared/images/blue_arrow_left.jpg";}
		 if (document.getElementById("tab_arrow_right")!=null){ document.getElementById("tab_arrow_right").src="http://www.smartsite.tv/client_sites/shared/images/blue_arrow_right.jpg";}
		 
		 new Effect.Move ('tabscoller',{ x: 490, y: 0, duration:.7, mode: 'relative', afterFinish:function(){tabscrolling=false;}});
		 document.forms["admin_form"].tab_pos.value=tabpos;
	 }
	 
	 function slide_tab_right(){
		 if(tabscrolling==true  || tabpos==2 ) return;
		 tabscrolling=true;
		 tabpos++;
		 
		 if(tabpos==2 && document.getElementById("tab_arrow_right")!=null){ document.getElementById("tab_arrow_right").src="http://www.smartsite.tv/client_sites/shared/images/gray_arrow_right.jpg";}
		 else if (document.getElementById("tab_arrow_right")!=null){ document.getElementById("tab_arrow_right").src="http://www.smartsite.tv/client_sites/shared/images/blue_arrow_right.jpg";}
		 if (document.getElementById("tab_arrow_left")!=null){ document.getElementById("tab_arrow_left").src="http://www.smartsite.tv/client_sites/shared/images/blue_arrow_left.jpg";}
		 
		 new Effect.Move ('tabscoller',{ x: -490, y: 0, duration:.7, mode: 'relative', afterFinish:function(){tabscrolling=false;}});
		 document.forms["admin_form"].tab_pos.value=tabpos;
	 }
	
	function showAdmin(){
	
		if(stripWhitespace(document.getElementById("recent_activity").innerHTML)!=""){
			if(browserName=="Explorer"){
				if(	Number(browserVersion<7)){
					document.getElementById("admin_panel").style.position="absolute";
					document.getElementById("admin_panel").style.top="-390px";
					document.getElementById("admin_panel").style.left="0px";
				}
			}
			
			document.getElementById("admin_panel").style.display="block";
			
			new Effect.Move ('admin_panel_back',{ x: 0, y: -467, duration:.7, mode: 'relative'});
	
			if(document.getElementById("footer_div")) document.getElementById("footer_div").style.zIndex=999;
		

			writeImageToDiv("http://www.smartsite.tv/client_sites/shared/panelbottom.png", 227, 11, 0, 0, "panelbottom", 0);
			writeImageToDiv("http://www.smartsite.tv/client_sites/shared/paneltop.png", 227, 11, 0, 0, "paneltop", 0);
			writeImageToDiv("http://www.smartsite.tv/client_sites/shared/images/panel2_top.png", 532, 26, 0, 0, "panel2div", 0);	
			
			//The admin panel has just been opened, so any video content that needs to be closed should be closed now. Go through the array of closing functions and run them.
			for(i=0;i<turnOffForAdminFunctions.length;i++){
				turnOffForAdminFunctions[i]();	
			}
	
		}
		
	}

	function hideAdmin(){	
			
			new Effect.Move ('admin_panel_back',{ x: 0, y: 467, duration:.7, mode: 'relative', afterFinish:function(){
				document.getElementById("admin_panel").style.display="none";
				document.getElementById("recent_activity").innerHTML="";
				if(document.getElementById("footer_div")) document.getElementById("footer_div").style.zIndex=0;
			}});

	}