// JavaScript Document
// pop up script -- start //
var sUserAgent = navigator.userAgent.toLowerCase();
var isOp = (sUserAgent.indexOf('opera')!=-1)?true:false;
function pop(oAnchor,sProps,sWindow){
	var sUrl = '';
	if(oAnchor.getAttribute) sUrl = oAnchor.getAttribute('href');
	if(sUrl=='') sUrl = oAnchor.href;
	if(sUrl=='') return true;
	var sWindowName = sWindow?sWindow:'reusedWindow';
	if(!sProps) sProps = null;
	
	// get digits out of passed props for width and height
	var sPropsdigits = new Array();
	sPropsdigits = sProps.match(/\d+/g); //returns the array [8,15]
	var pLeft = (screen.width - sPropsdigits[0])/2;
	var pTop = (screen.height - sPropsdigits[1])/2;
	
	// add left and top positions to sProps for centering window
	sProps += ', left = ' + pLeft + ',top=' + pTop;

	if(sUrl) var oPopup = window.open(sUrl,sWindowName,sProps);
	if(oPopup && !isOp) oPopup.focus();
	if(!oPopup){
		alert("Please disable your popup blocking software.");
	}
	return (oPopup)?false:true;
}
function switchImg(sImg,sSrc){
	oImg = document.images[sImg];
	return !(oImg.src = 'img/' + sSrc);
}
function verifyKey(oElement,oEvent){
	if(oEvent.keyCode==13 && oElement.onclick) oElement.onclick();
}
// pop up script -- end //



//new pop up script //


var win = null;
function newWindow(mypage,myname,w,h,features) {
	//alert("dfghdfghdfg");
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}


// end new pop up script ////



//Gets the browser specific XmlHttpRequest Object
// *** ajax DOM test *** //
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		 //Internet Explorer
		 try {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		 }
	}
	return xmlHttp;
}

function showLoggedIn(){
	xmlHttp2=GetXmlHttpObject()
	if (xmlHttp2==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	var url ="./includes/logged_in.inc.php";
	var data = "&ajax_id="+Math.random()
	xmlHttp2.onreadystatechange=stateChangedLoggedIn
	
	xmlHttp2.open('GET', url, true);
	xmlHttp2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp2.send(data);
	return false;
}

function stateChangedLoggedIn() 
{ 
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
	{ 
		document.getElementById("log").innerHTML=xmlHttp2.responseText;
		window.location = "/";

		
	} else {
		document.getElementById("log").innerHTML="Loading ...";

	}
}

// *** Ajax for Login form *** //
function aztvlogin(){
	
	document.getElementById("login_error").innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	var username = document.frmlogin.username.value;
	var user_password = document.frmlogin.user_password.value;
	var login = document.frmlogin.login.value;
	
	var url ="./includes/actions/login.php";
	var data = "username="+username+"&user_password="+user_password+"&login="+login;
	data = data + "&ajax_id="+Math.random()
	xmlHttp.onreadystatechange=stateChangedlogin
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedlogin() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText == "success"){
			// if successful, show the login form
			showLoggedIn();
		} else {
			// if not, show the error message
			document.getElementById("login_error").innerHTML=xmlHttp.responseText;
		}
	} else {
		document.getElementById("login_error").innerHTML="Sending request ...";

	}
}
// *** Ajax for Login form *** //

// *** Ajax for Submit Comment form *** //
function submitCommentForm()
{ 
	document.getElementById("submit_comments").innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	var comment = document.commentform.comment.value;
	var comment_name = document.commentform.comment_name.value;
	var comment_email = document.commentform.comment_email.value;
	var episode_id = document.commentform.episode_id.value;
	var channel_id = document.commentform.channel_id.value;
	
	var url ="/includes/actions/submit_comment.inc.php";
	var data = "comment="+comment+"&comment_name="+comment_name+"&comment_email="+comment_email+"&episode_id="+episode_id+"&channel_id="+channel_id;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedCommentsubmit
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedCommentsubmit() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	if(xmlHttp.responseText == "success"){
		document.getElementById("success").innerHTML=" <div id='success'><p>Crikey! Thanks for the comment. We look forward to reviewing your comment and having it online as soon as possible</p></div>"
		document.getElementById("commentform").innerHTML=""
	} else {
		document.getElementById("submit_comments").innerHTML=xmlHttp.responseText
	}
	} else {
		document.getElementById("submit_comments").innerHTML="<div style='border:1px dashed red;color:red;padding:8px;margin:5px 0;float:left;width:420px'>Sending request ...</div>";

	}
}
// *** end of ajax for submit comment *** //

// *** Ajax for Notifications form *** //
function notify(action,member,channel)
{ 	
	//alert(action + channel+member);
	if(action){
		var actiontype = "add";
	} else {
		var actiontype = "remove";
	}
	//alert(actiontype);
	//document.getElementById("channel"+channel).innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	
	
	var url ="/includes/actions/notify.inc.php";
	var data = "member="+member+"&channel="+channel+"&actiontype="+actiontype;
	//var data = "";
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=function(){return stateChangedNotifysubmit(channel)}
	
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
	
}

function stateChangedNotifysubmit(channel) 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 	
		document.getElementById("channel"+channel).innerHTML=xmlHttp.responseText;
	} else {
		document.getElementById("channel"+channel).innerHTML="updating...";

	}
}
// *** end of ajax for notifications form *** //

// *** Ajax for favourites form *** //
function addfav(member_id,episode_id,epid)
{ 

	document.getElementById("myfav").innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}

	
	var url ="/includes/actions/addfav.inc.php";
	var data = "member_id="+member_id+"&favepisode="+episode_id+"&epid="+epid;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedaddfav
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedaddfav() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText == 'success'){
		//document.getElementById("myfav").innerHTML=xmlHttp.responseText 
		document.getElementById("myfav").innerHTML="<img src='/images/sc_fav2sm.gif' alt='this episode has been added to your favourites'/>";
		} else if(xmlHttp.responseText == 'notlogged'){
		document.getElementById("myfav").innerHTML="<img src='/images/sc_fav3sm.gif' alt='you need to be logged in to add this favourite'/>";	
	}
		
	} else {
		document.getElementById("myfav").innerHTML="Sending request ...";

	}

}
// *** end of ajax for favourtites form *** //
// *** Ajax for remove favourites form *** //
function removefav(favid)
{ 	

	//document.getElementById("fav"+favid).innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}

	var url ="/includes/actions/removefav.inc.php";
	var data = "favid="+favid;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=function(){return stateChangedremovefav(favid)}
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedremovefav(favid) 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText == 'success'){
		//document.getElementById("fav"+favid).innerHTML=xmlHttp.responseText 
		document.getElementById("fav"+favid).innerHTML="successfully removed";
		//window.location = "/favourites/";
		} else {
		document.getElementById("fav"+favid).innerHTML="failed to remove from favourites";	
	
	}
		
	} else {
		document.getElementById("fav"+favid).innerHTML="removing ...";

	}

}
// *** end of ajax for favourtites form *** //

// *** Ajax for retrieve form *** //
function sendPass()
{ 	
	document.getElementById("ee").innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	var sendme = document.sendpass.sendme.value
	var emailme = document.sendpass.emailme.value;
	
	var url ="/includes/actions/subscribe.inc.php";
	var data = "emailme="+emailme+"&sendme="+sendme;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedSendPasssubmit
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedSendPasssubmit() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText == 'success'){
		//document.getElementById("myfav").innerHTML=xmlHttp.responseText 
		document.getElementById("ee").innerHTML="Please check your email to collect your password";
		} else if(xmlHttp.responseText == 'success2'){
			document.getElementById("ee").innerHTML="but you need to confirm";
		} else {
			document.getElementById("ee").innerHTML=xmlHttp.responseText;
		}
	} else {
		document.getElementById("ee").innerHTML="processing";

	}
}
// *** end of ajax for retrieve form *** //


// *** Ajax for Submit Subscription form *** //
function submitSubscriptionForm()
{ 	
	/*check for empty or incorrect values*/
	if(document.subscribeme.email.value == "" || document.subscribeme.fname.value ==""){
		alert ("all fields are required");
	 return false;
	}
	
	/*simple email validation*/
	var at="@"
		if (document.subscribeme.email.value.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}
	
	document.getElementById("ss").innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	var fname = document.subscribeme.fname.value;
	/*var lname = document.subscribeMe.lname.value;*/
	//var username = document.subscribeMe.username.value;
	/*var password = document.subscribeMe.password.value;*/
	var set = document.subscribeme.set.value
	var email = document.subscribeme.email.value;
	
	var url ="/includes/actions/subscribe.inc.php";
	var data = "fname="+fname+"&email="+email+"&set="+set;
	/*var data = "set="+set+"&email="+email;*/
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedSubscribesubmit
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedSubscribesubmit() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
		if(xmlHttp.responseText == 'success'){
			
		//document.getElementById("myfav").innerHTML=xmlHttp.responseText 
		document.getElementById("subscribeme").innerHTML="<div style='width:300px;'><strong>SUCCESS</strong><br />An email has been sent to the email address you subscribed with. Please check your in box to confirm your subscription</div>";
		} else if(xmlHttp.responseText == 'email exists'){
		document.getElementById("myemail").innerHTML="email already exists";
		document.getElementById("ss").innerHTML="<input type='image' src='/images/subscribe.gif' name='submit' value='Subscribe' onclick='return submitSubscriptionForm()' style='width:120px; height:36px; float:right;'/>";
		document.getElementById("sendpass").innerHTML="<span style='display:block; border:solid 1px #f00;'><h3>Retrieve your password here</h3><input type='text' name='emailme' id='emailme' value='my email here' /><input type='hidden' name='sendme' value='sendme' /><div id='ee'><input type='image' src='/images/retrieve.gif' name='submit' value='SendPass' onclick='return sendPass()' style='width:120px; height:36px; float:right;'/></div></span>";
	} else if(xmlHttp.responseText == 'username exists'){
		document.getElementById("ss").innerHTML="<input type='image' src='/images/subscribe.gif' name='submit' value='Subscribe' onclick='return submitSubscriptionForm()' style='width:120px; height:36px; float:right;'/>";
		document.getElementById("user").innerHTML="username exists";	
		
	} else if(xmlHttp.responseText == 'check name'){
				document.getElementById("myname").innerHTML="check your name";
				document.getElementById("ss").innerHTML="<input type='image' src='/images/subscribe.gif' name='submit' value='Subscribe' onclick='return submitSubscriptionForm()' style='width:120px; height:36px; float:right;'/>";
				
	} else if(xmlHttp.responseText == 'check name one'){
				document.getElementById("myname").innerHTML="you need to provide both names";
				document.getElementById("ss").innerHTML="<input type='image' src='/images/subscribe.gif' name='submit' value='Subscribe' onclick='return submitSubscriptionForm()' style='width:120px; height:36px; float:right;'/>";
				
	} else {
		document.getElementById("ss").innerHTML="<img src='/images/processing.gif' alt='processing your subscription' style='float:right;' />";
		document.getElementById("user").innerHTML="";
		document.getElementById("myemail").innerHTML="";

	}
	}
}
// *** end of ajax for submit subscription *** //


// *** end of ajax for submit feedback *** //
function submitFeedbackFormNew(){
	/*check for empty or incorrect values*/
	if(document.feedback.speed.value =="slt" || document.feedback.country.value =="slt" || document.feedback.city.value =="" || document.feedback.state.value =="" || document.feedback.comments.value ==""){
		alert ("all fields are required");
	 return false;
	}
	
	for (var i=0; i < document.feedback.playback.length; i++)
   {
   if (document.feedback.playback[i].checked)
      {
      var playback = document.feedback.playback[i].value;
	  var radioset = 1;
      }
   }
   if (!radioset) {
alert("You must select a radio button");
return false;
}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	var state = document.feedback.state.value;
	var city = document.feedback.city.value;
	var country = document.feedback.country.value;
	var comments = document.feedback.comments.value;
	var ip = document.feedback.ip.value;
	var browser = document.feedback.browser.value;
	var speed = document.feedback.speed.value;
	var set = document.feedback.set.value;
	var url ="./includes/actions/feedback.inc.php";
	var data = "state="+state+"&city="+city+"&country="+country+"&comments="+comments+"&playback="+playback+"&ip="+ip+"&browser="+browser+"&set="+set+"&speed="+speed;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedFeed
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}
function stateChangedFeed() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//document.getElementById("upcoming_episodes").innerHTML=xmlHttp.responseText 
	if(xmlHttp.responseText=='success'){
		document.getElementById("process").innerHTML="Thank you for sending feedback";
	} else{
		document.getElementById("process").innerHTML="nope";
	}
	}
}

// *** edit order *** //
function orderEdit(newitem,itemsarray){
	
	//alert(itemsarray.length);
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	
	
	
	var newitemsarray = new Array();
	//alert(itemsarray[2]);
	
	for (loop=0; loop < itemsarray.length; loop++)
  {
    newitemsarray[loop] = itemsarray[loop];
	//alert(newitemsarray[loop]);
  }
	newitemsarray[newitemsarray.length] = newitem;

/*for (loop=0; loop < newitemsarray.length; loop++)
  {
   
	//alert(newitemsarray[loop]);
  }*/
 

	var homer = newitem;
	var url ="/includes/actions/orderedit.inc.php";
	var data = "ls="+homer+"&narray="+newitemsarray;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=function(){return stateChangedorderedit(homer)}
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedorderedit(homer) 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//if(xmlHttp.responseText == 'success'){
		document.getElementById("epsholder").innerHTML=xmlHttp.responseText 
		
		//document.getElementById(homer).innerHTML="<div id='+homer+'></div>";
		//document.getElementById("myfav").innerHTML="<li id='myfav' style='width:55px;'><img src='/images/heart2.png' alt='this episode has been added to your favourites'/></li>";
		//alert("fghj");
		//} else {
		//document.getElementById("myfav").innerHTML="<li id='myfav' style='width:55px;'><img src='/images/heartx.png' alt='this episode has been added to your favourites'/></li>";	
	//}
		
	} else {
		//document.getElementById("myfav").innerHTML="Sending request ...";

	}

}


// *** submit purchase form *** //
function submitPurchaseForm(){
	//alert(document.buyepisode.epid.value + document.buyepisode.payment_amount.value+document.buyepisode.card_type.value+document.buyepisode.episode_id.value+document.buyepisode.channel_id.value+document.buyepisode.member_id.value+document.buyepisode.card_number.value+document.buyepisode.card_holder.value+document.buyepisode.card_cvv.value+document.buyepisode.purchase.value+document.buyepisode.month.value+document.buyepisode.year.value);

  if (document.buyepisode.terms.checked == false) {
alert("You must agree to the terms");
return false;
}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
		document.getElementById("process").innerHTML="Processing";
	var epid = document.buyepisode.epid.value;
	 var payment_amount = document.buyepisode.payment_amount.value;
	 var card_type = document.buyepisode.card_type.value;
	var episode_id = document.buyepisode.episode_id.value;
	var card_month = document.buyepisode.month.value;
	var card_year = document.buyepisode.year.value;
	var channel_id = document.buyepisode.channel_id.value;
	var member_id = document.buyepisode.member_id.value;
	var card_number = document.buyepisode.card_number.value;
	var card_holder = document.buyepisode.card_holder.value;
	var card_cvv = document.buyepisode.card_cvv.value;
	var card_expiry = card_month+""+card_year;
	var purchase = document.buyepisode.purchase.value;
	var url ="../includes/actions/purchase.inc.php";
	var data = "epid="+epid+"&episode_id="+episode_id+"&channel_id="+channel_id+"&member_id="+member_id+"&purchase="+purchase+"&payment_amount="+payment_amount+"&card_number="+card_number+"&card_cvv="+card_cvv+"&card_holder="+card_holder+"&card_expiry="+card_expiry+"&card_type="+card_type;
	//var data = "&purchase="+purchase;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedPurchase
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}
function stateChangedPurchase() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//document.getElementById("upcoming_episodes").innerHTML=xmlHttp.responseText 
	if(xmlHttp.responseText=='success'){
		document.getElementById("purchase").innerHTML="Thank you for your purchase<br>to View the episode <a href='#' onclick='window.opener.location.reload(); window.close();'>close the window</a>";
		//window.opener.location.reload();
		//window.close();
	}else if(xmlHttp.responseText=='failed'){
		document.getElementById("process").innerHTML="The transaction failed. Please check yourdetails and try again.<input type='image' src='/images/confirm.png' name='submit' value='Confirm Purchase' onclick='return submitPurchaseForm()' style='width:120px; height:36px; float:right;'/>";
	} else{
		document.getElementById("process").innerHTML="processing";
	}
	}
}


// *** submit conact form *** //
function submitContact(){

	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	var sent = document.contactzoo.sent.value;
	var firstname = document.contactzoo.firstname.value;
	var lastname = document.contactzoo.lastname.value;
	var subject = document.contactzoo.subject.value;
	var comments = document.contactzoo.comments.value;
	var email = document.contactzoo.email.value;
	var url ="/includes/actions/submit.inc.php";
	var data = "sent="+sent+"&firstname="+firstname+"&lastname="+lastname+"&subject="+subject+"&comments="+comments+"&email="+email;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedContact
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}
function stateChangedContact() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//document.getElementById("upcoming_episodes").innerHTML=xmlHttp.responseText 
	if(xmlHttp.responseText=='success'){
		document.getElementById("form_container").innerHTML="Thank you for your contact. Australia Zoo TV will get back to you as soon as we can.";
		//window.opener.location.reload();
		//window.close();
	}else if(xmlHttp.responseText=='failed'){
		document.getElementById("process").innerHTML="failed";
	} else{
		document.getElementById("process").innerHTML="processing";
	}
	}
}


///when some selects a different bandwidth
function bandselect(speed, feed, playertype, epid, chid, episode, media){
	document.getElementById("scrpt").innerHTML = "<div id='container_id'></div>";
	flowplayer("container_id", {
			   src: "/flowplayer/flowplayer-3.2.1.swf",
			    // we need at least this version 
    version: [9, 115], 
 	wmode:'opaque',
	onFail: function()  { 
        document.getElementById("info").innerHTML = 
            "You need the latest Flash version to view MP4 movies. " + 
            "Your version is " + this.getVersion(); 
    } 
			   },
			   {
 
    // common configuration for each clip 
    clip: { 
 
        // each clip uses the rtmp provider 
        provider: 'rtmp'
    }, 
 
    // here is our playlist 
    playlist: [ 
        
			{ 
            url: speed, 
		  urlResolvers: null,
            onStart: function() { 
                this.getControls().show(); 
				viewcount(epid);
				//hidePreview();
            },
			
			onFinish: function() {
				freeplayer('subscription',epid,chid,episode,speed);
			}
             
            // when playback finishes player is resumed back to it's original splash image state 
           
        }
		
    ], 
 
    plugins: { 
	gatracker: {
			url: "/flowplayer/flowplayer.analytics-3.2.0.swf",
			labels: {
				start: "Start",	
				play: "Play",	
				pause: "Pause",	
				resume: "Resume",	
				seek: "Seek",	
				stop: "Stop",	
				finish: "Finish",	
				mute: "Mute",	
				unmute: "Unmute",	
				fullscreen: "Full Screen",	
				fullscreenexit: "Full Screen Exit"	
			},
			//debug: true,
			trackingMode: "AS3",
			googleId: "UA-894223-21" // your Google Analytics id here
		},
	controls:  {display: 'none',
		 stop: true
	},
        rtmp: { 
            url: '/flowplayer/flowplayer.rtmp-3.2.0.swf', 
			 urlResolvers: null,
            netConnectionUrl: feed 
        } 
    } 
	
});
	
}
//end when someone selects a new bandwidth



// *** Ajax for Submit Comment form *** //
function nextpage(page,channel)
{ 
	document.getElementById("episode_list").innerHTML="";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	
	var page = page;
	var channel = channel;
	var url ="/includes/next_page.inc.php";
	var data = "page="+page+"&channel="+channel;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedNextPage
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedNextPage() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("episode_list").innerHTML=xmlHttp.responseText;
	} else {
		document.getElementById("epnavigation").innerHTML="processing";

	}
}
// *** end of ajax for submit comment *** //


function displaymessage()
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	if(document.khaki.terms.checked){
	
	} else {
	alert("please tick the terms and conditions box");
	return false;
	}
if(document.khaki.channelname.value == ""){
	alert("You need to add some text for a channel name");
} else {
	var channel = document.khaki.channelname.value;
	var member = document.khaki.member.value;
	var description = document.khaki.description.value;
	var url ="/includes/actions/khaki.inc.steps.php";
	var data = "channel="+channel+"&khaki=khaki&member="+member+"&description="+description;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedKhakiStep
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}
}

function stateChangedKhakiStep() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
		if(xmlHttp.responseText == 'success'){
			//document.getElementById("process").innerHTML=xmlHttp.responseText
		document.getElementById("channelcreate").innerHTML = "<p><strong>Congratulations</strong> you have successfully created you're very own channel. The best part is you can start uploading your very own videos to Australia Zoo TV right away. The more videos you upload between March and May the more chances you have in the random draw to WIN the <strong>Sony HD HandyCam</strong>. So what are you waiting for? <a href='/subscribe/'>Start uploading today!</a></p>";
			
		} else {
		//document.getElementById('light2').style.display='block';
		//document.getElementById('fade').style.display='block';
		//document.getElementById('light').style.display='none';
		document.getElementById("process").innerHTML=xmlHttp.responseText;
		}
	} else {
		document.getElementById("process").innerHTML="processing";
	
	}
}




function submitnewkhaki()
{ 	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	
	//var title = 
	var id = document.uploadform.chid.value;
	var title = document.uploadform.mytitle.value;
	var file = document.uploadform.myfile.value;
	var url ="/includes/actions/uploadkhaki.inc.php";
	var data = "id="+id+"&title="+title+"&file="+file;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedSubmitDvd
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedSubmitDvd() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
	document.getElementById("container2").innerHTML=xmlHttp.responseText 
	
	} else {
		//document.getElementByClassName("myfav").innerHTML="Sending request ...";

	}

}




<!--
function startUploadKhaki(id){
	if(document.vidupload.mytitle.value == "" || document.vidupload.mydescription.value == ""){
	alert("You need to fill in the video title field or the description field");
	return;
	} else {
	  document.getElementById('f1_upload').innerHTML = "<img src='/images/uploadprocess.gif' alt='Processing please wait' style='float:right'/>";
	  //document.getElementById('f1_upload_form3').innerHTML = "";
      return true;
	}
}

function stopUploadKhaki(success,blogid,channel){
      var result = '';
      if (success == 1){
         result = '<span class="error">The video was uploaded successfully! <a href="/subscribe/">Upload another</a></span><br/><br/>';
		document.getElementById('f1_upload_process3').style.visibility = 'hidden';
      document.getElementById('f1_upload_form3').innerHTML = result + '';
      document.getElementById('f1_upload_form3').style.visibility = 'visible'; 
	  document.getElementById('f1_upload').innerHTML = "";
	  } else if (success == 5){
		  xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
		  
         result = '<span class="error">Your profile pic was uploaded successfully!</span>';
		document.getElementById('f1_upload_process3').style.visibility = 'hidden';
     document.getElementById('f1_upload_form3').innerHTML = result;
	 
      document.getElementById('f1_upload_form3').style.visibility = 'visible'; 
	  document.getElementById('f1_upload').innerHTML = "";	
	  
	  
	  var url ="/includes/actions/picview.inc.php";
	var data = "channel="+channel;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedPicView
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
	  
	 } else {
		if (success == 2){  
		  result = '<span class="error" style="font-weight:bold">That is the wrong file type. We can only accept .mp4, .m4v, .flv, .f4v, .mov files.<\/span><br/><br/>'; 
		} else if (success == 3){
			result = '<span class="error" style="font-weight:bold">The File is too large. For videos it needs to be under 30mb, and photos under 2mb.<\/span><br/><br/>'; 
		} else if (success == 4){
			result = '<span class="error" style="font-weight:bold">That is the wrong file type. We can only accept .jpg, .gif, .png files.<\/span><br/>'; 
		} else {
			result = '<span class="error" style="font-weight:bold">There was an error during file upload!<\/span><br/><br/>';
		}
      document.getElementById('f1_upload_form3').style.visibility = 'visible';  
	   document.getElementById('f1_upload').innerHTML = result + "<input type='image' src='/images/upload.gif' name='submitBtn' value='Upload' style='float:right; display:block;'/>";
      }
       
      return true;   
}
//-->

// pic view start //

function stateChangedPicView() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
	 document.getElementById('current').innerHTML=xmlHttp.responseText 
	
	} else {
		//document.getElementByClassName("myfav").innerHTML="Sending request ...";

	}

}

// pic view end //


function startedit(val){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	if(val == 1){
	var edit = "edit";
	} else {
	var edit = "not";	
	}
	var url ="/includes/content/khakichannel.inc.php";
	var data = "edit="+edit;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedEdit
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedEdit() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
	document.getElementById("khakichannel").innerHTML=xmlHttp.responseText 
	
	} else {
		//document.getElementByClassName("myfav").innerHTML="Sending request ...";

	}

}


//******** channel update ****//////

function channeledit(){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	var descript = document.khakiupdate.descript.value;
	var chid = document.khakiupdate.chid.value;
	var actionedit = "actionedit";
	var edit="edit";
	var url ="/includes/content/khakichannel.inc.php";
	var data = "descript="+descript+"&actionedit="+actionedit+"&chid="+chid+"&edit="+edit;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedChEdit
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedChEdit() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
	document.getElementById("khakichannel").innerHTML=xmlHttp.responseText 
	
	} else {
		document.getElementByClassName("khakichannel").innerHTML="Updating channel ...";

	}

}

//******** end channel update ****//////


//********* remove channel *****/////

function removeme(channel){
	var sure = confirm('are you sure you want to remove your channel? This will remove all videos relating to this channel.');
	
	if(sure){
		xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	var channel = channel;
	var dlete="delete";
	var url ="/includes/actions/deletechannel.inc.php";
	var data = "delete="+dlete+"&channel="+channel;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedDelete
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
	} else {
	//nothing
	}
	
}

function stateChangedDelete() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
	document.getElementById("get").innerHTML=xmlHttp.responseText 
	
	} else {
		document.getElementByClassName("khakichannel").innerHTML="removing channel ...";

	}

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

///****** end remove channel *****/////

///***** what happens when a video from the FREE player ends *********////
function freeplayer(playertype, epid, chid, episode, media){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	var url ="/includes/actions/freeplayer.next.inc.php";
	var data = "epid="+epid+"&chid="+chid+"&episode="+episode+"&media="+media+"&playertype="+playertype+"&viewcount="+viewcount;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedNextFree
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
	
	
}

function stateChangedNextFree() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 

	document.getElementById("scrpt").innerHTML=xmlHttp.responseText 
	
	} else {
		//document.getElementByClassName("khakichannel").innerHTML="removing channel ...";

	}

}

//end free player action ///

// select the player for play agaion ///

function freeplayerselect(epid, chid, episode, media)
{
	document.getElementById("scrpt").innerHTML="<div id='container_id'></div>"; //xmlHttp.responseText 
	flowplayer("container_id", { 
 
    // our Flash component 
    src: "/flowplayer/flowplayer-3.2.1.swf", 
 
    // we need at least this version 
    version: [9, 115], 
 	wmode:'opaque',
    // older versions will see a custom message 
    onFail: function()  { 
        document.getElementById("info").innerHTML = 
            "You need the latest Flash version to view MP4 movies. " + 
            "Your version is " + this.getVersion(); 
    } 
 
    // here is our third argument which is the Flowplayer configuration 
}, { 
   // clip:  
   
   clip: {                      
		
      	url: media,
        autoPlay: true,
		
		onStart: function(clip) {
		viewcount(epid);
		}, 
		       
        onFinish: function(clip) {           
			freeplayer('free',epid,chid,episode,media);               
        }              
    },
	plugins:{
		gatracker: {
			url: "/flowplayer/flowplayer.analytics-3.2.0.swf",
			labels: {
				start: "Start",	
				play: "Play",	
				pause: "Pause",	
				resume: "Resume",	
				seek: "Seek",	
				stop: "Stop",	
				finish: "Finish",	
				mute: "Mute",	
				unmute: "Unmute",	
				fullscreen: "Full Screen",	
				fullscreenexit: "Full Screen Exit"	
			},
			//debug: true,
			trackingMode: "AS3",
			googleId: "UA-894223-21" // your Google Analytics id here
		}
	}
});
}

// end select player ///

// add to the view count ////

function viewcount(id){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return false;
	}
	var url ="/includes/actions/viewcount.php";
	var data = "id="+id;
	data = data + "&ajaxid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedViewCount
	
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(data);
	return false;
}

function stateChangedViewCount() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	//document.getElementById("scrpt").innerHTML=xmlHttp.responseText 
	
	} else {
		//document.getElementByClassName("khakichannel").innerHTML="removing channel ...";

	}

}

// end the view count //
