//Check Series 
function checkSeries(){
var index = document.form.MediaType.options.selectedIndex;
var value = document.form.MediaType.options[index].value;

if (value == 'Series'){
	document.getElementById('EpisodesNumber').disabled = false;
	document.getElementById('MediaDuration').disabled = true;
	}
}
function SelectOptions(box,xoptions){
	//alert(xoptions +" "+box);
	var regexpc = /\d/;
	var arr = xoptions.split("_")
	var length = document.getElementById(box).length;
		for (k=0; k<length; k++) {
			for(i=0;i<arr.length;i++){
				if(arr[i].match(regexpc)){
					if(document.getElementById(box).options[k].value == arr[i])
					document.getElementById(box).options[k].selected = true;
				}
			}
		}
	}
	
function ValidateForm(form){
	
		if(document.form.MediaName.value==''){
			alert("Media Name can't be empty\nPlease fill Media Name");
			setTimeout("document.form.MediaName.focus()",0);
			return false;
		}
		/*
		if(document.form.MediaDuration.value==''){
			alert("Media Duration can't be empty\nPlease fill Media Duration");
			setTimeout("document.form.MediaDuration.focus()",0);
			return false;
		}else if(isNaN(document.form.MediaDuration.value)){
			alert("Media Duration MUST be an Intger");
			document.form.MediaDuration.value = '';
			setTimeout("document.form.MediaDuration.focus()",0);
			return false;
			}
		else if(document.form.MediaDuration.value<1){
			alert("Media Duration MUST be greater than 0");
			document.form.MediaDuration.value = '';
			setTimeout("document.form.MediaDuration.focus()",0);
			return false;
			}
		//Tape Number
		if(document.form.MediaTapeNumber.value==''){
			alert("Media Tape Number can't be empty\nPlease fill Tape Number");
			setTimeout("document.form.MediaTapeNumber.focus()",0);
			return false;
		}else if(isNaN(document.form.MediaTapeNumber.value)){
			alert("Media Tape Number MUST be an Intger");
			document.form.MediaTapeNumber.value = '';
			setTimeout("document.form.MediaTapeNumber.focus()",0);
			return false;
			}
		else if(document.form.MediaTapeNumber.value<1){
			alert("Media Tape Number MUST be greater than 0");
			document.form.MediaTapeNumber.value = '';
			setTimeout("document.form.MediaTapeNumber.focus()",0);
			return false;
			}
		//Media Purchase Date
		if(document.form.MediaPurchaseDate.value==''){
			alert("Media Purchase Date can't be empty\nPlease fill Purchase Date");
			displayCalendar(document.forms[1].MediaPurchaseDate,'yyyy-mm-dd',document.forms[1].MediaPurchaseDateButton)
			return false;
		}
		//Media Production Year
		var regexp = /\d\d\d\d/;
			var val = document.form.MediaProductionYear.value;
		if(val==''){
			alert("Media Production Year can't be empty\nPlease fill Production Year");
			setTimeout("document.form.MediaProductionYear.focus()",0);
			return false;
		}else if(isNaN(val)){
			alert("Media Production Year MUST be an Intger");
			document.form.MediaProductionYear.value = '';
			setTimeout("document.form.MediaProductionYear.focus()",0);
			return false;
			}
		   else if(val<1900 || !(val.test(regexp))){
			alert("Media Production Year MUST be greater than 1900");
			//document.form.MediaProductionYear.value = '';
			setTimeout("document.form.MediaProductionYear.focus()",0);
			return false;
			}
			*/
		
	}
function DeleteProduct(id,action){
fla=confirm("Are you sure? Please note that you cannot undo this action!");
if(fla)
doAjaxJob("/Inc/DeleteProduct.php?id="+id+"&action="+action);
}
function DeleteClient(id,action){
fla=confirm("Are you sure? Please note that you cannot undo this action!");
if(fla)
doAjaxJob("/Inc/DeleteClient.php?id="+id+"&action="+action);
}
function DeleteNews(id,action){
fla=confirm("Are you sure? Please note that you cannot undo this action!");
if(fla)
doAjaxJob("/Inc/DeleteNews.php?id="+id+"&action="+action);
}
function DeleteEvent(id,action){
fla=confirm("Are you sure? Please note that you cannot undo this action!");
if(fla)
doAjaxJob("/Inc/DeleteEvent.php?id="+id+"&action="+action);
}
function Deletejob(id,action){
fla=confirm("Are you sure? Please note that you cannot undo this action!");
if(fla)
doAjaxJob("/Inc/Deletejob.php?id="+id+"&action="+action);
}
function DeletejobApp(id,action,resume){
fla=confirm("Are you sure? Please note that you cannot undo this action!");
if(fla)
doAjaxJob("/Inc/DeletejobApp.php?id="+id+"&action="+action+"&resume="+resume);
}

function DeleteGridAd(id){
	fla = confirm("Are you sure? Please note that you cannot undo this action!");
	if(fla)
	doAjaxJob("/Inc/DeleteGridAd.php?id="+id);
}
function chnageCastOrder(id,order){
	
	doAjaxJob("/Inc/chnageCastOrder.php?id="+id+"&Order="+order);
	
	}
function chnageEpisodeOrder(id,order){
	
	doAjaxJob("/Inc/chnageEpisodeOrder.php?id="+id+"&Order="+order);
	
	}
	//DeleteUser 
function DeleteUser(id,action){
fla=confirm("Are you sure? Please note that you cannot undo this action!");
if(fla)
doAjaxJob("/Inc/DeleteUser.php?id="+id+"&action="+action);
}


var xmlhttp;

function doAjaxJob(path)
{
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		  {
		  alert ("Browser does not support HTTP Request");
		  return;
		  }
		var url=path;
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("POST",url,true);
		xmlhttp.send(null);
}

function stateChanged()
{
		if (xmlhttp.readyState==4)
		{
				var result = xmlhttp.responseText;
				//alert(result);
				if(result.match(/here/))
				{
				//	alert(result);
				   window.location.reload();
				}
				else if(result.match(/back/)){
				//	alert(result);
					window.history.back(-2)
					}
					
				
		}
}
		
function GetXmlHttpObject()
		{
		if (window.XMLHttpRequest)
		  {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  return new XMLHttpRequest();
		  }
		if (window.ActiveXObject)
		  {
		  // code for IE6, IE5
		  return new ActiveXObject("Microsoft.XMLHTTP");
		  }
		return null;
}
function checkType(value){
	if(value == 'Series'){
		document.getElementById('EpisodesNumber').disabled = false;
		document.getElementById('MediaDuration').disabled = true;
		document.getElementById('Days').style.display = 'block';
		document.getElementById('Days1').style.display = 'block';
		
		}else{
			document.getElementById('EpisodesNumber').disabled = true;
			document.getElementById('MediaDuration').disabled = false;
			document.getElementById('Days').style.display = 'none';
			document.getElementById('Days1').style.display = 'none';
			}
}

function ReloadGridPage(val){

formatDate(document.getElementById('Time').value);
var Time = document.getElementById('Time').value;
var Fram = document.getElementById('Fram').value;
var Date = document.getElementById('Date').value;
location.href='?GridMediaType='+val+'&Time='+Time+'&Fram='+Fram+'&Date='+Date;
}

function formatDate(Field1){
//alert(Field1);
if(!(Field1.match(/\-/))){
temp1 = Field1.split('/');
	if(temp1.length>1){
	temp1_1 = temp1[2].split(' ');
	document.getElementById("Time").value = temp1_1[0]+"-"+temp1[0]+"-"+temp1[1]+" "+temp1_1[1]+":00";
	}
}
}
 function CheckAll(){
 var Agent = navigator.userAgent;
if(Agent.match(/MSIE/)){

 	var body = document.getElementById("body");
 	var check = body.getElementsByTagName("input");
 	for(var x=0; x < check.length; x++ ){
 	//alert(check[x].getAttribute("name"));
 		var name = check[x].getAttribute("name");
 		var id = check[x].getAttribute("id");
 		if(id.match(/Sat/)){
 			
 			alert(name);
 			document.getElementById("Sat").checked = true;
 		}
 	}
 	}
 
 }
function showHide(row){
	var tr = "row_"+row;
//alert(tr);
	var el = document.getElementById(tr);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
		
	}

}
