function Validate_channel()
{
	var chlist = document.getElementById('chlist');
	var chlist_supcat = document.getElementById('supChlist');
	var chlist_length = chlist.options.length;
	var chlist_Suplength = chlist_supcat.options.length;
	
	var i;
	var count_chlist =0;
	for(i=0;i<chlist_length;i++)
	{
		if(chlist.options[i].selected == true)
		{
			count_chlist = count_chlist+1;
		}
	}
	
	var j;
	var count_chlistSupcat =0;
	for(j=0;j<chlist_Suplength;j++)
	{
		if(chlist_supcat.options[j].selected == true)
		{
			count_chlistSupcat = count_chlistSupcat+1;
		}
	}
	var total = count_chlistSupcat+count_chlist;
	if(total >5)
	{
		alert("Please select up to five channels.");
		return false;
	}
}
//start of upload profile image section
function uploadThumb()
{
	document.getElementById('uploadthumb').style.display='block';
	document.getElementById('browse_div').style.display='block';	
	document.getElementById("userpic").value='';
	document.getElementById("photo").reset();
	$('pic_frame').src = 'blank.html';
	$('upload_box').style.width = '500px';
	$('UPLOAD_HEADERctnr').style.width = '442px';
	$('pic_frame').style.width = '350px';
	$('pic_frame').style.height = '100px';
	location.href = "#upload";
	//$('upload_frame').innerHTML = '<iframe name="pic_frame" id="pic_frame" src="crop.php" frameborder="0" allowtransparency="true" style="background: #ffffff;" scrolling="no" height="150" width="500"></iframe>';

}

function uploadBcastThumb()
{
	document.getElementById('bcast_uploadthumb').style.display='block';
	document.getElementById('browse_div').style.display='block';	
	document.getElementById("userpic").value='';
	document.getElementById("bcast_photo").reset();
	$('bcast_pic_frame').src = 'blank.html';
	$('upload_box').style.width = '500px';
	$('UPLOAD_HEADERctnr').style.width = '442px';
	$('bcast_pic_frame').style.width = '350px';
	$('bcast_pic_frame').style.height = '100px';
	location.href = "#add_upload";
	//$('upload_frame').innerHTML = '<iframe name="pic_frame" id="pic_frame" src="crop.php" frameborder="0" allowtransparency="true" style="background: #ffffff;" scrolling="no" height="150" width="500"></iframe>';

}

function check_image_upload()
{
	if(parent.document.getElementById('image_path').value == "")
	{
		setTimeout('check_image_upload()',1000);
	}
	else
	{
		document.getElementById('edit_bcast_image').src = parent.document.getElementById('image_path').value;
		parent.document.getElementById('image_path').value = "";
	}
}			

//Start of edit thumb
function uploadEditThumb()
{
	check_image_upload();
	parent.document.getElementById('edit_bcast_thumb').style.display='block';
	parent.document.getElementById('browse_div').style.display='block';	
	parent.document.getElementById("edit_bcast_photo").reset();
	parent.document.getElementById("edit_bcast_pic_frame").src = 'blank.html';
	parent.document.getElementById("upload_box").style.width = '500px';
	parent.document.getElementById("UPLOAD_HEADERctnr").style.width = '442px';
	parent.document.getElementById("edit_bcast_pic_frame").style.width = '350px';
	parent.document.getElementById("edit_bcast_pic_frame").style.height = '100px';
	parent.document.getElementById("edit_bcast_thumb").style.zIndex = '1000';
	/*$('pic_frame').src = 'blank.html';
	$('upload_box').style.width = '500px';
	$('UPLOAD_HEADERctnr').style.width = '442px';
	$('pic_frame').style.width = '350px';
	$('pic_frame').style.height = '100px';*/
	location.href = "#edit_upload";
	//$('upload_frame').innerHTML = '<iframe name="pic_frame" id="pic_frame" src="crop.php" frameborder="0" allowtransparency="true" style="background: #ffffff;" scrolling="no" height="150" width="500"></iframe>';

}

function showProcessLoader(divId)
{
	document.getElementById(divId).style.display = 'block';
}
function hideProcessLoader(divId)
{
	document.getElementById(divId).style.display = 'none';
}
function closeUploadThumb()
{
	$('pic_frame').src = 'blank.html';
	document.getElementById('uploadthumb').style.display = 'none';
}	
function closeUploadThumbBlogin()
{
	$('pic_frame').src = 'blank.html';
	document.getElementById('uploadthumb').style.display = 'none';
	document.getElementById('upload_status1').checked = true;
}	
function saveThumbnail()
{
	  document.getElementById('ajaxLoader1').style.display = 'block';
	  var x1 = document.getElementById('x1').value;
	  var y1 = document.getElementById('y1').value;
	  var x2 = document.getElementById('x2').value;
	  var y2 = document.getElementById('y2').value;
	  var w = document.getElementById('w').value;
	  var h = document.getElementById('h').value;
	  
	  var xmlHttpReq = false;
	  var self = this;
	  // Mozilla/Safari
	  if (window.XMLHttpRequest) {
	      self.xmlHttpReq = new XMLHttpRequest();
	  }
	  // IE
	  else if (window.ActiveXObject) {
	      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  var strURL = "crop.php?action=SAVE_THUMBNAIL";
	  var params = "&x1="+x1+"&y1="+y1+"&x2="+x2+"&y2="+y2+"&w="+w+"&h="+h;

	  self.xmlHttpReq.open('POST', strURL, true);
	  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  self.xmlHttpReq.onreadystatechange = function() {
	      if (self.xmlHttpReq.readyState == 4) {
		  handleSaveThumbnail(self.xmlHttpReq.responseText);
	      }
	 }
	 self.xmlHttpReq.send(params);			
			
}
function handleSaveThumbnail(str)
{
	document.getElementById('ajaxLoader1').style.display = 'none';
	if(str == "SUCCESS")
	{
			refreshImage();
			parent.document.getElementById("userpic").value='1';
			//parent.document.getElementById("delete").disabled='';
			parent.document.getElementById('pic_frame').src = 'blank.html';
			parent.document.getElementById('uploadthumb').style.display = 'none';
	}
	else if(str == "PAGE_RELOAD")
			parent.location.reload();
}

function saveThumbnailBlogin()
{
	  document.getElementById('ajaxLoader1').style.display = 'block';
	  var x1 = document.getElementById('x1').value;
	  var y1 = document.getElementById('y1').value;
	  var x2 = document.getElementById('x2').value;
	  var y2 = document.getElementById('y2').value;
	  var w = document.getElementById('w').value;
	  var h = document.getElementById('h').value;
	  var unreg_username = document.getElementById('unregistered_username').value;
	  
	  var xmlHttpReq = false;
	  var self = this;
	  // Mozilla/Safari
	  if (window.XMLHttpRequest) {
	      self.xmlHttpReq = new XMLHttpRequest();
	  }
	  // IE
	  else if (window.ActiveXObject) {
	      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  var strURL = "crop_beforelogin.php?action=SAVE_THUMBNAIL";
	  var params = "&x1="+x1+"&y1="+y1+"&x2="+x2+"&y2="+y2+"&w="+w+"&h="+h+"&unregistered_username="+unreg_username;

	  self.xmlHttpReq.open('POST', strURL, true);
	  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  self.xmlHttpReq.onreadystatechange = function() {
	      if (self.xmlHttpReq.readyState == 4) {
		  handleSaveThumbnailBlogin(self.xmlHttpReq.responseText);
	      }
	 }
	 self.xmlHttpReq.send(params);
}

function saveBcastThumbnailBlogin()
{
	  document.getElementById('ajaxLoader1').style.display = 'block';
	  var x1 = document.getElementById('x1').value;
	  var y1 = document.getElementById('y1').value;
	  var x2 = document.getElementById('x2').value;
	  var y2 = document.getElementById('y2').value;
	  var w = document.getElementById('w').value;
	  var h = document.getElementById('h').value;
	  var unreg_username = document.getElementById('unregistered_username').value;
	  
	  var xmlHttpReq = false;
	  var self = this;
	  // Mozilla/Safari
	  if (window.XMLHttpRequest) {
	      self.xmlHttpReq = new XMLHttpRequest();
	  }
	  // IE
	  else if (window.ActiveXObject) {
	      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  var strURL = "crop_bcastimage.php?action=SAVE_THUMBNAIL";
	  var params = "&x1="+x1+"&y1="+y1+"&x2="+x2+"&y2="+y2+"&w="+w+"&h="+h+"&unregistered_username="+unreg_username;

	  self.xmlHttpReq.open('POST', strURL, true);
	  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  self.xmlHttpReq.onreadystatechange = function() {
	      if (self.xmlHttpReq.readyState == 4) {
		  handleBcastSaveThumbnailBlogin(self.xmlHttpReq.responseText);
	      }
	 }
	 self.xmlHttpReq.send(params);
}
function closeBcastThumbBlogin()
{
	$('bcast_pic_frame').src = 'blank.html';
	document.getElementById('bcast_uploadthumb').style.display = 'none';
	document.getElementById('upload_status1').checked = true;
}	
function closeEditUploadThumbBlogin()
{
	$('edit_bcast_pic_frame').src = 'blank.html';
	document.getElementById('edit_bcast_thumb').style.display = 'none';
	document.getElementById('upload_status1').checked = true;
}	


function saveEditBcastThumbnailBlogin()
{
	  document.getElementById('ajaxLoader1').style.display = 'block';
	  var x1 = document.getElementById('x1').value;
	  var y1 = document.getElementById('y1').value;
	  var x2 = document.getElementById('x2').value;
	  var y2 = document.getElementById('y2').value;
	  var w = document.getElementById('w').value;
	  var h = document.getElementById('h').value;
	  var unreg_username = document.getElementById('unregistered_username').value;
	  
	  var xmlHttpReq = false;
	  var self = this;
	  // Mozilla/Safari
	  if (window.XMLHttpRequest) {
	      self.xmlHttpReq = new XMLHttpRequest();
	  }
	  // IE
	  else if (window.ActiveXObject) {
	      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  var strURL = "crop_edit_bcastimage.php?action=SAVE_THUMBNAIL";
	  var params = "&x1="+x1+"&y1="+y1+"&x2="+x2+"&y2="+y2+"&w="+w+"&h="+h+"&unregistered_username="+unreg_username;

	  self.xmlHttpReq.open('POST', strURL, true);
	  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  self.xmlHttpReq.onreadystatechange = function() {
	      if (self.xmlHttpReq.readyState == 4) {
		  handleEditBcastSaveThumbnailBlogin(self.xmlHttpReq.responseText);
	      }
	 }
	 self.xmlHttpReq.send(params);
}
function handleSaveThumbnailBlogin(str)
{
	document.getElementById('ajaxLoader1').style.display = 'none';
	if(str == "SUCCESS")
	{
			refreshImage();
			//parent.document.getElementById("userpic").value='1';
			//parent.document.getElementById("delete").disabled='';
			parent.document.getElementById('pic_frame').src = 'blank.html';
			parent.document.getElementById('uploadthumb').style.display = 'none';
	}
}
function showLoader()
{
	document.getElementById('ajaxLoader1').style.display = 'block';
}
//end of upload profile image section
function clearThumb(path) {
	document.getElementById("profile_image").src = baseurl+"/images/no_User_pic.jpg";
	}
function clearBcastThumb(path) {
	document.getElementById("profile_bcast_image").src = baseurl+"/images/no_User_pic.jpg";
}
function clearThumb(path) {
	document.getElementById("edit_bcast_image").src = baseurl+"/images/no_User_pic.jpg";
}

function handleBcastSaveThumbnailBlogin(str)
{
	document.getElementById('ajaxLoader1').style.display = 'none';
	if(str == "SUCCESS")
	{
			refreshImage();
			//parent.document.getElementById("userpic").value='1';
			//parent.document.getElementById("delete").disabled='';
			parent.document.getElementById('bcast_pic_frame').src = 'blank.html';
			parent.document.getElementById('bcast_uploadthumb').style.display = 'none';
	}
}	
function handleEditBcastSaveThumbnailBlogin(str)
{
	document.getElementById('ajaxLoader1').style.display = 'none';
	if(str == "SUCCESS")
	{
			refreshImage();
			//parent.document.getElementById("userpic").value='1';
			//parent.document.getElementById("delete").disabled='';
			parent.document.getElementById('edit_bcast_pic_frame').src = 'blank.html';
			parent.document.getElementById('edit_bcast_thumb').style.display = 'none';
	}
}	