// COMMON JS Functions ------------------
function set_focus(element_id){
	if(document.getElementById(element_id)){
		document.getElementById(element_id).focus();
	}
}
function set_value(ele,val){alert('Here');
	document.getElementById(ele).value	=	val;
}
function newPage(page) {
	window.location = base_url + page;
}
function display_error(msg){
	hide_error();
	if(msg){
		$('#error_message').html(msg);
		$('#error_message').css("display", "block");
        window.scroll(0,0);
	}
}
function display_success(msg){
	hide_error();
	if(msg){
		$('#success_message').html(msg);
		$('#success_message').css("display", "block");
	}
}
function hide_error(){
	if($('#error_message')){
		$('#error_message').html('');
		$('#error_message').css("display", "none");
	}
	if($('#success_message')){
		$('#success_message').html('');
		$('#success_message').css("display", "none");
	}
}
function display_content_loader(){
	hide_error();
}
/* Email Validation */
function isValidEmail(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
	if (filter.test(email)){
		return true;
	}else{
		return false;
	}

}
function numbersonly(myfield, e, dec){
		var key;
		var keychar;
		if (window.event)
			 key = window.event.keyCode;
		else if (e)
			 key = e.which;
		else
			 return true;
		keychar = String.fromCharCode(key);
		
		// control keys
		if ((key==null) || (key==0) || (key==8) || 
				(key==9) || (key==13) || (key==27) )
			 return true;
		
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			 return true;
		
		// decimal point jump
		else if (dec && (keychar == "."))
			 {
			 myfield.form.elements[dec].focus();
			 return false;
			 }
		else
			 return false;
			 
}
function numbersonly_sp(myfield, e, dec,sp){
		var key;
		var keychar;
		if (window.event)
			 key = window.event.keyCode;
		else if (e)
			 key = e.which;
		else
			 return true;
		keychar = String.fromCharCode(key);
		
		// control keys
		if ((key==null) || (key==0) || (key==8) || 
				(key==9) || (key==13) || (key==27) )
			 return true;
		
		// numbers
		else if ((("0123456789"+sp).indexOf(keychar) > -1))
			 return true;
		
		// decimal point jump
		else if (dec && (keychar == "."))
			 {
			 myfield.form.elements[dec].focus();
			 return false;
			 }
		else
			 return false;
			 
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function numbersonlynonzero(myfield, e, dec){
		var key;
		var keychar;
		if (window.event)
			 key = window.event.keyCode;
		else if (e)
			 key = e.which;
		else
			 return true;
		keychar = String.fromCharCode(key);
		
		// control keys
		if ((key==null) || (key==0) || (key==8) || 
				(key==9) || (key==13) || (key==27) )
			 return true;
		
		// numbers
		else if ((("123456789").indexOf(keychar) > -1))
			 return true;
		
		// decimal point jump
		else if (dec && (keychar == "."))
			 {
			 myfield.form.elements[dec].focus();
			 return false;
			 }
		else
			 return false;
			 
}
function makeUpper(ele){
	cur	=	ele.value;
	ele.value	=	cur.toUpperCase();
}
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function open_tooltip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}
function hide_tooltip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        {
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        }
      }
    return "";
}
