var Num=0;
var stopflag=0;
var status = sequence = new Array();
   
function toggleClipsThumbsWatch()
{
	if(document.getElementById('toggleThumb').style.display == '')
	{ 
		document.getElementById('toggleClipThumbText').innerHTML = 'Show Thumbs';
		document.getElementById('toggleThumb').style.display ='none';
		document.getElementById('toggleClip').style.display ='';
		
	}
	else
	{
		document.getElementById('toggleClipThumbText').innerHTML = 'Show Clips';
		document.getElementById('toggleClip').style.display ='none';
		document.getElementById('toggleThumb').style.display ='';
	}
}
 
function getMoreTags(max)
{
	var xmlHttp; 
	
		try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		  }
		catch (e)
		  {
		  // Internet Explorer
		  try
		    {
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		    }
		  catch (e)
		    {
		    try
		      {
		      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		      }
		    catch (e)
		      {
		      alert("Your browser does not support AJAX!");
		      return false;
		      }
		    }
		  } 
		  
	  arg    =  "function/function.php?parseAllTagCloud="+max+"&"+ new  Date().getTime();
	  	
	 xmlHttp.open("GET",arg,true);   						
	 
	  xmlHttp.onreadystatechange=function()
	    {
	   	 if(xmlHttp.readyState==4)
	      {
	      	ret = (xmlHttp.responseText); 
	      	// document.getElementById(uid+'-row').style.backgroundColor = '#B5FF6F'; 
	      	//  setTimeout("document.getElementById('"+uid+"-row').style.backgroundColor = '#FFFFFF';",1000)
	       
	      	 try
	      	 {
	      	 	temp = document.getElementById('tagArea');
	      	 	temp.innerHTML = ret;
	      	 }
	      	 catch (e){} 
	      	  
	      }
	    }
	  
	   xmlHttp.send(null);
}

function getLessTags(max)
{
	var xmlHttp; 
	
		try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		  }
		catch (e)
		  {
		  // Internet Explorer
		  try
		    {
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		    }
		  catch (e)
		    {
		    try
		      {
		      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		      }
		    catch (e)
		      {
		      alert("Your browser does not support AJAX!");
		      return false;
		      }
		    }
		  } 
		  
	  arg    =  "function/function.php?parseTagCloud="+max+"&reload=1&"+ new  Date().getTime();
	  	
	 xmlHttp.open("GET",arg,true);   						
	 
	  xmlHttp.onreadystatechange=function()
	    {
	   	 if(xmlHttp.readyState==4)
	      {
	      	ret = (xmlHttp.responseText); 
	      	// document.getElementById(uid+'-row').style.backgroundColor = '#B5FF6F'; 
	      	//  setTimeout("document.getElementById('"+uid+"-row').style.backgroundColor = '#FFFFFF';",1000)
	       
	      	 try
	      	 {
	      	 	temp = document.getElementById('tagArea');
	      	 	temp.innerHTML = ret;
	      	 }
	      	 catch (e){} 
	      	  
	      }
	    }
	  
	   xmlHttp.send(null);
}

function web_request() {
	  var xmlhttp;

  try {
    xmlhttp = new XMLHttpRequest();
  }
  catch(e) {
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
				alert("Your browser doesn't support the HTTP request object");
      }
    }
  }
	
	return xmlhttp;

}

/** For adding favorites */
function ajaxRequest(data,element,val) {
	var xmlhttp = web_request();
	
	xmlhttp.onreadystatechange = function() {

		if(xmlhttp.readyState == 4) {
			if(xmlhttp.responseText == 'false') 
				ShowBox(element, val);
			else
				alert(xmlhttp.responseText);
		}		

	}

	xmlhttp.open("GET", 'process_ajax.php?' + data, true);
	xmlhttp.send(null);

}

/** For video flagging */
 

/** For star rating */
function RatingRequest(data) {
	var xmlhttp = web_request();
	
	xmlhttp.onreadystatechange = function () {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById('rating').innerHTML = xmlhttp.responseText;
	};
	
	xmlhttp.open("GET", 'process_ajax.php?' + data, true);
	xmlhttp.send(null);
}

/** For adding category */
 

/** Checking existing username on registration */
function seek() {
	var url = 'process_ajax.php';
	var pars = 'field_username='+escape($F('field_username'));
	var target = 'info';
	var perform = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
}

/** To show login box */
function ShowBox(element,val) {
	
	if(val != '') {
		var message = (val=='flag') ? 'to flag this video.' : 'to add to favorites.';
		document.getElementById('messageBox').innerHTML= message;
	}

	document.getElementById(element).style.display = 'block';
	
}
	
/** To hide login box */	
function HideBox(element) {
	document.getElementById(element).style.display = 'none';
}
		

/** For related video */		
function change_tab(val) {
	switch(val) {
		case 'related_vid': 
			//document.getElementById('related_vid_li').setStyle({background: '#CCC'});
			//document.getElementById('morefromuser_li').setStyle({background: '#FFF'});
			
			document.getElementById('related_vid').style.display = 'block';
			document.getElementById('morefromuser').style.display = 'none';
		break;
		case 'morefromuser': 
			//document.getElementById('morefromuser_li').setStyle({background: '#CCC'});
			//document.getElementById('related_vid_li').setStyle({background: '#FFF'});
			document.getElementById('related_vid').style.display = 'none';
			document.getElementById('morefromuser').style.display = 'block';	
		break;		
	}			
}
	
function process(data,query) {
	var url = 'process_ajax.php';
	var yes = confirm("Are You Sure? Click (OK) to Continue");
	if (yes == true) 
	{
		var xmlhttp = web_request();
	
		xmlhttp.onreadystatechange = function () 
		{
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
				window.location=query; 
		};
		
		xmlhttp.open("GET", 'process_ajax.php?' + data, true);
		xmlhttp.send(null); 
		
	}
}

function confirmed(){
	var yes = confirm("Are you sure?");
	if (yes == true) {
		return true;
	} else {
		return false;
	}
}

  
/** For Previewing the thumb */
function preview() {
	var url 	= 'process_ajax.php';
	var target 	= 'preview';
	var data	='thumb_preview='+$F('prev_thumb');
	var perform = new Ajax.Updater(target, url, {method:'get', parameters: data });
}

/** For Previewing banner, also now used on all preview process */
function PreviewBanner(data, action) {
	var url		= 'preview.php?view='+action+'&value='+escape($F(data));
	window.open(url);
}

/** For image roll over process*/
function Start(str,div) {	
	status[div] = 1;
	newArray = str.split(',');
	cnt = newArray.length;
	var first = 1;
	
	for(var j=0;j<cnt;j++) { 
		sequence[j] = new Image();
		loadpic(newArray[j],j); 
	}
	slideshow(0,div,cnt);
}

/** For image roll over process*/
function loadpic(url,j) {
	if(status) {
		sequence[j].src = url;
	}
}

/** For image roll over process*/
function slideshow(i,div,cnt) {
	if(status[div]) {
		if(i == cnt) {
			i = 0;
		}
	document.getElementById(div).src=sequence[i].src;
	i++;
	setTimeout("slideshow("+i+",'"+div+"','"+cnt+"')",550); 
	}
}

/** For image roll over process*/
function Stop(div) {
	status[div]=0;
}

/** To check all on the checkbox */
function checkAll(field) {
	if (field.length > 0) {
		for (i = 0; i < field.length; i++) {	
			field[i].checked = true;
		}			
	} else {
		field.checked = true;
	}
}

/** To uncheck all on the checkbox */
function uncheckAll(field) {
	if (field.length > 0) {
		for (i = 0; i < field.length; i++)
		field[i].checked = false;
	} else {
		field.checked = false;
	}
} 