/* Highlighted Cursor Focus */
var highlightcolor="#F0F0FF";
var ns6=document.getElementById&&!document.all;
var previous='';
var eventobj;

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA/;

function getMyListRef() {
	winwidth = 750; // width of the new window
	winheight = 550; // height of the new window
	winleft = 200; // just dummie values
	wintop = 200; // just dummie values

	if(parseInt(navigator.appVersion)>=4){
		winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left 
		wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom 
		 // the values get inserted into the features parameter of the window.open command... 
	}
	window.open('Login.php?action=MyListRef','ReferenceWindow', 'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth + ',menubar,toolbar,scrollbars,resizable');
}

//Function to check whether element clicked is form element
function checkel(which){
	if (which.style&&intended.test(which.tagName)){
		if (ns6&&eventobj.nodeType==3){ eventobj=eventobj.parentNode.parentNode; }
		return true	
	}else {	return false; }
}

//Function to highlight form element
function highlight(e){
	eventobj=ns6? e.target : event.srcElement;
	if (previous!=''){
		if (checkel(previous)){	previous.style.backgroundColor='';}
		previous=eventobj;
		if (checkel(eventobj)){	eventobj.style.backgroundColor=highlightcolor;}
	}else{
		if (checkel(eventobj)){ eventobj.style.backgroundColor=highlightcolor;}
		previous=eventobj;
	}
}

//Function to check element before submit
function checkrequired(which){
	var pass=true;
	if (document.images){
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i];
			if ((tempobj.name.substring(0,8)=="required")||(tempobj.name.substring(0,2)=="ck")){
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
					pass=false;
					break;
				}
			}
		}
	}
	if (!pass){
		winwidth = 350; // width of the new window 
		winheight = 320; // height of the new window 
		winleft   = 200; // just dummie values
		wintop    = 200; // just dummie values

		if(parseInt(navigator.appVersion)>=4){
			var winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left 
			var wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom 
			// the values get inserted into the features parameter of the window.open command... 
		}
	
		var win=window.open('','Error','top=500,left=' + winleft+',height=' + winheight + ',width=' + winwidth+',toolbar=no,resizable=no'); 
		win.document.write('<html><head><title>Required Field</title></head><body>');
		win.document.write('<center><img src="images/error.gif"></center><br>');
		win.document.write('<p><CENTER><font face="verdana" color="red"><b>Fill-up fields with • to continue!</font></center></p>');
		win.document.write('<p><center><form><input type="button" onClick="javascript:self.close()" value="  OK  " class="ifldbutton" ></form></center></p>');
		win.document.write('</body></html>');
		return false;
	} else { return true; }
}

//Function to Limit characters to text area elements
var ns6=document.getElementById&&!document.all;
function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength) { return false; }
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
		var pressedkey=/[a-zA-Z0-9\.\,\/]/; //detect alphanumeric keys
		if (pressedkey.test(String.fromCharCode(e.which))) { e.stopPropagation(); }
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder);
	var lengthleft=maxlength-theform.value.length;
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder);
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0) {	theform.value=theform.value.substring(0,maxlength); }
		placeholderobj.innerHTML=lengthleft;
	}
}

function displaylimit(theform,thelimit){
	var limit_text='<font class=ebucksnorm><font color=red><span id="'+theform.toString()+'">'+thelimit+'</span>' +' <br>spaces left</font></font>';
	if (document.all||ns6){	document.write(limit_text); }
	if (document.all){
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)};
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)};
	}else if (ns6){
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}
