// 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://www.africastabuja.com/images/ajax-loader.gif' height='20'  />&nbsp; Wait while processing .....",
					constLoadHTML: "<img src='http://www.africastabuja.com/images/ajax-loader.gif' height='20'  />&nbsp; Wait while Loading .....",
					constLoadOption: "<img src='http://www.africastabuja.com/images/ajax-loader.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",
					enctype: "multipart/form-data",
					myheader: "Content-Type",
					GET:"GET",
					delayTimeout: 2000,
					delayBeforeRedirect: 4000
				  };

//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]);
		//alert(menudiv);
		setObjState(menudiv, true, true);
		
		if(tempdiv != menudiv){
			if(tempdiv != null){
				setObjState(tempdiv, false, false);
			}
		}
		tempdiv = menudiv;  
	}
	catch(e){
		alert(e.name + ' ' + e.message);
		return;
	}
}

function openLink(){
	try{
		self.document.location.href = arguments[0];
		return true;
	}
	catch(e){
	}
}

function showVisible(obj, visible){
	obj.style.visibility = visible ? "visible" : "hidden";
}

// 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 = '';
		}
		else if(type == 'select-one'){
			frm.elements[i].options[0].selected = true;
		}
	}
}
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){
	if(msg.length > 0){
		with(obj){
			innerHTML = msg.toString();
			style.Border = 'thick 1px #FFCC00';
			style.fontSize = '10px';
			style.color = '#0000FF';
			style.Height = '20px';
			style.fontFamily = ' Verdana';
			style.backgroundColor="#FFFFFF";
		}
	}
}

function getQueryString(obj){
	var sParams = Array();
	var sParam;
	for(var i=0; i < obj.elements.length; ++i){
		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);
}
//parse date of this format dd/mm/yyyy to yyyy,mm,dd
function parseDate(dt){
	dt = dt.split('/');
	str = dt[2]+','+dt[1]+','+dt[0];
	return str;
}
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";
		document.location.href=url;
		return true;
	}
	return false;
}