﻿// JScript File
function RadioShow(){
}

function getform(objectid){                    
       new Ajax.Request("/library/ajaxservices/radioshows/radioshow.aspx", {method:'post',asynchronous:false,postBody:'&action=getform', onSuccess:function(t){         
           
            document.getElementById("objRadioShow").innerHTML = t.responseText;
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}
function getlist(objectid){                    
       new Ajax.Request("/library/ajaxservices/radioshows/radioshow.aspx", {method:'post',asynchronous:false,postBody:'&action=getlist', onSuccess:function(t){                    
            document.getElementById("objRadioShow").innerHTML = t.responseText;
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}
function getweekdayshow(objectid,weekdays){                    
       new Ajax.Request("/library/ajaxservices/radioshows/radioshow.aspx", {method:'post',asynchronous:false,postBody:'&action=getweekdayshow&weekdays=' + escape(weekdays), onSuccess:function(t){                    
            document.getElementById("objRadioShow").innerHTML = t.responseText;
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function geteditform(objectid,showid){                    
       new Ajax.Request("/library/ajaxservices/radioshows/radioshow.aspx", {method:'post',asynchronous:false,postBody:'&action=geteditform&showid=' + escape(showid), onSuccess:function(t){                    
            document.getElementById("objRadioShow").innerHTML = t.responseText;
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function saveform(objectid,showid,showname,description,websiteurl,weekdays,starttime,endtime,timezone,highbandwidth,lowbandwidth,uscallin,chaturl,startdate,isrecurring){                    
       new Ajax.Request("/library/ajaxservices/radioshows/radioshow.aspx", {method:'post',asynchronous:false,postBody:'&action=saveform&showid=' + escape(showid) + '&showname=' + escape(showname) +'&description=' + escape(description) + '&websiteurl=' + escape(websiteurl) + '&weekdays=' + escape(weekdays) + '&starttime=' + escape(starttime) + '&endtime=' + escape(endtime) + '&timezone=' + escape(timezone) + '&highbandwidth=' + escape(highbandwidth) + '&lowbandwidth=' + escape(lowbandwidth) + '&uscallin=' + escape(uscallin) + '&chaturl=' + escape(chaturl) + '&startdate=' + escape(startdate) + '&isrecurring=' + escape(isrecurring), onSuccess:function(t){                    
            document.getElementById("objRadioShow").innerHTML = t.responseText;
        }, onFailure:function(t){
        alert("There is a data-entry error on the form. Something is not in a valid format.");
    }}); 
}

function deleteShow(objectid,showid){                    
       new Ajax.Request("/library/ajaxservices/radioshows/radioshow.aspx", {method:'post',asynchronous:false,postBody:'&action=delete&showid=' + escape(showid), onSuccess:function(t){                    
            document.getElementById("objRadioShow").innerHTML = t.responseText;
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function getUserShows(){
       new Ajax.Request("/library/ajaxservices/radioshows/radioshow.aspx", {method:'post',asynchronous:false,postBody:'&action=getusershows', onSuccess:function(t){                    
        document.getElementById("objRadioShow").innerHTML = t.responseText;
    }, onFailure:function(t){
    alert(t.responseText);
    }}); 
}
function GetWeekdayShow(weekday){
    getweekdayshow("objRadioShow",weekday)
}

function Cancel(){
    getlist("objRadioShow");
}

function AddShow(){
    geteditform("objRadioShow","");
}

function ShowEditWindow(id){
       geteditform("objRadioShow",id);
}
function Delete(){
    var showid = document.getElementById("frm_showid").value;
    deleteShow("objRadioShow",showid);  
}

function Save(){    
    var showid = document.getElementById("frm_showid").value; 
    var startdate = document.getElementById("frm_startdate").value;
    var isrecurring = false;
    if(document.getElementById("frm_isrecurring").checked){
      isrecurring = true;
    }
    
    
    var showname =document.getElementById("frm_showname").value; 
    var description =document.getElementById("frm_description").value; 
    var websiteurl =document.getElementById("frm_websiteurl").value;
    var weekdays = "";    
    if(document.getElementById("frm_monday").checked){
        weekdays += "monday,";
    };
    if(document.getElementById("frm_tuesday").checked){
        weekdays += "tuesday,";
    };if(document.getElementById("frm_wednesday").checked){
        weekdays += "wednesday,";
    };if(document.getElementById("frm_thursday").checked){
        weekdays += "thursday,";
    };if(document.getElementById("frm_friday").checked){
        weekdays += "friday,";
    };if(document.getElementById("frm_saturday").checked){
        weekdays += "saturday,";
    };if(document.getElementById("frm_sunday").checked){
        weekdays += "sunday,";
    }; 
    var starttime=document.getElementById("frm_starttime").value;
     var endtime=document.getElementById("frm_endtime").value;
    
    var timezone=document.getElementById("frm_timezone").value;
    var highbandwidth=document.getElementById("frm_highbandwidth").value;
    var lowbandwidth=document.getElementById("frm_lowbandwidth").value;
    var uscallin=document.getElementById("frm_uscallin").value;
    var chaturl=document.getElementById("frm_chaturl").value;
    if(isNaN(Date.parse("01/01/2000 " + starttime))){
        alert("please enter a valid start time.");
        document.getElementById("frm_starttime").focus();
        return;
    };    
    if(trim(starttime).length <=0){
        alert("please enter a valid start time.");
        document.getElementById("frm_starttime").focus();
        return;
    };    
    if(isNaN(Date.parse("01/01/2000 " + endtime))){
        alert("please enter a valid endtime.");
        document.getElementById("frm_endtime").focus();
        return;
    };
    if(trim(endtime).length <=0){
        alert("please enter a valid end time.");
        document.getElementById("frm_endtime").focus();
        return;
    };    
    saveform("objRadioShow",showid,showname,description,websiteurl,weekdays,starttime,endtime,timezone,highbandwidth,lowbandwidth,uscallin,chaturl,startdate,isrecurring);   
}
RadioShow.prototype.deleteshow = deleteShow;
RadioShow.prototype.getform = getform;
RadioShow.prototype.saveform = saveform;
RadioShow.prototype.geteditform = geteditform;
RadioShow.prototype.getlist = getlist;
RadioShow.prototype.getweekdayshow = getweekdayshow;

function ltrim(s){
return s.replace( /^\s*/, "");
}
//rtrim
function rtrim(s){
return s.replace( /\s*$/, "");
}  
//trim
function trim(s){
return rtrim(ltrim(s));
}