var LDIN = "<img src=\"images/aud_images/loadin.gif\" align=\"top\" alt=\"loading\"/>";
var preCon,mPreCon,curTab,preSpo,premSpo,curSTAB;
var upStat = 'view';
var supStat = 'view';

function elm(str) {
	return document.getElementById(str);
}

function go() {
	selTab('imgs');
}
function selTab(vw,qs) {
	if(!qs) var qs = '';
	var felem = elm(vw+'TAB');
	if(vw == 'sports' || vw == 'simgs') {
		if(curSTAB) {
			curSTAB.style.backgroundImage = 'url(images/nofile.gif)';
		}
		view(vw,'sPubs',qs);
		curSTAB = felem;
	} else {
		if(curTab) {
			curTab.style.backgroundImage = 'url(images/nofile.gif)';
		}
		view(vw,'pubs',qs);
		curTab = felem;
	}
	felem.style.backgroundImage = "url(images/aud_images/"+vw+"_bg.gif)";
}
function view(vw,e,qs) {
	if(!qs) var qs = '';
	var pubs = elm(e);
	function fetch_audios(cnt) {
		pubs.innerHTML = cnt;
		document.location = '#'+vw;
	}
	function error_fetch(cnt) {
		pubs.innerHTML = 'The following error occurred while loading publications: '+cnt;
	}
	pubs.innerHTML = "<div align=\"center\"><p>"+LDIN+"<strong> 1 SEC...</strong></p></div>";
	aGet('CMS/crudAuds.php', 'act=read&auds='+vw+'&'+qs, fetch_audios,error_fetch);
}
function hovOut(e) {
	var el = elm(e);
	if(el != curTab && el != curSTAB) {
		el.style.backgroundImage = 'url(images/clear.gif)';
	}
}
function hovOvr(e,bg) {
	var el = elm(e);
	el.style.backgroundImage = "url("+bg+")";
}
function fFocs(fld) {
	fld.style.backgroundColor = "#ffe37e";
	fld.style.color = "#9A5800";
	fld.select();
}
function fBlur(fld) {
	fld.style.backgroundColor = "";
	fld.style.color = "";
}
function rand(s) {
	if(!s) var s = 999999;
	return Math.floor(Math.random()*s)
}
function abort(rid,s) {
	var stat = elm('stat'+rid);
	stat.innerHTML = '';
	alert(s);
}
function error(s) {
	alert(s);
	refresh();
}
function refresh(s) {
	if(!s) var s = document.location.hash.substr(1);
	//url = (url.length > 0 && url != 'sports') ? url : s ;
	var queryS = s == 'imgs' ? 'news&coms' : s == 'simgs' ? 'sports' : '' ;
	selTab(s,queryS);
}
function addAud(vw,aud) {
	var newaud = vw == 'sports' ? elm('sPubs') : elm('pubs') ;
	var r = rand();
	preCon = newaud.innerHTML;
	newaud.innerHTML = '<form name="add_form'+r+'" id="add_form'+r+'" enctype="multipart/form-data" method="POST" action="CMS/crudAuds.php?act=create&auds='+vw+'" target="add_pub'+r+'"><table cellpadding="0" cellspacing="10" ><tr><td>Input the publication name and select the audio file you wish to upload.</td></tr><tr><td><table cellpadding="0" cellspacing="0" class="pBar"><tr> <td class="l_moon">&nbsp;</td> <td class="t_cont" style="width:40px; padding-left:4px;">Name:</td> <td class="t_cont" style="width:auto;"><input type="text" name="pubName" id="pubName'+r+'" onblur="fBlur(this)" onfocus="fFocs(this)" value="'+aud+'" /></td> <td class="r_moon">&nbsp;</td> </tr></table></td></tr><tr><td> 	<table cellpadding="0" cellspacing="0" class="pBar"><tr> <td class="l_moon">&nbsp;</td> <td class="t_cont" style="width:40px; padding-left:4px;">File:</td> <td style="overflow:hidden; background-color:#9A5800; width:152px;"><input type="file" name="pubFile" id="pubFile'+r+'" onblur="fBlur(this)" onfocus="fFocs(this)" size="35" style="border:none; height:auto;" /></td> <td class="r_moon">&nbsp;</td> </tr></table></td></tr><tr><td align="right"><table cellpadding="0" cellspacing="0" style="margin-right:10px;"> <tr> <td><iframe frameborder="0" height="0px" width="0px" name="add_pub'+r+'" id="add_pub'+r+'"></iframe><div id="stat'+r+'"></div></td><td> <div class="l_but" onclick="subAud(\''+vw+'\','+r+');">SUBMIT</div> </td> <td> <div class="r_but" onclick="canAd(\''+vw+'\','+r+')">CANCEL</div> </td> </tr> </table></td></tr></table></form>';
}
function subAud(v,id) {
	var frm = elm('add_form'+id);
    var stat = elm('stat'+id);
    if (frm.pubName.value != '') {
        if (frm.pubName.value.length < 32) {
			if (frm.pubFile.value != '') {
                stat.innerHTML = LDIN;
				frm.submit();
	        } else {
	            alert('You have to select the Audio File to upload!');
	        }
        } else {
            alert('The Name has to be 32 characters or less in length, including spaces!');
        }
    } else {
        alert('You need to give a name.');
    }
}
function canAd(v,id) {
	var newaud = v == 'sports' ? elm('sPubs') : elm('pubs') ;
	newaud.innerHTML = v == 'sports' ? premSpo : preCon ;
}
function delAud(id, vw) {
	var pname = elm(vw+'_pubName_'+id).innerHTML;
	var audbar = elm(vw+'_audBar_'+id);
	var preBar = audbar.innerHTML;
	if(confirm('Are you sure you want to delete '+pname+'?')) {
		audbar.innerHTML = '<div class="audBar" id="newAud"> <table cellpadding="0" cellspacing="0"> <tr> <td class="l_o_moon"></td> <td class="c_cont">'+LDIN+'</td> <td class="r_o_moon"></td> </tr> </table> </div>';
		
		function compl(cnt) {
			switch(cnt) {
				case 'saved':
					alert('The entry was deleted. However, could not delete the audio file. Use ftp to delete it manually.');
					refresh(vw);
				break;
				case 'saved_deleted':
					refresh(vw);
				break;
				case 'not_found':
					erro('The selected publication for deletion could not be found. Refresh and ');
				break;
				case 'not_removed':
					erro('There was a problem deleting this publication.');
				break;
				case 'unsaved':
					erro('There was a problem saving the changes.');
				break;
			}
		}
		function erro(cnt) {
			audbar.innerHTML = preBar;
			alert('Try again. Error: '+cnt);
		}
		aGet('CMS/crudAuds.php', 'act=delete&auds='+vw+'&id='+id, compl, erro);
	}
}
function ediAud(id, vw, fl) {
	var r = rand();
	var mov = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="120" height="20" codebase="http://www.apple.com/qtactivex/qtplugin.cab"> <param name="src" value="'+fl+'"> <param name="href" value="'+fl+'"> <param name="autoplay" value="false"> <param name="target" value="myself"> <param name="loop" value="false"> <param name="controller" value="true"> <param name="type" value="video/quicktime" width="120" height="15"> <param name="pluginspage" value="http://www.apple.com/quicktime/download/"> <embed src="'+fl+'" href="'+fl+'" width="120" height="15" type="video/quicktime" autoplay="false" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/download/" target="myself"></embed> </object>';
	
	var upaud = vw == 'sports' ? elm('sPubs') : elm('pubs') ;
	var oName = elm(vw+'_pubName_'+id).innerHTML;
	
	if(vw == 'sports') {
		preSpo = upaud.innerHTML;
	} else {
		preCon = upaud.innerHTML;
	}
	upaud.innerHTML = '<form name="up_form'+r+'" id="up_form'+r+'" enctype="multipart/form-data" method="POST" action="CMS/crudAuds.php?act=update&auds='+vw+'&id='+id+'&rid='+r+'" target="up_pub'+r+'"><table cellpadding="0" cellspacing="10" ><tr><td>To replace the audio file, click the arrows icon.</td></tr><tr><td><table cellpadding="0" cellspacing="0" class="pBar"><tr> <td class="l_moon">&nbsp;</td> <td class="t_cont" style="width:40px; padding-left:4px;">Name:</td> <td class="t_cont" style="width:auto;"><input type="text" name="pubName" id="pubName'+r+'" onblur="fBlur(this)" onfocus="fFocs(this)" value="'+oName+'" /></td> <td class="r_moon">&nbsp;</td> </tr></table></td></tr><tr><td> 	<table cellpadding="0" cellspacing="0" class="pBar"><tr> <td class="l_moon">&nbsp;</td> <td class="t_cont" style="width:40px; padding-left:4px;">File:</td> <td class="t_cont" style="overflow:hidden; width:152px;" id="pubMov'+r+'"><table cellpadding="0" cellspacing="0"><tr><td style="padding-top: 3px;">'+mov+'</td><td style="padding-left:5px;"><div class="con_but" style="height:14px; width:17px !important; float:right; margin:1px 3px 0px 0px;" onclick="togUpStat(\''+vw+'\','+r+')"><img src="images/aud_images/replace_horz.gif" alt="replace" align="middle" title="replace" /></div></td></tr></table></td> <td class="r_moon">&nbsp;</td> </tr></table></td></tr><tr><td align="right"><table cellpadding="0" cellspacing="0" style="margin-right:10px;"> <tr> <td><iframe frameborder="0" height="0px" width="0px" name="up_pub'+r+'" id="up_pub'+r+'"></iframe><div id="stat'+r+'"></div></td><td> <div class="l_but" onclick="updAud(\''+vw+'\','+r+');">UPDATE</div> </td> <td> <div class="r_but" onclick="canUpd(\''+vw+'\','+r+')">CANCEL</div> </td> </tr> </table></td></tr></table></form>';
}
function canUpd(vw,r) {
	var upaud = vw == 'sports' ? elm('sPubs') : elm('pubs') ;
	upaud.innerHTML = (vw == 'sports') ? preSpo : preCon ;
}
function updAud(vw,r) {
	var frm = elm('up_form'+r);
    var stat = elm('stat'+r);
    if (frm.pubName.value != '') {
        if (frm.pubName.value.length < 32) {
			if(upStat == 'view') {
				stat.innerHTML = LDIN;
				frm.submit();
			} else if (frm.pubFile.value != '') {
                stat.innerHTML = LDIN+'&nbsp;';
				frm.submit();
	        } else {
	            alert('You have to select the Audio File you wish to replace the current one with, other wise, click the X to cancel upload!');
	        }
        } else {
            alert('The Name has to be 32 characters or less in length, including spaces!');
        }
    } else {
        alert('You need to give a name.');
    }
}
function togUpStat(vw,id) {
	var pubMov;
	if(vw == 'sports') {
		pubMov = elm('pubMov'+id);
		switch(supStat) {
			case 'view':
				supStat = pubMov.innerHTML;
				pubMov.innerHTML = '<table cellpadding="0" cellspacing="0"> <tr><td style="overflow:hidden;"><input type="file" name="pubFile" id="pubFile" onblur="fBlur(this)" onfocus="fFocs(this)" size="35" style="border:none;" /></td><td><div class="con_but" onclick="togUpStat(\''+vw+'\',\''+id+'\')"> <img src="images/aud_images/delete.gif" alt="delete" title="cancel" /> </div></td></tr></table>';
			break;
			default:
				pubMov.innerHTML = supStat;
				supStat = 'view';
			break;
		}
	} else {
		pubMov = elm('pubMov'+id);
		switch(upStat) {
			case 'view':
				upStat = pubMov.innerHTML;
				pubMov.innerHTML = '<table cellpadding="0" cellspacing="0"> <tr><td style="overflow:hidden;"><input type="file" name="pubFile" id="pubFile" onblur="fBlur(this)" onfocus="fFocs(this)" size="35" style="border:none;" /></td><td><div class="con_but" onclick="togUpStat(\''+vw+'\',\''+id+'\')"> <img src="images/aud_images/delete.gif" alt="delete" title="cancel" /> </div></td></tr></table>';
			break;
			default:
				pubMov.innerHTML = upStat;
				upStat = 'view';
			break;
		}
	}
}
function repIMG(vew) {
	if(confirm('Replacing this image will overwrite the current one. Are you sure?')) {
		var fi = elm(vew+'_up');
		fi.style.display = 'block';
	}
}
function subRep(vew) {
	var frm = elm(vew+'_form');
	var stat = elm(vew+'Stati');
	frm.submit();
	stat.innerHTML = LDIN;
}
function delIMG(vew) {
	var frm = elm('rep_form');
	var stat = elm(vew+'Stati');
	var pubs = vew == 'sports' ? elm('sPubs') : elm('pubs') ;
	var prePub = pubs.innerHTML;
	var host = vew == 'news' ? "News Host's picture" : vew == 'coms' ? "Commentary Host's picture" : "Sports Host's picture" ;
	
	if(confirm('Are you sure you want to delete the '+host+'?')) {
		pubs.innerHTML = "<div align=\"center\"><p>"+LDIN+"<strong>1 SEC...</strong></p></div>";
		
		function compl(cnt) {
			switch(cnt) {
				case 'saved_deleted':
					refresh(vew);
				break;
				case 'not_found':
					erro('The selected image for deletion could not be found. Refresh and Try again. ');
				break;
				case 'unsaved':
					erro('There was a problem saving the changes.');
				break;
			}
		}
		function erro(cnt) {
			pubs.innerHTML = prePub;
			alert('Try again. Error: '+cnt);
		}
		aGet('CMS/crudAuds.php', 'act=delete&auds='+vew+'&id=imgs', compl, erro);
	}
}
function transform() {
	var pc = elm('pubsCont');
	mPreCon = pc.innerHTML;
	pc.innerHTML = '<div class="minitab"> <div class="minitab_left" style="background-image:url(elements/tab_left.png); background-repeat:no-repeat"></div> <div class="minitab_middle" style="background-image:url(elements/tab_middle.png); background-repeat:repeat-x; padding-top:3px; height:24px;"> <table cellpadding="0" cellspacing="0" id="audTabs"> <tr> <td class="audTab" id="newsTAB" onclick="selTab(\'news\')" onmouseover="hovOvr(\'newsTAB\',\'images/aud_images/news_bg.gif\')" onmouseout="hovOut(\'newsTAB\')">NEWS</td> <td class="audTab" id="comsTAB" onclick="selTab(\'coms\')" onmouseover="hovOvr(\'comsTAB\',\'images/aud_images/coms_bg.gif\')" onmouseout="hovOut(\'comsTAB\')">COMMENTARY</td> <td class="audTab" id="imgsTAB" onclick="selTab(\'imgs\',\'news=&coms=\')" onmouseover="hovOvr(\'imgsTAB\',\'images/aud_images/imgs_bg.gif\')" onmouseout="hovOut(\'imgsTAB\')">IMAGE</td> </tr> </table> </div> <div class="minitab_right" style="background-image:url(elements/tab_right.png); background-repeat:no-repeat"></div> </div> <!--minitabtab--> <div class="miniwrap" id="pubs"> &nbsp; </div><div id="a_logout"><a href="javascript:void(0);" onclick="a_logout();" class="log" style="color:#B87000 !important;">logout&nbsp;&nbsp;</a><a href="javascript:void(0);" onclick="goBacAuds();" class="log" style="color:#B87000 !important;">go&nbsp;back&nbsp;|&nbsp;</a></div>';
	pc.style.backgroundColor = '';
	refresh('news');
}
function reform() {
	var pc = elm('pubsCont');
	pc.innerHTML = mPreCon;
	pc.style.backgroundColor = '#000';
}
function goBacAuds() {
	reform();
	var cont = elm('pDisp');
	function fetch_audios(cnt) {
		cont.innerHTML = cnt;
	}
	cont.innerHTML = '<div align="center"><strong>Fetching News...</strong></div>';
	aGet('readAuds.php', 'news=&coms=', fetch_audios);
}
function a_logout() {
	var pc = elm('pubsCont');
	var lg = elm('a_logout');
	lg.innerHTML = LDIN;
	function success(cnt) {
		goBacAuds();
	}
	function failed(cnt) {
		pDisp.innerHTML = 'The following error occurred while loading publications: '+cnt;
	}
	aGet('CMS/login.php', 'action=logout', success, failed);
}

//////////////////////////////////////SPORTS
function doSports() {
	var se = elm('weekSports');
	preSpo = se.innerHTML;
	se.innerHTML = '<div class="minitab"> <div class="minitab_left" style="background-image:url(elements/tab_left.png); background-repeat:no-repeat"></div> <div class="minitab_middle" style="background-image:url(elements/tab_middle.png); background-repeat:repeat-x; padding-top:3px; height:24px;"> <table cellpadding="0" cellspacing="0" id="sAudTabs"> <tr> <td class="audTab" id="sportsTAB" onclick="selTab(\'sports\')" onmouseover="hovOvr(\'sportsTAB\',\'images/aud_images/sports_bg.gif\')" onmouseout="hovOut(\'sportsTAB\')">SPORTS NEWS</td><td class="audTab" id="simgsTAB" onclick="selTab(\'simgs\',\'sports=\')" onmouseover="hovOvr(\'simgsTAB\',\'images/aud_images/imgs_bg.gif\')" onmouseout="hovOut(\'simgsTAB\')">IMAGE</td> </tr> </table> </div> <div class="minitab_right" style="background-image:url(elements/tab_right.png); background-repeat:no-repeat"></div> </div> <!--minitabtab--> <div class="miniwrap" id="sPubs" style="height:auto;"> &nbsp; </div><div id="s_logout"><a href="javascript:void(0);" onclick="s_logout();"  class="log" style="color:#B87000 !important;">logout&nbsp;&nbsp;</a><a href="javascript:void(0);" onclick="goBacSpo();" class="log" style="color:#B87000 !important;">go&nbsp;back&nbsp;|&nbsp;</a></div>';
	elm('sPubs').innerHTML = "<div align=\"center\"><p>"+LDIN+"<strong>1 SEC...</strong></p></div>";
	se.style.backgroundColor = '';
	selTab('sports');
}

function canSpo() {
	var se = elm('weekSports');
	se.innerHTML = preSpo;
	se.style.backgroundColor = '#000';
}

function goBacSpo() {
	var se = elm('weekSports');
	se.innerHTML = preSpo;
	var cont = elm('sportAuds');
	function shoSpo(cnt) {
		se.style.backgroundColor = '#000';
		cont.innerHTML = cnt;
	}
	cont.innerHTML = '<div align="center"><strong>Fetching Sports Updates...</strong></div>';
	aGet('readAuds.php', 'sports=', shoSpo);
}

function s_logout() {
	var se = elm('weekSports');
	var lg = elm('s_logout');
	lg.innerHTML = LDIN;
	function success(cnt) {
		goBacSpo();
	}
	function failed(cnt) {
		pDisp.innerHTML = 'The following error occurred while loading publications: '+cnt;
	}
	aGet('CMS/login.php', 'action=logout', success, failed);
}






























