function ShowHideTvOrRadio() {
    show_ogg_vorbis = false;
    if ( document.forms[0].stream.value == "tv" ) {
				divform = $(".ch_quadfau form");
				$("tr, hr, div, h3",divform).show();
				if (recday){
					$("#past_days").hide();
				}
				else {
					$("#future_days").hide();
				}
		  	warn = document.getElementById("AppleTvWarning");
				warn.setAttribute("class", "right2");
				tv_type = document.getElementById("tv_type");
//				if (tv_type.value == "3") {
//					warn.innerHTML = "Il formato H.264 - Apple Tv ora può essere visualizzato direttamente online grazie al nuovo plugin di Adobe Flash.";
//				}
//				else{
//					warn.innerHTML = "";
//				}
        tv_form   = document.getElementById("tv_form");
        tv_form.style.display = "inline";
        radio_form   = document.getElementById("radio_form");
        radio_form.style.display = "none";
        tv_type.style.display = "inline";
        radio_type   = document.getElementById("radio_type");
        radio_type.style.display = "none";
        for (i=0;i < document.forms[0].elements.length;i++) {  
            if ( document.forms[0].elements[i].name=="hq_channels[]" && document.forms[0].elements[i].value==document.forms[0].channel_tv.value ) {
                show_ogg_vorbis = true;
            }
        }  
    } else {
			  warn = document.getElementById("AppleTvWarning");
				warn.innerHTML = "<br />La registrazione delle radio non è più disponibile in VCast: un servizio analogo ora viene fornito da <a class='lefter_error under' target='_blank' href='http://drivecast.eu'>Drivecast</a><br /><br />";
				warn.setAttribute("class", "lefter_error");
//        radio_type= document.getElementById("radio_type");
//        radio_type.style.display = "inline";
        tv_form   = document.getElementById("tv_form");
        tv_form.style.display = "none";
//        radio_form   = document.getElementById("radio_form");
//        radio_form.style.display = "inline";
        tv_type   = document.getElementById("tv_type");
        tv_type.style.display = "none";
//        for (i=0;i < document.forms[0].elements.length;i++) {  
//            if ( document.forms[0].elements[i].name=="hq_channels[]" && document.forms[0].elements[i].value==document.forms[0].channel_radio.value ) {
//                show_ogg_vorbis = true;
//            }
//        }
				recday = $("#future_days").is(":visible");
				divform = $(".ch_quadfau form");
				$("tr, hr, div, h3",divform).hide();
				$("#AppleTvWarning,#AppleTvWarning a").show();
				$("tr:first",divform).show();
				
				
    } 
    if ( show_ogg_vorbis ) {
        ShowOggVorbValue();
    } else {
        HideOggVorbValue();
    }      
}

function HideOggVorbValue() {
    ogg_obris_hide = document.getElementById("hide_oggvorb_in_case");   
    str_to_replace = ogg_obris_hide.innerHTML;
    //alert(str_to_replace);
    str_to_replace = str_to_replace.replace(/<option value=\"{0,1}7\"{0,1}>OggVorbis\s{0,1}<\/option>/ig,'');
    str_to_replace = str_to_replace.replace(/<option value=\"{0,1}7\"{0,1} selected=\"{0,1}selected\"{0,1}>OggVorbis\s{0,1}<\/option>/ig,'');
    str_to_replace = str_to_replace.replace(/<option value=\"{0,1}7\"{0,1} selected>OggVorbis\s{0,1}<\/option>/ig,'');
    //alert(str_to_replace);
    ogg_obris_hide.innerHTML = str_to_replace;
}

function ShowOggVorbValue() {
//    ogg_obris_hide = document.getElementById("hide_oggvorb_in_case");   
//    str_to_replace = ogg_obris_hide.innerHTML;
//    if ( !str_to_replace.match(/OggVorbis/i) ) {
//        str_to_replace = str_to_replace.replace(/\MP3\s{0,1}<\/option\>/ig,'MP3</option><option value=7>OggVorbis</option>');
//    }
//    ogg_obris_hide.innerHTML = str_to_replace;
}

function HighlightFoundedString() {
    //alert('Inside Highlight');
    arr_divs_to_be_replaced = Array("body");
    for (i=0;i<arr_divs_to_be_replaced.length;i++) {
        div_on_work = arr_divs_to_be_replaced[i];
        item_title = document.getElementById(div_on_work);
        old_str = item_title.innerHTML;
        new_str = replace(old_str,"&lt;","<");
        new_str = replace(new_str,"&gt;",">");
        item_title.innerHTML = new_str;
    }        
}
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}
function ExecuteDelete (url,confirm_text) {
    confirm_text = confirm_text.replace(/_/g," ");
	var agree=confirm(confirm_text);
    if (!agree) { return; }
    location.replace(url);
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
    if ( Get_Cookie( name ) ) {
	    document.cookie = name + "=" +( ( path ) ? ";path=" + path : "") +( ( domain ) ? ";domain=" + domain : "" ) +";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}

function goEdit(usr, path, title){
	path = path.replace(/http:\/\/fb(.)\.vcast\.it/i,"/usr1/Fbucket");
	var server = RegExp.$1;
	var usr64 = Base64.encode(usr);
	var path64 = Base64.encode(path);
	var title64 = Base64.encode(title);

	window.location.href="http://fb"+server+".vcast.it/JBEdit/index.php?usr="+usr64+"&vpth="+path64+"&ttl="+title64;
}

function ExecuteDelete (url,confirm_text) {
        confirm_text = confirm_text.replace(/_/g," ");
	var agree=confirm(confirm_text);
        if (!agree) { return; }
	location.href=url;
}
function OpenScheduledUrl(url,what) {
        if ( what=='radio' ) {
	    url += '?url='+document.faucet_pvr.channel_radio.value;
        } else {
	    url += '?url='+document.faucet_pvr.channel_tv.value;
        }
	window.open(url,'');
}
function DisplayWarning(warning) {
    var AppleTvWarning;
    if ( document.forms[0].compression.value =="3" ) {
        AppleTvWarning = document.getElementById("AppleTvWarning");
        AppleTvWarning.innerHTML = warning;
        document.forms[0].must_unset.value = "yes";
    }  else if ( document.forms[0].must_unset.value=="yes" || document.forms[0].compression.value != "3" ) {
        AppleTvWarning = document.getElementById("AppleTvWarning");
        AppleTvWarning.innerHTML = "";
    }
}

function DisplayWarningChannel(warning) {
    if ( document.forms[0].channel_tv.value =="La7" || document.forms[0].channel_tv.value =="Mtv") {
        AppleTvWarning = document.getElementById("La7Warning");
        AppleTvWarning.innerHTML = warning;
    }
		else{
			AppleTvWarning.innerHTML = "";
		}
}

function DisplayRepo(freq) {
	  $("#ru, #du, #fu, #rp, #dp, #fp, #Radd").hide();
    if ( document.forms[0].repository.value == "keep_1" || document.forms[0].repository.value == "keep_2" || document.forms[0].repository.value == "keep_3" )
			 $("#Rrem, #Radd, #Ruser, #Rpass").hide();
    else
			 $("#Rrem, #Ruser, #Rpass").show();	 
		if (document.forms[0].repository.value !="4")
			 $("#ru, #rp").show();
		else
       $("#Radd, #ru, #rp").show();
		$("#ru, #rp").val("");
		if (freq == "periodic") {
			$("#FModWarning").html("La variazione di deposito registrazione avverrà dalla prossima acquisizione.");
	  }	
}

function HideRepo() {
			$("#Rrem").hide();
      $("#Radd").hide();
			$("#Ruser").hide();
			$("#Rpass").hide();
}

function HandleForm(freq){
	if (freq == "done") {
  	$("#mod_form :input").attr("disabled", "disabled");
		$("#be").removeAttr("disabled");
		$("#bb").removeAttr("disabled");
		$("#FModWarning").html("Non e' possibile modificare una registrazione in corso o gia' terminata.");
  } 
}


function CheckAction(){
	if (document.forms[0].repository.value !="1") document.forms[0].action = "disclaimer.php";
}

function EnablePastInCase() {
		var past_days;
		var future_days;
		past_found	= false;
		past_days 	= document.getElementById("past_days");
		future_days = document.getElementById("future_days");
		for (i=0;i < document.forms[0].elements.length;i++) {	
				if ( document.forms[0].elements[i].name == 'arr_node_past_allowed[]' || document.forms[0].full_past_allowed.value == "1" ) {
						if ( document.forms[0].elements[i].value == document.forms[0].channel_tv.value ) {
								past_found = true;
								past_days.style.display 	= "inline";
								future_days.style.display = "none";
								document.forms[0].day_used.value="past";
								break;
						}
				}
		}		
		if ( !past_found ) {
				past_days.style.display 	= "none";
				future_days.style.display = "inline";
				document.forms[0].day_used.value="future"
		}
		show_ogg_vorbis = false;
		for (i=0;i < document.forms[0].elements.length;i++) {	
				if ( document.forms[0].elements[i].name=="hq_channels[]" && document.forms[0].elements[i].value==document.forms[0].channel_tv.value ) {
						show_ogg_vorbis = true;
				}
		}		
		if ( show_ogg_vorbis ) {
				ShowOggVorbValue();
		} else {
				HideOggVorbValue();
		}
}
function EnablePastInCaseRadio() {
		var past_days;
		var future_days;
		past_found	= false;
		past_days 	= document.getElementById("past_days");
		future_days = document.getElementById("future_days");
		for (i=0;i < document.forms[0].elements.length;i++) {	
				if ( document.forms[0].elements[i].name == 'arr_node_past_allowed[]' || document.forms[0].full_past_allowed.value == "1" ) {
						if ( document.forms[0].elements[i].value == document.forms[0].channel_radio.value ) {
								past_found = true;
								past_days.style.display 	= "inline";
								future_days.style.display = "none";
								document.forms[0].day_used.value="past";
								break;
						}
				}
		}		
		if ( !past_found ) {
				past_days.style.display 	= "none";
				future_days.style.display = "inline";
				document.forms[0].day_used.value="future"
		}
		show_ogg_vorbis = false;
		for (i=0;i < document.forms[0].elements.length;i++) {	
				if ( document.forms[0].elements[i].name=="hq_channels[]" && document.forms[0].elements[i].value==document.forms[0].channel_radio.value ) {
						show_ogg_vorbis = true;
				}
		}
		if ( show_ogg_vorbis ) {
				ShowOggVorbValue();

		} else {
				HideOggVorbValue();
		}
		
}

function EnableDisableOggVorbisTv() {
    show_ogg_vorbis = false;
    for (i=0;i < document.forms[0].elements.length;i++) {  
        if ( document.forms[0].elements[i].name=="hq_channels[]" && document.forms[0].elements[i].value==document.forms[0].channel_tv.value ) {
            show_ogg_vorbis = true;
        }
    }
    if ( show_ogg_vorbis ) {
        ShowOggVorbValue();
    } else {
        HideOggVorbValue();
    }
}

function EnableDisableOggVorbisRadio() {
    show_ogg_vorbis = false;
    for (i=0;i < document.forms[0].elements.length;i++) {  
        if ( document.forms[0].elements[i].name=="hq_channels[]" && document.forms[0].elements[i].value==document.forms[0].channel_radio.value ) {
            show_ogg_vorbis = true;
        }
    }
    if ( show_ogg_vorbis ) {
        ShowOggVorbValue();
    } else {
        HideOggVorbValue();
    }
}

function ValidateFrom() {
    if ( document.forms[0].channel_tv.value == "---" ) {
        alert("Choose a channel");
        return false;
    }
    hours_start = document.forms[0].hours_start.value;
    minutes_start = document.forms[0].minutes_start.value;
    hours_stop = document.forms[0].hours_stop.value;
    minutes_stop = document.forms[0].minutes_stop.value;
    hour_now = document.forms[0].hour_now.value;
    minute_now = document.forms[0].minute_now.value;
    seconds_start = 3600*hours_start+60*minutes_start;
    seconds_stop  = 3600*hours_stop+60*minutes_stop;
    if ( seconds_stop < seconds_start ) {
        seconds_stop += 3600*24;
    }

    seconds_now = 3600*hour_now+60*minute_now;
    if ( seconds_start < seconds_now && (document.forms[0].day_f.selectedIndex == 0 && document.forms[0].full_past_allowed.value == "0") ) {
        alert("La registrazione non è definibile per il passato");
        //alert(document.forms[0].day_p.value+" "+document.forms[0].day_f.value);
        return false;
    }
    sec_recording_time = seconds_stop - seconds_start;
    sec_allowed_recording_time = 3*3600+30*60;
    if ( sec_recording_time > sec_allowed_recording_time ) {
        alert("Maximum recording time allowed  03:30");
        return false;
    }

    user = "";  pass = ""; 
    if (document.forms[0].reeplay_user.value != "" )  {
        user = document.forms[0].reeplay_user.value;
    } 
    if (document.forms[0].dropbox_user.value != "" )  {
        user = document.forms[0].dropbox_user.value;
    } 
    if (document.forms[0].ftp_user.value != "" )  {
        user = document.forms[0].ftp_user.value;
    } 
    if (document.forms[0].reeplay_password.value != "" )  {
        pass = document.forms[0].reeplay_password.value;
    } 
    if (document.forms[0].dropbox_password.value != "" )  {
        pass = document.forms[0].dropbox_password.value;
    } 
    if (document.forms[0].ftp_password.value != "" )  {
        pass = document.forms[0].ftp_password.value;
    } 
    //debug_str = 'user='+user+'&pass='+pass+'&repo_addr='+document.forms[0].ftp_addr.value+'&repository='+document.forms[0].repository.value;
    //alert(debug_str);
    $.ajax({
        type: 'get',
        url: 'disclaimer_status.php',
        data: 'user='+user+'&pass='+pass+'&repo_addr='+document.forms[0].ftp_addr.value+'&repository='+document.forms[0].repository.value,
        error: function(){
        //alert('some error ocurred in ajax call');
        },
        success: function(data) {
            if ( data == "disclaimer_false" ) {
                document.forms[0].submit();
                return true;
            } else {
            	if ( document.forms[0].repository.value !="keep_1" && document.forms[0].repository.value !="keep_2" && document.forms[0].repository.value !="keep_3" ) {
	               document.forms[0].action = "disclaimer.php";
	           }
               document.forms[0].submit();
	           return true;
            }
        }
    }
    );
    return false;
}

