function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
                                     
    var ret = str;
    
    ret = ret.toString();
    ret = encodeURIComponent(ret);
    ret = ret.replace(/%20/g, '+');
 
    return ret;
}

function getXmlObj(){
 	var xmlHttpRequest;
	
	//Browser check
	try
	{
	 // Firefox, Safari, Opera
	 xmlHttpRequest = new XMLHttpRequest();
	}
	catch (e)
	{
	 //IE
	 try
	 {
	   xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch (e)
	 {
		//IE 7.0
		try
		{
		   xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
		   //alert("This feature is not supported by your browser.");
		   return false;
		}
	  }
	}
	
	return xmlHttpRequest;
}

function returnElement(sContent)
{
	var objLocation;
	var sElement;
	
	if(document.getElementById)
	{
		sElement = "document.getElementById('" + sContent + "')";
	}
	else if(document.all)
	{
		sElement = "document.all['" + sContent + "']";
	}
	
	objLocation = eval(sElement);
	return objLocation;
}

function getContent(sType, sElement, nStart, nItems, arrItems)
{
  var xmlHttpRequest;

  //Browser check
  try
  {
     // Firefox, Safari, Opera
     xmlHttpRequest = new XMLHttpRequest();
  }
  catch (e)
  {
     //IE
     try
     {
       xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e)
     {
        //IE 7.0
        try
        {
           xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
           //alert("This feature is not supported by your browser.");
           return false;
        }
      }
    }
    xmlHttpRequest.onreadystatechange=function()
    {
       if(xmlHttpRequest.readyState == 4)
       {
        var objSection = returnElement(sElement);
        objSection.style.display = "block";
	    	objSection.innerHTML = xmlHttpRequest.responseText;
       }
    }   	
		var sScript = '/includes/modules/cmnShowVids.php';
		if (sType == "product"){
			sScript = '/includes/modules/cmnShowProducts.php';
		}
		
		var sURL = sScript+'?nStart='+nStart+"&nItems="+nItems+"&sElement="+sElement+"&nTotal=7"; 
		
		var j=1;
		var nOffset = nStart-1;
		
		
		for (var i=1; i<=arrItems.length; i++){
			if (i<arrItems.length){
				sURL += "&nItem"+j+"="+arrItems[i];
				j++;
			}
		}

		xmlHttpRequest.open("GET",sURL,true);
		xmlHttpRequest.send(null);
}

function getTagCloud(tagId, sElement, channel_id)
{

  var xmlHttpRequest;

  //Browser check
  try
  {
     // Firefox, Safari, Opera
     xmlHttpRequest = new XMLHttpRequest();
  }
  catch (e)
  {
     //IE
     try
     {
       xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e)
     {
        //IE 7.0
        try
        {
           xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
           //alert("This feature is not supported by your browser.");
           return false;
        }
      }
    }
    xmlHttpRequest.onreadystatechange=function()
    {
       if(xmlHttpRequest.readyState == 4)
       {
        var objSection = returnElement(sElement);
        objSection.style.display = "block";
	    	objSection.innerHTML = xmlHttpRequest.responseText;
       }
    }   	
		var sScript = '/includes/modules/getTagCloud.php';
		
		var sURL = sScript+'?tagId='+tagId+'&channel_id='+channel_id; 
		
		xmlHttpRequest.open("GET",sURL,true);
		xmlHttpRequest.send(null);
}

function sendComment(form, sElement)
{

////alert(form);
////alert(sElement);
  
  
  var message = document.frmJoin.message.value;
  var user_id = document.frmJoin.user_id.value;
  var source = document.frmJoin.source.value;
  var source_id = document.frmJoin.source_id.value;
  
  var xmlHttpRequest = getXmlObj();
  
  xmlHttpRequest.onreadystatechange=function()
    {
       if(xmlHttpRequest.readyState == 4)
       {
/*        var objSection = returnElement(sElement);
        objSection.style.display = "block";
	    	objSection.innerHTML = xmlHttpRequest.responseText;
*/
	    var xml = xmlHttpRequest.responseXML;

	    var username =  xml.getElementsByTagName("screenname");
		var message =  xml.getElementsByTagName("message");
		var anonymous = xml.getElementsByTagName("anonymous");
		var profileurl = xml.getElementsByTagName("profileurl");
		//var user_id = xml.getElementsByTagName("user_id");
		//var iconvalue = xml.getElementsByTagName("iconvalue");
		
	    var innerhtml = "";
	 //  alert(username.length);
	    for(var i=0; i < username.length; i++){
//alert(i);
			var current_username = username[i].childNodes[0].nodeValue;
			var current_message = message[i].childNodes[0].nodeValue;
			
			if(xml.getElementsByTagName("anonymous")[i].firstChild != null){
			//if(anonymous[i].childNodes[0].nodeValue != null){
				var current_anonymous = true;
				var current_iconvalue = xml.getElementsByTagName("iconvalue")[i].firstChild.nodeValue;
				var current_avatar = '<img src="http://images.hook.tv/common/miscicons/commentAvatar_'+ current_iconvalue + '.gif" height="47" width="47" border="0" alt="" title="" class="avatar" />';
			}else{
//alert(i);
				var current_anonymous = false;
				var current_profileurl = xml.getElementsByTagName("profileurl")[i].firstChild.nodeValue;
				var current_user_id = xml.getElementsByTagName("user_id")[i].firstChild.nodeValue;
				if(xml.getElementsByTagName("rd_avatar")[i].firstChild.nodeValue == 'true')
					var current_avatar = '<img src="http://flyfishing.hook.tv/UserImg.aspx?id=' + current_user_id + '" height="48" width="48" class="avatar">';
				else
					var current_avatar = '<img src="viewavatar.php?user_id=' + current_user_id + '" height="48" width="48" class="avatar">';
			}
/*
{if $comments[iterator].rd_avatar == 'false'}
	<img src="viewavatar.php?user_id={$comments[iterator].user_id}" height="48" width="48" class="avatar">
{elseif $comments[iterator].rd_avatar == 'true'}
	<img src="http://flyfishing.hook.tv/UserImg.aspx?id={$comments[iterator].user_id}" height="48" width="48" class="avatar">
{else}
	<img src="http://images.hook.tv/common/miscicons/commentAvatar_{$comments[iterator].iconvalue}.gif" height="47" width="47" border="0" alt="" title="" class="avatar" />
{/if}
*/
//alert(current_avatar);
			innerhtml = innerhtml + '<div class="comment"> ' + current_avatar + '<span class="author">';
			
			if(current_anonymous)
				innerhtml = innerhtml + '' + current_username + '</span> <hr></hr> ' + current_message + '</div> <br /><br />';
			else
				innerhtml = innerhtml + '<a href="profile.php?member='+ current_profileurl + '">' + current_username + '</a></span> <hr></hr> ' + current_message + '</div> <br /><br />';
//alert(i);

		}
	//	alert(innerhtml);
	    	document.getElementById(sElement).innerHTML = innerhtml;
       }
    }   	
		var sScript = '/includes/modules/leaveMessage.php';

		/*//var sURL = sScript+'?tagId='+tagId; 
		var params;

		xmlHttpRequest.open("POST",sScript,true);
		xmlHttpRequest.send(null);*/
		
	//var url = "get_data.php";
//var params = "lorem=ipsum&name=binny";

var params = "source=" + source + "&message=" + message + "&source_id=" + source_id;

if(user_id > 0)
	params = params + "&user_id=" + user_id;

if(document.frmJoin.txtUsername != null){
  	var username = document.frmJoin.txtUsername.value;
  
	if(username.length > 0)	
		params = params + "&anonymous=" + username;
}
	
xmlHttpRequest.open("POST", sScript, true);

//Send the proper header information along with the request
xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpRequest.setRequestHeader("Content-length", params.length);
xmlHttpRequest.setRequestHeader("Connection", "close");

/*http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		//alert(http.responseText);
	}
}*/

xmlHttpRequest.send(params);
}

function showObject(objObject){
	objObject.style.display = 'block';
}

function hideObject(objObject){
	objObject.style.display = 'none';
}

function toggleEntry(sContent, sMethod){	
	var sElementShow = sContent+"_entry";
	var sElementHide = sContent+"_display";
	
	if (sMethod == "hide"){
		sElementShow = sElementHide;
		sElementHide = sContent+"_entry";
	}
	
	var objLocationShow = returnElement(sElementShow);
	var objLocationHide = returnElement(sElementHide);
	
	if (objLocationShow && objLocationHide){
			showObject(objLocationShow);
			hideObject(objLocationHide);
	}
}

function toggleProfileSave(sContent, sMethod){
	
	// use ajax to save profile data

 	var xmlHttpRequest = getXmlObj();
 	
 	var firstName = document.getElementById("txtFirstName").value;
	var lastName = document.getElementById("txtLastName").value;
	var hobbies = document.getElementById("txtHobbies").value;
	var interests = document.getElementById("txtInterests").value;
	var month = document.getElementById("cboBirthMonth").value;
	var date = document.getElementById("cboBirthDay").value;
	var year = document.getElementById("cboBirthYear").value;
	var status = document.getElementById("cboStatus").value;
	var species = document.getElementById("txtSpecies").value;
	var brands = document.getElementById("txtBrands").value;


	if(document.getElementById("radGender_m").checked == true)
		var gender = "Male";
	else if(document.getElementById("radGender_f").checked == true)
		var gender = "Female";

	xmlHttpRequest.onreadystatechange=function(){
	   if(xmlHttpRequest.readyState == 4){
	   	var response = xmlHttpRequest.responseText;
	   	var xml = xmlHttpRequest.responseXML;
	   	//alert(response);

	   	document.getElementById("lblName").innerHTML = xml.getElementsByTagName("firstName")[0].firstChild.nodeValue + " " + xml.getElementsByTagName("lastName")[0].firstChild.nodeValue;

		if(xml.getElementsByTagName("hobbies")[0].firstChild != null)
			document.getElementById("lblHobbies").innerHTML = xml.getElementsByTagName("hobbies")[0].firstChild.nodeValue;
		else
			document.getElementById("lblHobbies").innerHTML = "";

	   	if(xml.getElementsByTagName("interests")[0].firstChild != null)
			document.getElementById("lblInterests").innerHTML = xml.getElementsByTagName("interests")[0].firstChild.nodeValue;
		else
			document.getElementById("lblInterests").innerHTML = "";
			
		if(xml.getElementsByTagName("species")[0].firstChild != null)
			document.getElementById("lblSpecies").innerHTML = xml.getElementsByTagName("species")[0].firstChild.nodeValue;
		else
			document.getElementById("lblSpecies").innerHTML = "";
		
		if(xml.getElementsByTagName("brands")[0].firstChild != null)
			document.getElementById("lblBrands").innerHTML = xml.getElementsByTagName("brands")[0].firstChild.nodeValue;
	   	else
	   		document.getElementById("lblBrands").innerHTML = "";
	   	
	   	document.getElementById("lblStatus").innerHTML = xml.getElementsByTagName("status")[0].firstChild.nodeValue;
	   	document.getElementById("lblGender").innerHTML = xml.getElementsByTagName("gender")[0].firstChild.nodeValue;
	   	
	   	document.getElementById("lblBirthDate").innerHTML = xml.getElementsByTagName("birthday")[0].firstChild.nodeValue
	   	toggleEntry(sContent, sMethod);
	   }

	}


	var sScript = '/includes/modules/postProfileData.php';
	var user_id = document.getElementById("user_id").value;
	var params = "user_id=" + user_id + "&firstName=" + firstName + "&lastName=" + lastName + "&hobbies=" + hobbies + "&interests=" + interests + "&gender=" + gender + "&month=" + month + "&date=" + date + "&year=" + year + "&status=" + status + "&species=" + species + "&brands=" + brands;

	//alert(params);
	xmlHttpRequest.open("POST", sScript, true);


	//Send the proper header information along with the request
	xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpRequest.setRequestHeader("Content-length", params.length);
	xmlHttpRequest.setRequestHeader("Connection", "close");
	xmlHttpRequest.send(params);
	
}

function toggleProfileEdit(sContent, sMethod) {
	// use ajax to get profile data

 	var xmlHttpRequest = getXmlObj();
	var status;
	var hobbies;
	var interests;
	var value;

	xmlHttpRequest.onreadystatechange=function()
	{
	   if(xmlHttpRequest.readyState == 4){
	   	var xml = xmlHttpRequest.responseXML;

		//alert(xmlHttpRequest.responseText);


		var frmValue = document.getElementById("txtFirstName");
		if(xml.getElementsByTagName("firstName")[0].firstChild != null)
			frmValue.value =  xml.getElementsByTagName("firstName")[0].firstChild.nodeValue;

		var frmValue = document.getElementById("txtLastName");
		if(xml.getElementsByTagName("lastName")[0].firstChild != null)
			frmValue.value =  xml.getElementsByTagName("lastName")[0].firstChild.nodeValue;

		var frmValue = document.getElementById("txtHobbies");
		if(xml.getElementsByTagName("hobbies")[0].firstChild != null)
			frmValue.value =  xml.getElementsByTagName("hobbies")[0].firstChild.nodeValue;

		var frmValue = document.getElementById("txtInterests");
		if(xml.getElementsByTagName("interests")[0].firstChild != null)
			frmValue.value =  xml.getElementsByTagName("interests")[0].firstChild.nodeValue;
		
		var frmValue = document.getElementById("txtSpecies");
		if(xml.getElementsByTagName("species")[0].firstChild != null)
			frmValue.value =  xml.getElementsByTagName("species")[0].firstChild.nodeValue;
			
		var frmValue = document.getElementById("txtBrands");
		if(xml.getElementsByTagName("brands")[0].firstChild != null)
			frmValue.value =  xml.getElementsByTagName("brands")[0].firstChild.nodeValue;
				
		if(xml.getElementsByTagName("gender")[0].firstChild != null){
					
			if(xml.getElementsByTagName("gender")[0].firstChild.nodeValue == 'Male')
				document.getElementById("radGender_m").checked = true;
			else if(xml.getElementsByTagName("gender")[0].firstChild.nodeValue == 'Female')
				document.getElementById("radGender_f").checked = true;
		}


		// select status dropdown item
		var myDropdownList = document.getElementById("cboStatus");
		var itemToSelect = xml.getElementsByTagName("status")[0].firstChild.nodeValue;

		// Loop through all the items
		for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++){    
		  if (myDropdownList.options[iLoop].value == itemToSelect){
			// Item is found. Set its selected property, and exit the loop
			myDropdownList.options[iLoop].selected = true;
			break;
		  }
		}

		// select birth month dropdown item
		var myDropdownList = document.getElementById("cboBirthMonth");
		var itemToSelect = xml.getElementsByTagName("month")[0].firstChild.nodeValue;
		selectDropdownItem(myDropdownList, itemToSelect);

		// select birth date dropdown item
		var myDropdownList = document.getElementById("cboBirthDay");
		var itemToSelect = xml.getElementsByTagName("date")[0].firstChild.nodeValue;
		selectDropdownItem(myDropdownList, itemToSelect);
		
		// select birth year dropdown item
		var myDropdownList = document.getElementById("cboBirthYear");
		var itemToSelect = xml.getElementsByTagName("year")[0].firstChild.nodeValue;
		selectDropdownItem(myDropdownList, itemToSelect);

		toggleEntry(sContent, sMethod);


	   }
	}   	

	var sScript = '/includes/modules/getProfileData.php';

	var user_id = document.getElementById("user_id").value;
	var params = "user_id=" + user_id;

	xmlHttpRequest.open("POST", sScript, true);


	//Send the proper header information along with the request
	xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpRequest.setRequestHeader("Content-length", params.length);
	xmlHttpRequest.setRequestHeader("Connection", "close");
	xmlHttpRequest.send(params);
}

function toggleEntryEdit(sContent, sMethod) {
	// use ajax to get profile data

 	var xmlHttpRequest = getXmlObj();
	var bio;
	var url;

	xmlHttpRequest.onreadystatechange=function()
	{
	   if(xmlHttpRequest.readyState == 4){
	   	var xml = xmlHttpRequest.responseXML;

		//alert(xmlHttpRequest.responseText);


		var frmValue = document.getElementById("txtBio");
		frmValue.value =  xml.getElementsByTagName("bio")[0].firstChild.nodeValue;

		var frmValue = document.getElementById("txtUrl");
		frmValue.value =  xml.getElementsByTagName("url")[0].firstChild.nodeValue;

		toggleEntry(sContent, sMethod);

	   }
	}   	

	var sScript = '/includes/modules/getProfileData.php';

	var user_id = document.getElementById("user_id").value;
	var params = "user_id=" + user_id + "&bio=" + bio + "&url=" + url;

	xmlHttpRequest.open("POST", sScript, true);


	//Send the proper header information along with the request
	xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpRequest.setRequestHeader("Content-length", params.length);
	xmlHttpRequest.setRequestHeader("Connection", "close");
	xmlHttpRequest.send(params);
}

function toggleEntrySave(sContent, sMethod){
	
	// use ajax to save profile data

 	var xmlHttpRequest = getXmlObj();

 	var bio = document.getElementById("txtBio").value;
	var url = document.getElementById("txtUrl").value;


	xmlHttpRequest.onreadystatechange=function(){
	   if(xmlHttpRequest.readyState == 4){
	   	var response = xmlHttpRequest.responseText;
	   	var xml = xmlHttpRequest.responseXML;
	   	//alert(response);

	   	if(xml.getElementsByTagName("bio")[0].firstChild != null)
	   		document.getElementById("lblBio").innerHTML = xml.getElementsByTagName("bio")[0].firstChild.nodeValue;
	   	else
			document.getElementById("lblBio").innerHTML = "";

		if(xml.getElementsByTagName("url")[0].firstChild != null){
			document.getElementById("lblUrl").innerHTML = "<a href='" + xml.getElementsByTagName("url")[0].firstChild.nodeValue + "'>" + xml.getElementsByTagName("url")[0].firstChild.nodeValue + "</a>";
		
		}else
			document.getElementById("lblUrl").innerHTML = "";

	   	toggleEntry(sContent, sMethod);
	   }

	}


	var sScript = '/includes/modules/postProfileData.php';
	var user_id = document.getElementById("user_id").value;
	var params = "user_id=" + user_id + "&bio=" + bio + "&url=" + url + "&type=bio";

	//alert(params);
	xmlHttpRequest.open("POST", sScript, true);


	//Send the proper header information along with the request
	xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpRequest.setRequestHeader("Content-length", params.length);
	xmlHttpRequest.setRequestHeader("Connection", "close");
	xmlHttpRequest.send(params);
	
}

function selectDropdownItem(myDropdownList, itemToSelect){
	// select birth month dropdown item
	
	// Loop through all the items
	for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++){    
		////alert(myDropdownList.options[iLoop].value + ":" + itemToSelect);
	  if (myDropdownList.options[iLoop].value == itemToSelect){
		// Item is found. Set its selected property, and exit the loop
		myDropdownList.options[iLoop].selected = true;
		break;
	  }
	}
}

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function hideAllTabs(){
	var objCommentTab = returnElement('tab_comment');
	var objBlogTab = returnElement('tab_blog');
	var objForumTab = returnElement('tab_forum');
	
	hideObject(objCommentTab);
	hideObject(objBlogTab);
	hideObject(objForumTab);
}

function getChildTagsSelect(parent_tag_id, dest)
{

  var xmlHttpRequest;

  //Browser check
  try
  {
     // Firefox, Safari, Opera
     xmlHttpRequest = new XMLHttpRequest();
  }
  catch (e)
  {
     //IE
     try
     {
       xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e)
     {
        //IE 7.0
        try
        {
           xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
           //alert("This feature is not supported by your browser.");
           return false;
        }
      }
    }
    xmlHttpRequest.onreadystatechange=function()
    {
       if(xmlHttpRequest.readyState == 4)
       {
        var objSection = returnElement(sElement);
        objSection.style.display = "block";
	    	objSection.innerHTML = xmlHttpRequest.responseText;
       }
    }   	
		var sScript = '/includes/modules/getTagCloud.php';
		
		var sURL = sScript+'?tagId='+tagId; 
		
		xmlHttpRequest.open("GET",sURL,true);
		xmlHttpRequest.send(null);
}

function getNextVideo(video_series, start, user_id, total, max){
	// total = total videos to display on screen (ie. 3)
	// max = total videos belonging to user (ie. 50)
	// start = first row to fetch from db (ie: ...LIMIT start, 3)

 	var xmlHttpRequest = getXmlObj();
 
	xmlHttpRequest.onreadystatechange=function()
	{
	   if(xmlHttpRequest.readyState == 4){
	   	var xml = xmlHttpRequest.responseXML;

		//alert(xmlHttpRequest.responseText);

		var title =  xml.getElementsByTagName("title");
		var thumbnail =  xml.getElementsByTagName("thumbnail");
		var rateCount=  xml.getElementsByTagName("rateCount");
		var rating =  xml.getElementsByTagName("rating");
		var viewCount =  xml.getElementsByTagName("viewCount");
		var asset_key =  xml.getElementsByTagName("asset_key");
		var username =  xml.getElementsByTagName("author");

		for(var i=0; i < title.length; i++){
			var current_asset_key = asset_key[i].childNodes[0].nodeValue;
			//document.getElementById("vid_title_" + i).innerHTML = "<a href=''>" + current_title.childNodes[0].nodeValue + "</a>";
//alert(video_series + "_vid_title_" + i);
			var current_title = title[i];
			document.getElementById(video_series + "_vid_title_" + i).innerHTML = "<a href='player.php?key=" + current_asset_key + "'>" + current_title.childNodes[0].nodeValue + "</a>";
//alert(video_series + "_vid_author_" + i);
			var current_username = username[i];
			document.getElementById(video_series + "_vid_author_" + i).innerHTML = "<a href='profile.php?member=" + current_username.childNodes[0].nodeValue + "'>" + current_username.childNodes[0].nodeValue + "</a>";

			var current_thumbnail = thumbnail[i];
			document.getElementById(video_series + "_vid_thumbnail_" + i).innerHTML = "<a href=''><img src='" + current_thumbnail.childNodes[0].nodeValue + "' height='75' width='100' border='0' alt='' title='' class='outlined'></a>";
			
			var current_rateCount = rateCount[i];
			document.getElementById(video_series + "_vid_rateCount_" + i).innerHTML = "<a href=''>" + current_rateCount.childNodes[0].nodeValue + "</a>";

			var current_rating = rating[i];
			document.getElementById(video_series + "_vid_rating_" + i).innerHTML = "<img src='http://images.hook.tv/common/stars_" + current_rating.childNodes[0].nodeValue + ".gif'></a>";

			var current_viewCount = viewCount[i];
			document.getElementById(video_series + "_vid_viewCount_" + i).innerHTML = current_viewCount.childNodes[0].nodeValue + " views.";

		}

//alert("max: " + max + ",total: " + total + ", start: " + start);

		if((start + total) == max)
			var next_class = 'class="disabled"';
		else if(start == 0)
			var prev_class = 'class="disabled"';

		document.getElementById(video_series + "_left_arrow").innerHTML = '<a href="javascript: getNextVideo(\'' + video_series + '\', ' + (start - 1) + ', ' + user_id + ', ' + total + ', ' + max + ')"> <img src="http://images.hook.tv/common/button_previous.gif" height="34" width="34" border="0" alt="next video" title="next video" ' + prev_class + '/> </a>';
		
		document.getElementById(video_series + "_right_arrow").innerHTML = '<a href="javascript: getNextVideo(\'' + video_series + '\', ' + (start + 1) + ', ' + user_id + ', ' + total + ', ' + max + ')"> <img src="http://images.hook.tv/common/button_next.gif" height="34" width="34" border="0" alt="next video" title="next video" ' + next_class + ' /> </a>';

	   }
	}   	

	var sScript = '/includes/modules/getNextVideo.php';

	var user_id = document.getElementById("user_id").value;
	
	if(video_series == 'photo_series')
		var type = "image";
	else if(video_series == 'video_series_1' || video_series == 'video_series_2')
		var type = "video";
	else if(video_series == 'favorite_series')
		var type = "favorite";
	
	var params = "user_id=" + user_id + "&start=" + start + "&total=" + total + "&type=" + type;

	xmlHttpRequest.open("POST", sScript, true);

	//Send the proper header information along with the request
	xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpRequest.setRequestHeader("Content-length", params.length);
	xmlHttpRequest.setRequestHeader("Connection", "close");
	xmlHttpRequest.send(params);
}

function getNextItem(video_series, start, user_id, total, max, type){
	// total = total videos to display on screen (ie. 3)
	// max = total videos belonging to user (ie. 50)
	// start = first row to fetch from db (ie: ...LIMIT start, 3)
	//alert(start + total);
	if(((start + total) <= max)) {
		
		var xmlHttpRequest = getXmlObj();
	 
		xmlHttpRequest.onreadystatechange=function()
		{
		   if(xmlHttpRequest.readyState == 4){
			var xml = xmlHttpRequest.responseXML;
	
			//alert(xmlHttpRequest.responseText);
	
			if(type == 'friend'){ // friend reels
				var name =  xml.getElementsByTagName("name");
				var thumbnail =  xml.getElementsByTagName("thumbnail");
				var screenName =  xml.getElementsByTagName("screenName");
				var profile_url =  xml.getElementsByTagName("profile_url");
	
				for(var i=0; i < name.length; i++){
		
					var current_screenname = screenName[i].childNodes[0].nodeValue;
					var current_thumbnail = thumbnail[i].childNodes[0].nodeValue;
					var current_profile_url = profile_url[i].childNodes[0].nodeValue;
					
					var unit = document.getElementById(type + '_container_' + i);
					unit.innerHTML = '<a href="profile.php?member=' + current_profile_url + '">' + current_thumbnail + '</a><br/> <div class="vid_title"><a href="profile.php?member=' + current_profile_url + '">' + current_screenname + '</a></div>';
		
				}
			}else if(type == 'user_video' || 'user_fav_video' || 'user_image' || 'pro_video' || 'most_watched' || 'latest_content'){ // user video reels
				var title =  xml.getElementsByTagName("title");
				var thumbnail =  xml.getElementsByTagName("thumbnail");
				var rating =  xml.getElementsByTagName("rating");
				var rateCount =  xml.getElementsByTagName("rateCount");
				var viewCount =  xml.getElementsByTagName("viewCount");
				var asset_key =  xml.getElementsByTagName("asset_key");
				var screenName =  xml.getElementsByTagName("author");
				var profile_url =  xml.getElementsByTagName("profile_url");
		
				for(var i=0; i < title.length; i++){
		
					var current_screenname = screenName[i].childNodes[0].nodeValue;
					var current_thumbnail = thumbnail[i].childNodes[0].nodeValue;
					var current_title = title[i].childNodes[0].nodeValue;
					var current_rating = rating[i].childNodes[0].nodeValue;
					var current_rateCount = rateCount[i].childNodes[0].nodeValue;
					var current_viewCount = viewCount[i].childNodes[0].nodeValue;
					var current_assetKey = asset_key[i].childNodes[0].nodeValue;
					var current_profile_url = profile_url[i].childNodes[0].nodeValue;
					
					var unit = document.getElementById(type + '_container_' + i);
					unit.innerHTML = '<a href="player.php?key=' + current_assetKey + '"><img src="' + current_thumbnail + '" height="75" width="100" border="0" alt="" title="" class="outlined" /></a></span><br/> <div class="vid_title"><a href="player.php?key=' + current_assetKey + '">' + current_title + '</a></div> By <span class="author"><a href="profile.php?member=' + current_profile_url + '">' + current_screenname + '</a></span><br/> <img src="http://images.hook.tv/common/stars_' + current_rating + '.gif" height="13" width="62" alt="rated ' + current_rating + ' stars" title="rated ' + current_rating + ' stars" /> <br/> ' + current_viewCount + ' views';
	
				}
			}
	
	//alert("max: " + max + ",total: " + total + ", start: " + start);
	
			if((start + total) == max)
				var next_class = 'class="disabled"';
			else if(start == 0)
				var prev_class = 'class="disabled"';
	
			document.getElementById(video_series + "_left_arrow").innerHTML = '<a href="javascript: getNextItem(\'' + video_series + '\', ' + (start - 1) + ', ' + user_id + ', ' + total + ', ' + max + ', \'' + type + '\')"> <img src="http://images.hook.tv/common/button_previous.gif" height="34" width="34" border="0" alt="next video" title="next video" ' + prev_class + '/> </a>';
			
			document.getElementById(video_series + "_right_arrow").innerHTML = '<a href="javascript: getNextItem(\'' + video_series + '\', ' + (start + 1) + ', ' + user_id + ', ' + total + ', ' + max + ', \'' + type + '\')"> <img src="http://images.hook.tv/common/button_next.gif" height="34" width="34" border="0" alt="next video" title="next video" ' + next_class + ' /> </a>';
	
		   }
		}   	
	
		var sScript = '/includes/modules/getNextItem.php';
		
		var params = "user_id=" + user_id + "&start=" + start + "&total=" + total + "&type=" + type;
	
		xmlHttpRequest.open("POST", sScript, true);
	
		//Send the proper header information along with the request
		xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttpRequest.setRequestHeader("Content-length", params.length);
		xmlHttpRequest.setRequestHeader("Connection", "close");
		xmlHttpRequest.send(params);
	}
	

}

function toggleVideoSave(sContent, sMethod, asset_key){

	// use ajax to save profile data

	var xmlHttpRequest = getXmlObj();

	var title = urlencode(document.getElementById("txtTitle").value);
	var description = urlencode(document.getElementById("txtDescription").value);
	var accessMode = document.getElementById("accessMode").value;

	if(document.getElementById("admperm") != null)
		var admin = document.getElementById("admperm").value;
	else
		var admin = "";

	if(document.getElementById("publish") != null)
		var publish = document.getElementById("publish").value;
	else
		var publish = "";
	
	if(document.getElementById("txtAdDescription") != null)
		var admin_description = urlencode(document.getElementById("txtAdDescription").value);
	else
		var admin_description = "";

	var tags = document.getElementById("txtTags").value;

	if(document.getElementById("txtAdTags") != null)
		var admin_tags = document.getElementById("txtAdTags").value;
	else
		var admin_tags = "";

	if(document.getElementById("chkActive").checked == true)
		var active = 1;
	else 
		var active = 0;
	
	var ob = document.edit.groups;
	if(document.getElementById("groups") != null){
		selected = new Array(); 
		for (var i = 0; i < ob.options.length; i++) 
		if (ob.options[i].selected) {
			//alert(ob.options[i].value);
			selected.push(ob.options[i].value);
		}
	}

	var channels = "";

	if(document.edit.channels != null){
		var boxes = document.edit.channels.length;

		//var checkbox_array = document.getElementById("channels");
		for(var i=0; i < boxes; i++){
			if(document.edit.channels[i].checked) {
				//alert(document.edit.channels[i].value);
				channels = channels + document.edit.channels[i].value + ",";
			}
		}
	}

	//alert(txt);

	xmlHttpRequest.onreadystatechange=function(){
		if(xmlHttpRequest.readyState == 4){
			var response = xmlHttpRequest.responseText;
			var xml = xmlHttpRequest.responseXML;
			//alert(response);
			
			if(xml.getElementsByTagName("title")[0].firstChild != null)
				document.getElementById("lblTitle").innerHTML = xml.getElementsByTagName("title")[0].firstChild.nodeValue;
			
			if(xml.getElementsByTagName("description")[0].firstChild != null)
				document.getElementById("lblDescription").innerHTML = xml.getElementsByTagName("description")[0].firstChild.nodeValue;
			
			if(xml.getElementsByTagName("tags")[0].firstChild != null)
				document.getElementById("lblTags").innerHTML = xml.getElementsByTagName("tags")[0].firstChild.nodeValue;

			if(xml.getElementsByTagName("active")[0].firstChild.nodeValue == 1)
				document.getElementById("chkActive").checked == true;
			else
				document.getElementById("chkActive").checked == false;

			if(document.getElementById("txtAdDescription") != null){
				if(xml.getElementsByTagName("admin_description")[0].firstChild != null)
					document.getElementById("txtAdDescription").innerHTML = xml.getElementsByTagName("admin_description")[0].firstChild.nodeValue;
				else
					document.getElementById("txtAdDescription").innerHTML = "";
			}

			if(document.getElementById("txtAdDescription") != null){
				if(xml.getElementsByTagName("admin_tags")[0].firstChild != null)
					document.getElementById("txtAdTags").innerHTML = xml.getElementsByTagName("admin_tags")[0].firstChild.nodeValue;
				else
					document.getElementById("txtAdTags").innerHTML = "";
			}

			var sElementShow = sContent+"_entry";
			var sElementHide = sContent+"_display";

			if (sMethod == "hide"){
				sElementShow = sElementHide;
				sElementHide = sContent+"_entry";
			}

			var objLocationShow = returnElement(sElementShow);
			var objLocationHide = returnElement(sElementHide);

			if (objLocationShow && objLocationHide){
				showObject(objLocationShow);
				hideObject(objLocationHide);
			}

	    }

	}


	var sScript = '/includes/modules/postAssetData.php';
	//var user_id = document.getElementById("user_id").value;
	var params = "key=" + asset_key + "&title=" + title + "&description=" + description + "&tags=" + tags + "&adDescription=" + admin_description + "&adTags=" + admin_tags + "&active=" + active + "&channels=" + channels + "&publish=" + publish + "&accessMode=" + accessMode + "&admin=" + admin + "&selected=" + selected;

	//alert(params);
	xmlHttpRequest.open("POST", sScript, true);


	//Send the proper header information along with the request
	xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpRequest.setRequestHeader("Content-length", params.length);
	xmlHttpRequest.setRequestHeader("Connection", "close");
	xmlHttpRequest.send(params);
	
}

function echoError(data, ioArgs) {
  alert('Error when retrieving data from the server!');
}