/*
***********************************************************************************************************
(c) www.joomla-alem.com January 2007

Script for Seyret component.
***********************************************************************************************************
*/
	window.onload = function () {
		};
		
		//general request object
		function createRequestObject() {
			var xRequest='';
			if (window.XMLHttpRequest) 
			{
				xRequest=new XMLHttpRequest(); 
			}
			else if (typeof ActiveXObject != "undefined")
			{
				xRequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			return xRequest;
		}
		
		var http = createRequestObject();

		
		function nextlist() {
		document.getElementById("blockit").style.visibility="visible";
		document.getElementById("ajxgif").style.visibility="visible";
		var startstring=document.getElementById("navstart").value;
		var thecatid=document.getElementById("catid").value;
		var theordtype=document.getElementById("orderingtype").value;
		var theordkey=document.getElementById("orderingkey").value;		
		http.open('post', 'index2.php?option=com_seyret&no_html=1&task=videolist&act=next&sender=ajax&navstart='+startstring+'&catid='+thecatid+'&orkey='+theordkey+'&ortyp='+theordtype);
		http.onreadystatechange = handleResponselist;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send('');
		}
		
		function previouslist() {
		document.getElementById("blockit").style.visibility="visible";
		document.getElementById("ajxgif").style.visibility="visible";
		var thecatid=document.getElementById("catid").value;
		var startstring=document.getElementById("navstart").value;
		var theordtype=document.getElementById("orderingtype").value;
		var theordkey=document.getElementById("orderingkey").value;
		http.open('post', 'index2.php?option=com_seyret&no_html=1&task=videolist&act=prev&sender=ajax&navstart='+startstring+'&catid='+thecatid+'&orkey='+theordkey+'&ortyp='+theordtype);
		http.onreadystatechange = handleResponselist;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send('');
		}

//*************************************
		function gopage() {
		var limstep=document.getElementById("limitstep").value;
		var pagnum=document.getElementById("pagenumber").value;
		var thecatid=document.getElementById("cid").value;
		document.getElementById("blockit").style.visibility="visible";
		document.getElementById("ajxgif").style.visibility="visible";
		var intlimstep=parseInt(limstep);
		var theordtype=document.getElementById("orderingtype").value;
		var theordkey=document.getElementById("orderingkey").value;
		var intpagnum=parseInt(pagnum);
		var startstring=intlimstep*(intpagnum-2);
		http.open('post', 'index2.php?option=com_seyret&no_html=1&task=videolist&act=next&sender=ajax&navstart='+startstring+'&catid='+thecatid+'&orkey='+theordkey+'&ortyp='+theordtype);
		http.onreadystatechange = handleResponselist;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send('');
		}

		function handleResponselist() {

			if(http.readyState == 4){
				var response = http.responseText;
				document.getElementById("blockit").style.visibility="hidden";
				document.getElementById("ajxgif").style.visibility="hidden";				
				document.getElementById("videolistdiv").innerHTML = response;
			}
		}		
//*************************************



//*************************************
		function sndReqDirectory(id) {
		document.getElementById("blockit").style.visibility="visible";
		document.getElementById("ajxgif").style.visibility="visible";
		var theordtype=document.getElementById("orderingtype").value;
		var theordkey=document.getElementById("orderingkey").value;	
		http.open('post', 'index2.php?option=com_seyret&no_html=1&task=changedirectory&catid='+id+'&orkey='+theordkey+'&ortyp='+theordtype);
		http.onreadystatechange = handleResponseChangeDirectory;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send('');
		}		

		function handleResponseChangeDirectory() {
			if(http.readyState == 4){
				var response = http.responseText;
				document.getElementById("blockit").style.visibility="hidden";
				document.getElementById("ajxgif").style.visibility="hidden";				
				document.getElementById("hiddenvalues").innerHTML = response;
				document.getElementById("groupcontext").innerHTML = document.getElementById("directoriesresult").innerHTML;
				document.getElementById("videolistdiv").innerHTML = document.getElementById("videoslistresult").innerHTML;
			}
		}		
//*************************************


		function sortbytype(type){
		document.getElementById("orderingtype").value=type;
		gopage();
		}

		function sortbykey(){
		var key=document.getElementById("orderingkeyselect").value;
		document.getElementById("orderingkey").value=key;		
		gopage();
		}

		function applyvideolink() {
		var videolink=document.getElementById("videolink").value;		
		var newvideolink1=videolink.replace(/&/g,"*am*");
		var newvideolink2=newvideolink1.replace(/=/g,"*eq*");
		var strReplaceAll = newvideolink2;
        var intIndexOfMatch = strReplaceAll.indexOf( "/" );
  
		 // Loop over the string value replacing out each matching
		 // substring.
		 while (intIndexOfMatch != -1){
		 // Relace out the current instance.
		 strReplaceAll = strReplaceAll.replace( "/", "25ja25" )
		  
		 // Get the index of any next matching substring.
		 intIndexOfMatch = strReplaceAll.indexOf( "/" );
		 }
		
		http.open('post', 'index2.php?option=com_seyret&no_html=1&task=applyvideolink&videourl='+strReplaceAll);
		http.onreadystatechange = handleResponseVideolinkdetails;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send('');
		}
		
		function handleResponseVideolinkdetails() {
		
			if(http.readyState == 4){
				var response = http.responseText;
				document.getElementById("videodetailsinput").innerHTML = response;
			}
		}

		
		
//*************************************
		function sndReqVideo(id) {
		document.getElementById("blockit").style.visibility="visible";
		document.getElementById("ajxgif").style.visibility="visible";
		http.open('post', 'index2.php?option=com_seyret&no_html=1&task=showvideo&id='+id+'&sender=ajax');
		http.onreadystatechange = handleResponseVideo;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send('');
		}
				
		function handleResponseVideo() {
		
			if(http.readyState == 4){
				var response = http.responseText;
				document.getElementById("blockit").style.visibility="hidden";
				document.getElementById("ajxgif").style.visibility="hidden";
				document.getElementById("hiddenvalues").innerHTML = response;
				document.getElementById("videotitlearea").innerHTML = document.getElementById("hiddenvideotitle").innerHTML;
				document.getElementById("showvideo").innerHTML = document.getElementById("hiddenvideoembed").innerHTML;

				document.getElementById("videodetailsarea").innerHTML = document.getElementById("hiddenvideodetails").innerHTML;
				document.getElementById("videooperationsarea").innerHTML = document.getElementById("hiddenvideooperations").innerHTML;
				document.getElementById("votearea").innerHTML = document.getElementById("hiddenvotearea").innerHTML;

				
				}
	
		}
//*************************************






		function showvideoinfo(viddivid) {
		var vidid="videoinfo"+viddivid;
		document.getElementById(vidid).style.visibility="visible";		
		}
		
		function hidevideoinfo(viddivid) {
		var vidid="videoinfo"+viddivid;
		document.getElementById(vidid).style.visibility="hidden";		
		}		
		
		
		function openinpopup(url,width,height){
		window.open (url,'ana' ,'top=300, left=500, menubar=no, toolbar=no, scrollbars=yes, location=no, width='+width+', height='+height+'')
		}

		function showdirectlink() {
		var shwdrstatus=document.getElementById("directlink").style.visibility;
			if (shwdrstatus=="visible"){
			document.getElementById("directlink").style.visibility="hidden";	
			} else {
			document.getElementById("directlink").style.visibility="visible";
			document.getElementById("videolink").select();	
			}
		}

		function showshareembed() {
		var shwdrstatus=document.getElementById("showshareembed").style.visibility;
			if (shwdrstatus=="visible"){
			document.getElementById("showshareembed").style.visibility="hidden";	
			} else {
			document.getElementById("showshareembed").style.visibility="visible";
			document.getElementById("embedlink").select();	
			}
		}

		
		function rnormal(){
		var normalrating=document.getElementById("hiddenrating").innerHTML;
		document.getElementById("ratingscale").style.width=normalrating;
		document.getElementById("yellowratingscale").style.width="0%";
		}
		
		
		function ratinganimate(width){
		document.getElementById("ratingscale").style.width="0%";
		document.getElementById("yellowratingscale").style.width=width+"%";
		}
		
		function voteclick(point) {
		document.getElementById("blockit").style.visibility="visible";
		document.getElementById("ajxgif").style.visibility="visible";
		var videoid=document.getElementById("hiddenthevideoid").innerHTML;
		http.open('post', 'index2.php?option=com_seyret&no_html=1&task=voteclick&point='+point+'&videoid='+videoid);
		http.onreadystatechange = handleResponsevote;
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send('');
		}
		
				function handleResponsevote() {
			if(http.readyState == 4){
				var response = http.responseText;
				document.getElementById("blockit").style.visibility="hidden";
				document.getElementById("ajxgif").style.visibility="hidden";
				document.getElementById("hiddenvalues").innerHTML = response;
				document.getElementById("votearea").innerHTML = document.getElementById("hiddennewstars").innerHTML;
				var message=document.getElementById("hiddenmessage").innerHTML;
				alert(message);
			}
		}
		

		
		
		
		