var Num=0;
var stopflag=0;
var status = sequence = new Array();

/** For adding favorites */
function ajaxRequest(data,element,val) {
	var url = 'process_ajax.php';
	var perform = new Ajax.Request(url, {method:'get', parameters: data, onComplete: 
		   function checkStatus(e){
		   		if(e.responseText == 'false') {
					ShowBox(element,val);
				} else {
					alert(e.responseText);
				}
		   } 
		} 
	);
}

/** For video flagging */
function ajaxRequest2(data,element,loc) {
	var url = 'process_ajax.php';
	var perform = new Ajax.Request(url, {method:'get', parameters: data, onComplete: 
		   function checkStatus(e){
		   		if(e.responseText == 'false') {
					ShowBox(element,'');
				} else {
					window.location=loc
				}
		   } 
		} 
	);
}

/** For star rating */
function RatingRequest(data) {
	var url = 'process_ajax.php';
	var target = 'rating';
	var perform = new Ajax.Updater(target, url, {method:'get', parameters: data });

}

/** 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} );
			$(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} );
		$(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.';
		$('messageBox').innerHTML= message;
	}
	
	new Effect.BlindDown(element,{duration:0.2});
}
	
/** To hide login box */	
function HideBox(element) {
	new Effect.BlindUp(element,{duration:0.2});
}
		

/** For related video */		
function change_tab(val) {
	switch(val) {
		case 'related_vid': 
			//$('related_vid_li').setStyle({background: '#CCC'});
			//$('morefromuser_li').setStyle({background: '#FFF'});
			
			$('related_vid').show();
			$('morefromuser').hide();
		break;
		case 'morefromuser': 
			//$('morefromuser_li').setStyle({background: '#CCC'});
			//$('related_vid_li').setStyle({background: '#FFF'});
			$('related_vid').hide();
			$('morefromuser').show();	
		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($('sitename').value == '') {
		alert('Please Enter Sitename');
		$('sitename').focus();
		return false;
	}
	
	if($('siteurl').value == '') {
		alert('Please Enter Site URl');
		$('siteurl').focus();
		return false;
	}
}

/** To check data on auto update */
function CheckDataAutoUpdate() {
	
	if($('dump_url').value == '') {
		alert('Please Enter Dump URL');
		$('dump_url').focus();
		return false;
	}
	
	var frequency = $('frequency');
	if(frequency.options[frequency.selectedIndex].value == '') {
		alert('Please Choose Frequency');
		return false;
	}
	
	var channel = $('channel');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Channel');
		return false;
	}
	
	var channel = $('type');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Type');
		return false;
	}
	
	var channel = $('insertion');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Insertion Type');
		return false;
	}
	
	var channel = $('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 = $('channel');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Channel');
		return false;
	} 
	
	if($('file').value == '') {
		alert('Please Enter Dump File');
		$('file').focus();
		return false;
	}
}

/** To check data on auto update */
function CheckDataEmbed() {
		
	var channel = $('channel');
	if(channel.options[channel.selectedIndex].value == '') {
		alert('Please Choose Channel');
		return false;
	}
	
	var image = $('img_type');
	if(image.options[image.selectedIndex].value == 'url') {
		if($('imageUrlData').value == '') {
			alert('Please Enter Image Url');
			$('imageUrlData').focus();
			return false;
		}
	} else {
		if($('imageUploadData').value == '') {
			alert('Please Browse Image Location');
			$('imageUploadData').focus();
			return false;
		}
	}
	
	if($('embed').value == '') {
		alert('Please Enter Embed Video ');
		$('embed').focus();
		return false;
	}
}

/** To check channel */
function CheckChannel() {
	var channel = $('channel');
	if(channel.options[channel.selectedIndex].value == 'new') {
		$('new_channel').show();
		$('not_new_channel').hide();
	} else {
		$('new_channel').hide();
		$('not_new_channel').show();
	}
}

/** To show the second channel banner */
function ShowHTMLBanner() {
	$('secondBanner').show();
}

/** To check image what type of image to be select on embed */ 
function CheckImage() {
	var image = $('img_type');
	if(image.options[image.selectedIndex].value == 'url') {
		$('imageUrl').show();
		$('imageUpload').hide();
	} else {
		$('imageUrl').hide();
		$('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();
			
		}
		
	}
	
	
}
