// JavaScript Document
//define all the generic constants and methods needed in client script here
var constValues = {
					regAmount:/^\d{1,3}(\d{3})*(\.\d{2})*$|^\d+\.\d\d$/,
					regDOB: /^(0[1-9]|[1-9]|(1|2)\d|3(0|1))\/(0[1-9]|1[0-2])\/(19|20)\d{2}$/,
					regEmail: /[\w\_-]+@[\w\-.]+\.[\w{2,4}]|[\d\w]+@[\w\-.]+\.[\w{2,4}]/,
					constWaitHTML: "<img src='http://localhost/nbc_new/images/loading.gif' height='20'  />&nbsp; Wait while processing .....",
					constLoadHTML: "<img src='http://localhost/nbc_new/images/loading.gif' height='20'  />&nbsp; Wait while Loading .....",
					constLoadOptions: "<img src='http://localhost/nbc_new/images/loading.gif' height='15'  />",
					Timeout: 100000,
					query:'',
					errmsg: "<div><span style='color:red; font-size:12px; font-weight:bold'>Please review the following error(s):</span> <br />",
					popmsg: "Do you want to delete this record?",
					POST: "POST",
					myvalue: "application/x-www-form-urlencoded",
					myheader: "Content-Type",
					delayTimeout: 5000
				  };

//set the menu to show or collapse and change the image to mimic the action

var menudiv = null;
var tempdiv = null;
function showList(){
	try{
		menudiv = getRawObject(arguments[0]);
		setObjState(menudiv, true, true);
		if(tempdiv != menudiv){
			if(tempdiv != null){
				setObjState(tempdiv, false, false);
			}
		}
		else if(tempdiv == menudiv){
			if(menudiv.style.diplay == 'none'){
				setObjState(menudiv, true, true);
			}
			else{
				setObjState(menudiv, false, false);
			}
		}
		tempdiv = menudiv;  
	}
	catch(e){
		alert(e.name + ' ' + e.message);
		return;
	}
}
var menudivs = new Array();
var on_off = new Array();
var number_of_menus = 6;
menudivs[0] = ["<a href='broadcast.php?menu=1&submenu=1' target='_self'>FG Owned</a>",
			   "<a href='broadcast.php?menu=1&submenu=2' target='_self'>State Govt Owned</a>",
			   "<a href='broadcast.php?menu=1&submenu=3' target='_self'>Private</a>",
			   "<a href='broadcast.php?menu=1&submenu=4' target='_self'>Network</a>",
			   "<a href='broadcast.php?menu=1&submenu=5' target='_self'>Campus TV</a>"];
menudivs[1] = ["<a href='broadcast.php?menu=2&submenu=1' target='_self'>FG Owned</a>",
			   "<a href='broadcast.php?menu=2&submenu=2' target='_self'>State Govt Owned</a>",
			   "<a href='broadcast.php?menu=2&submenu=3' target='_self'>Private</a>",
			   "<a href='broadcast.php?menu=2&submenu=4' target='_self'>Network</a>",
			   "<a href='broadcast.php?menu=2&submenu=5' target='_self'>Campus Radio</a>",
			    "<a href='broadcast.php?menu=2&submenu=6' target='_self'>Community Radio</a>"];
menudivs[2] = ["<a href='broadcast.php?menu=3&submenu=1' target='_self'>MMDS</a>",
			   "<a href='broadcast.php?menu=3&submenu=2' target='_self'>DTH</a>",
			   "<a href='broadcast.php?menu=3&submenu=3' target='_self'>DBS</a>"];
menudivs[3] = ["<a href='broadcast.php?menu=4&submenu=1' target='_self'>DTH</a>"];
//set on and off menu to zero
for(var loop=0; loop < number_of_menus; ++loop){
	on_off[loop] = 0;
}
function collapse_menu(){
	try{
		menudiv = getRawObject(arguments[0]);
		var itemno = arguments[1];
		var hassubmenu = arguments[2];
		if(parseInt(hassubmenu,10) == 1){
			if(menudiv.style.display == 'none'){
				setObjState(menudiv, true, true);
			}
			else{
				setObjState(menudiv, false, false);
			}
		}
		else{
			if(on_off[itemno] == 0){
				var items = menudivs[itemno];
				var ilist = '';
				setObjState(menudiv, true, true);
				for(var j=0; j < items.length; ++j){
					if(j == (items.length - 1)){
						ilist += items[j];
					}
					else{
						ilist += items[j] + '<br />';
					}
				}
				menudiv.innerHTML = ilist.toString();
				on_off[itemno] = 1;
			}
			else{
				menudiv.innerHTML = "&nbsp;";
				setObjState(menudiv, false, false);
				on_off[itemno] = 0;
			}
		}
	}
	catch(e){
		alert(e.name + ' ' + e.message);
		return;
	}
}

// set the field value nothing
function setFormElementsToNothing(frm){
	var len = frm.elements.length;
	for(var i=0; i < len; ++i){
		var type = frm.elements[i].type;
		if(type == 'text' || type == 'textarea'){
			frm.elements[i].value = '';
		}
	}
}
function openwin(url,winname, width, height){
	var top = parseInt((screen.availHeight / 2) - (height/2));
	var left = parseInt((screen.availWidth / 2) - (width/2));
	var win;
	var windowfeatures = "scrollbars, location,fullscreen,resizable=no,status=no, menubar=no,top="+top+", left="+left+",width="+width+", height="+height+",toolbar=no";
	//alert(windowfeatures); return;
	if(win){
		win.close(); //closes the window
	}
	win = window.open(url, winname,windowfeatures);
	win.focus(); //set it current
}

//process the ajax calling routine
function processForm(url,progress,obj,reqType,qry, progresshtml){ 
	try{
		InitRequest(url,progress,obj,reqType,qry, progresshtml);
		//alert(getXMLHTTP());
	}
	catch(err){
		alert(err.name + '  ' + err.message);
		return;
	}	
}

function setObjState(obj, showdisplay, showVisible){
	obj.style.display = showdisplay ? "block": "none";
	obj.style.visibility = showVisible ? "visible": "hidden";
}

function setObjToNull(obj, space){
	obj.innerHTML = space;
	setObjState(obj, false, false);
}

function setObjError(obj, msg, color){
	if(msg.length > 0){
		with(obj){
			innerHTML = msg.toString();
			style.Border = 'thick 1px #FFCC00';
			style.fontSize = '10px';
			style.color = color;
			style.Height = '20px';
			style.fontFamily = ' Verdana';
			style.backgroundColor="#FFFFFF";
		}
	}
}

function getQueryString(obj){
	var sParams = Array();
	var sParam;
	var type;
	for(var i=0; i < obj.elements.length; ++i){
		type = obj.elements[i].type;
		if(type != 'radio'){
			sParam = encodeURIComponent(obj.elements[i].name);
			sParam += "=";
			sParam += encodeURIComponent(obj.elements[i].value);
			sParams.push(sParam);
		}
		else{
			if((type == 'radio') && (obj.elements[i].checked == true)){
				sParam = encodeURIComponent(obj.elements[i].name);
				sParam += "=";
				sParam += encodeURIComponent(obj.elements[i].value);
				sParams.push(sParam);
			}
		}
	}
	return sParams.join("&");
}
//get the page url
function getPageUrl(){
	var index = location.href.search();
}
//validate any value via regular expression
function validate(reg, val){
	return reg.test(val);
}

function _getDay(dt){
	dt = dt.split('/');
	return dt[0];
}
function _getMonth(dt){
	dt = dt.split('/');
	return dt[1];
}
function _getYear(dt){
	dt = dt.split('/');
	return dt[2];
}
//return days difference between two dates
function dayDifference(startdate, enddate){
	var ms1 = startdate.getTime();
	var ms2 = enddate.getTime();
	var oneSec = 1000;
	var oneMin = 60 * oneSec;
	var oneHr = 60 * oneMin;
	var oneDay = 24 * oneHr;
	var diff = ms2 - ms1;
	var daysLeft = Math.floor(diff/oneDay);
	return daysLeft;
}
//find the first textbox in a control and set it as a focus
function setFocus(form){
	if(document.forms){
		var len = form.elements.length;
		var type;
		for(var i=0; i < len; ++i){
			type = form.elements[i].type;
			if(type == 'text'){
				form.elements[i].focus();
				return false;
			}
		}
	}
}
//use this to check fa space when expectation is a whole word
function containsblanks(s)

{
  for(var i = 0; i < s.value.length; i++)

  {

      var c = s.value.charAt(i);

      if ((c == ' ') || (c == '\n') || (c == '\t'))

      {
         // alert('The field must not contain whitespace');
          return false;

      }
  }
  return true;
}
//to log out of the application
function LogOut(url){
	if(window.confirm("Do you really want to Log Out?")){
		url += "?q=logout";
		location.href=url;
		return true;
	}
	return false;
}
//redirect to a page
function openLink(){
	var url = arguments[0];
	if(url.toLowerCase() == 'www.africastabuja.com'){
		document.location.href = "http://"+url;
		return true;
	}
	window.location.href = url;
	document.returnValue = true;
}