// JavaScript Document

// global variables
// This is the URL for streaming
var pkStreamURL = 'http://www.antrimcoc.org/cgi-bin/createram.cgi';
// URL for forcing a file upload
var pkForceUploadURL = 'http://www.antrimcoc.org/phputil/forceupload.php';

// to go to a URL...if not given with http or https it uses 
// pkStreamURL + ?media_file=
function pkGoThere(menu_choice) {
    var base_uri = pkStreamURL + "?media_file=";
    // did we not choose anything?
    if (menu_choice == "notchosen" || menu_choice == '') {
        return;
        }
    else if (menu_choice.indexOf("http") == 0) {
        window.location.href = menu_choice;
        }
    else {
        window.location.href = base_uri + menu_choice;
        }
    }

// this takes a file type (mp3, mp3_large, wma_low, wma, m4b, or rm) and
// returns the full extention (.mp3, _low.wma, .wma, .m4b,
// or .rm repectively)
function pkResourceFileExt(file_type) {
	var file_ext = "";
	switch(file_type) {
		case "wma_low":
		    file_ext = "low.wma";
			break;
		case "mp3_large":
		    file_ext = "large.mp3";
			break;
                case "":
                    file_ext = "";
                    break;
		default:
			file_ext = "." + file_type;
	}
	return(file_ext);
}
	
function pkResourceStream(relative_base_url,base_file_name,file_type) {
	pkGoThere(relative_base_url + base_file_name + pkResourceFileExt(file_type));
}

function pkResourceUrl(relative_base_url,base_file_name,file_type) {
	pkGoThere(pkForceUploadURL + '?file=' + relative_base_url + base_file_name + pkResourceFileExt(file_type));
}

// Function to return a specific day of the week in the future
// myFormat 0 -> milliseconds (now offset by days)
// myFormat 1 -> D Mmm YYYY
// dayWanted -> 3 character version of DOW (e.g. 'Sat')
// myFormat defaults to 1, dayWanted as 'Sat'
function pkGetSpecificDate(myFormat,dayWanted) {
    var shortMonth = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var dayOffset = new Array();
	dayOffset['Sun'] = 0;
	dayOffset['Mon'] = 1;
	dayOffset['Tue'] = 2;
	dayOffset['Wed'] = 3;
	dayOffset['Thu'] = 4;
	dayOffset['Fri'] = 5;
	dayOffset['Sat'] = 6;
    var objDate = new Date();
    if (myFormat == null) {
	    myFormat = 1;
	    }
	if (dayWanted == null) {
	    dayWanted = "Sat";
	    }
	var myIntDay = 0;
	
	var intDOW = objDate.getDay();
	var dayOffset = dayOffset[dayWanted] - intDOW  < 0 ? dayOffset[dayWanted] + 7 : dayOffset[dayWanted];
	
	objDate.setDate(objDate.getDate()+(dayOffset-intDOW));
	var intYear = objDate.getFullYear();
	var intMonth = objDate.getMonth();
	var intDay = objDate.getDate();
	switch(myFormat) {
	    // Milliseconds since epoc
		case 0:
			return(objDate.getTime());
			break;
	    // D Mmm YY
		case 1:
			return(intDay + " " + shortMonth[intMonth] + " " + intYear);
			break;
	    // D Mmm YY
		default:
		    return(intDay + " " + shortMonth[intMonth] + " " + intYear);
	     }
    }


