var Num=0;
var stopflag=0;
var status = sequence = new Array();

function showLimits(arg)
{
	area = document.getElementById('limitsArea');
	area.innerHTML = '';
	html = "<table bgcolor='#cecece' cellspacing=1 cellpadding=1 border=0><tr><td width='10%'><b>Start</b></td><td><input type='text' size='2' name='start' id='start' maxlength='3' value='0'></td></tr><tr><td><b>Stop</b></td><td><input type='text' size='2' name='limit' id='limit' maxlength='3' value='50'></td></tr></table>";
	if(arg == 'on')
		area.innerHTML = html;
	else if(arg == 'off')
		area.innerHTML = '<input type=hidden name=recent value=1>';
}

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 */
function ajaxRequest2(data,element,loc) {
	var xmlhttp = web_request();

	if(xmlhttp.readyState == 4) {
      if(xmlhttp.responseText == 'false')
        ShowBox(element, '');
      else
  			window.location = loc; 
	}

	xmlhttp.open("GET", 'process_ajax.php?' + data, true);
  xmlhttp.send(null);

}

/** 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 */
function CategoryRequestNotActive(data, id) {
	var url = 'process_ajax.php';
	var yes = confirm("Are you Sure? OK To Continue");
		if (yes == true) {
			var perform = new Ajax.Request(url, {method:'get', parameters: data} );
			document.getElementById(id).hide();
		} 
}

/** For matching category */
function CategoryMatchRequestNotActive(data, id) {
	var url = 'process_ajax.php';
	var pars = 'select_notactive='+$F(data);
	var yes = confirm("Use This Category? OK To Continue");
	if (yes == true) {
		var perform = new Ajax.Request(url, {method:'get', parameters: pars} );
		document.getElementById(id).hide();
	}
}

/** 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 unscribe2 = new Ajax.Request(url, {method:'get',parameters: data,onComplete: function playlistDelete() 
				{   
					window.location=query;
				}
			}
		);
	}
}

function confirmed(){
	var yes = confirm("Are you sure?");
	if (yes == true) {
		return true;
	} else {
		return false;
	}
}

/** To check data on friend list */
function CheckData() {
	if(document.getElementById('sitename').value == '') {
		alert('Please Enter Sitename');
		document.getElementById('sitename').focus();
		return false;
	}
	
	if(document.getElementById('siteurl').value == '') {
		alert('Please Enter Site URl');
		document.getElementById('siteurl').focus();
		return false;
	}
}

/** To check data on auto update */
function CheckDataAutoUpdate() {
	
	if(document.getElementById('dump_url').value == '') {
		alert('Please Enter Dump URL');
		document.getElementById('dump_url').focus();
		return false;
	}
	
	var frequency = document.getElementById('frequency');
	if(frequency.options[frequency.selectedIndex].value == '') {
		alert('Please Choose Frequency');
		return false;
	}
	
	var channel = document.getElementById('channel');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Channel');
		return false;
	}
	
	var channel = document.getElementById('type');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Type');
		return false;
	}
	
	var channel = document.getElementById('insertion');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Insertion Type');
		return false;
	}
	
	var channel = document.getElementById('img_type');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Image Type');
		return false;
	}
}

/** To check data on dump import */
function CheckDataImport() {	
	var channel = document.getElementById('channel');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Channel');
		return false;
	} 
	
	if(document.getElementById('file').value == '') {
		alert('Please Enter Dump File');
		document.getElementById('file').focus();
		return false;
	}
}

function CheckDataXMLImport() {	
	var channel = document.getElementById('channel');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Channel');
		return false;
	} 
	
	if(document.getElementById('url').value == '') {
		alert('Please enter a Valid URL');
		document.getElementById('url').focus();
		return false;
	}
}


/** To check data on auto update */
function CheckDataEmbed() {
		
	var channel = document.getElementById('channel');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Channel');
		return false;
	}
	
	var image = document.getElementById('img_type');
	if(image.options[image.selectedIndex].value == 'url') {
		if(document.getElementById('imageUrlData').value == '') {
			alert('Please Enter Image Url');
			document.getElementById('imageUrlData').focus();
			return false;
		}
	} else {
		if(document.getElementById('imageUploadData').value == '') {
			alert('Please Browse Image Location');
			document.getElementById('imageUploadData').focus();
			return false;
		}
	}
	
	if(document.getElementById('embed').value == '') {
		alert('Please Enter Embed Video ');
		document.getElementById('embed').focus();
		return false;
	}
}

/** To check channel */
function CheckChannel() {
	var channel = document.getElementById('channel');
	if(channel.options[channel.selectedIndex].value == 'new') {
		document.getElementById('new_channel').show();
		document.getElementById('not_new_channel').hide();
	} else {
		document.getElementById('new_channel').hide();
		document.getElementById('not_new_channel').show();
	}
}

/** To show the second channel banner */
function ShowHTMLBanner() {
	document.getElementById('secondBanner').show();
}

/** To check image what type of image to be select on embed */ 
function CheckImage() {
	var image = document.getElementById('img_type');
	if(image.options[image.selectedIndex].value == 'url') {
		document.getElementById('imageUrl').show();
		document.getElementById('imageUpload').hide();
	} else {
		document.getElementById('imageUrl').hide();
		document.getElementById('imageUpload').show();
	}
}

function Delete(url) {
	var check = confirm("Are You Sure? Click (OK) to Continue");
	if (check == true) {
		window.location=url;
	}
}

/** 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;
	}
}

function checkDate(nums)
{
	if(document.getElementById('date').value == '' && document.getElementById('vperd').value == '')
	{
		document.forms['myforms'].submit();
	}
	else if(document.getElementById('date').value != '' && document.getElementById('vperd').value == '')
	{ 
		document.getElementById('vperd').style.backgroundColor='tomato';
		new Effect.Shake('vperd'); 
		return false;
	}
	else if(document.getElementById('vperd').value != '' && document.getElementById('date').value == '')
	{
		document.getElementById('date').style.backgroundColor='tomato ';
		new Effect.Shake('date'); 
		return false;
		
	}
	else
	{
		
		var error = (cal1.prs_date(document.getElementById('date').value)); 

		if(error) 
		{
			var objRegExp  = /(^-?\d\d*$)/;
			if(!objRegExp.test(document.getElementById('vperd').value) || (document.getElementById('vperd').value) <= 0)
				  	alert('Invalid Number');
			else
				document.forms['myforms'].submit();
			
		}
		
	}
	
	
}

