// JavaScript Document
var ldiv='';//last div shown
function urlencode(s) {
	//php compatable
  s = encodeURIComponent(s);
  return s.replace(/~/g,'%7E').replace(/%20/g,'+');
}
function addEvent(obj,evType,fn,useCapture){
	useCapture=(!useCapture)?'false':useCapture;
	if(obj.addEventListener){
		obj.addEventListener(evType,fn,useCapture);
		return true;
	}else if(obj.attachEvent){
		var r=obj.attachEvent("on"+evType.toString(),fn);
		return r;
	}
}
function cancelEvent(evt){
	evt=(evt)?evt:window.event;
	evt.cancelBubble=true;
	if(typeof evt.stopPropagation=='function'){
		evt.stopPropagation();
	}
	evt.returnValue=false;
	if(typeof evt.preventDefault=='function'){
		evt.preventDefault();
	}
}
function fullScreen(theURL) {
window.open(theURL, '', 'fullscreen=yes, scrollbars=auto');
}
function mark_as_read(obj){
	var tr=obj.parentNode;
	while(tr.nodeName!="TR"){
		tr=tr.parentNode;
	}
	if(tr.className=="mess_unread"){
		myAddClassName(tr,"mess_read");
		myRemoveClassName(tr,"mess_unread");
	}
}
function myAddClassName(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};
function myRemoveClassName(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};
function popup(src,winname,pw,ph,center,scrollb){
	var top=10,left=10;
	var w=0,h=0;
	if(center){
		if(document.all){
			w=document.body.parentNode.clientWidth;
			h=document.body.parentNode.clientHeight;
		}else if(document.layers){
			w=window.innerWidth;
			h=window.innerHeight;
		}
		if(w>0 && h>0){
			left=(w-pw)/2;
			top=(h-ph)/2;
		}
	}
	var win=window.open(src,winname,'width='+pw+',height='+ph+',top='+top+',left='+left+',scrollbars='+scrollb);
	win.focus();
}
function unschedule_swap_txt(src,tgt,type,show,hide){
	var tgt=document.getElementById(tgt);
	switch(type){
		case "innerHTML":
		case "div":
			tgt.innerHTML=src;
			break;
		case "value":
			tgt.value=src;
			break;
		default:
			break;
	}
	if(show){document.getElementById(hide).style.display="none";}
	if(hide){document.getElementById(show).style.display="block";}
	
}
function align_div(targ,src,offsetx,offsety,border){
	targ=document.getElementById(targ);
	src=document.getElementById(src);
	if(!targ.style.position){targ.style.position="absolute";}
	if(border){targ.className="borderbk";}
	targ.style.zindex=999;
	targ.style.float="left";
	targ.style.left=getXfromLeft(src.id)+offsetx;
	targ.style.top=getYfromTop(src.id)+offsety;
}
function pleasewait1(onoff){
		var w=document.getElementById("pwait");
		if(!w){return;}
			if(!onoff){
				w.style.display="none";return;
			}else{
				w.style.display="block";
			}
	w.style.position="fixed";
	w.style.float="left";
	w.style.width=document.body.parentNode.clientWidth+"px";
	w.style.height=document.body.parentNode.clientHeight+"px";
	w.style.top=0;
	w.style.left=0;
	var t=document.getElementById('cont_wait');
	t.style.width="100%";
	t.style.height="90%";
	
}
function select_all(frmname,onoff){
	var frm=document.forms[frmname];
	for(x=0;x<frm.elements.length;x++){
		if(frm.elements[x].type=="checkbox"){
			frm.elements[x].checked=(onoff==1?"checked":false);
		}
	}
}
function toggle_div(obname){
	var mdiv=document.getElementById(obname);
	mdiv.style.display=(mdiv.style.display=="none"?"block":"none");
}
function show_hide(oshow,ohide){
	if(ohide!=""){
	var h=document.getElementById(ohide);
	h.style.display="none";
	}
	if(oshow!=""){
	var s=document.getElementById(oshow);
	s.style.display="block";
	ldiv=oshow;
	}
}
function set_cookie(name,value,days){
	var exp = new Date( );
	var nowPlusOneWeek = exp.getTime( ) + (days * 24 * 60 * 60 * 1000);
	exp.setTime(nowPlusOneWeek);
	document.cookie =name+"="+value+"; expires=" + exp.toGMTString( )+";path=/;";
	
}
function toggle_mod(obj,nocookie){
	
	if(obj.parentNode.className=="mod_main"){
		var mobj=obj.parentNode;
		for(i=0;i<mobj.childNodes.length;i++){
			if(mobj.childNodes[i].className=="mod_sub"||mobj.childNodes[i].className=="mod_sub_collapse"||mobj.childNodes[i].className=="mod_sub_xbk"){
				if(mobj.childNodes[i].style.display==""){
					mobj.childNodes[i].style.display=(mobj.childNodes[i].className=="mod_sub"||mobj.childNodes[i].className=="mod_sub_xbk"?"none":"block");
				}
				if(mobj.childNodes[i].style.display=="block"){
					mobj.childNodes[i].style.display="none"
					if(obj.style.backgroundImage!="none"){obj.style.backgroundImage="url(../images/icons/expand.gif)";}
					if(!nocookie){set_cookie(mobj.id,"expand",7);}
				}else{
					mobj.childNodes[i].style.display="block";
					if(obj.style.backgroundImage!="none"){obj.style.backgroundImage="url(../images/icons/collapse.gif)";}
					if(!nocookie){set_cookie(mobj.id,"collapse",7);}
				}
			}
		}
	}
}
var tm;
   function getformdata(obj) {
      var getstr = "";
      for (i=0; i<obj.elements.length; i++) {
            if (obj.elements[i].type == "text" || obj.elements[i].type == "hidden"||obj.elements[i].type == "password") {
               getstr += obj.elements[i].name + "=" + obj.elements[i].value.replace("&","%26") + "&";//replace & with hex value
            }
            if (obj.elements[i].type == "textarea" ) {
               getstr += obj.elements[i].name + "=" + obj.elements[i].innerHTML.replace("&","%26") + "&";
            }
            if (obj.elements[i].type == "checkbox") {
               if (obj.elements[i].checked) {
                  getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
               } else {
                  getstr += obj.elements[i].name + "=&";
               }
            }
            if (obj.elements[i].type == "radio") {
               if (obj.elements[i].checked) {
                  getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
               }
            }
			if(obj.elements[i].type=="select"||obj.elements[i].type=="select-one"){
				getstr +=obj.elements[i].name+"="+(obj.elements[i].options[obj.elements[i].selectedIndex].value)+"&";
			}
			if(obj.elements[i].type=="select-multiple"){
				for(x=0;x<obj.elements[i].options.length;x++){
					if(obj.elements[i].options[x].selected){
						getstr +=obj.elements[i].name+"["+x+"]="+(obj.elements[i].options[x].value)+"&";
					}
				}
			}
         }   
         
      return getstr;
   }
   function getformdata1(obj) {
      var getstr = "";
      for (i=0; i<obj.elements.length; i++) {
            if (obj.elements[i].type == "text" || obj.elements[i].type == "hidden"||obj.elements[i].type == "password") {
               getstr += obj.name+"["+obj.elements[i].name+"]" + "=" + obj.elements[i].value.replace("&","%26") + "&";//replace & with hex value
            }
            if (obj.elements[i].type == "textarea" ) {
               getstr += obj.name+"["+obj.elements[i].name+"]" + "=" + obj.elements[i].innerHTML.replace("&","%26") + "&";
            }
            if (obj.elements[i].type == "checkbox") {
               if (obj.elements[i].checked) {
                  getstr += obj.name+"["+obj.elements[i].name+"]" + "=" + obj.elements[i].value + "&";
               } else {
                  getstr += obj.name+"["+obj.elements[i].name+"]" + "=&";
               }
            }
            if (obj.elements[i].type == "radio") {
               if (obj.elements[i].checked) {
                  getstr += obj.name+"["+obj.elements[i].name+"]" + "=" + obj.elements[i].value + "&";
               }
            }
			if(obj.elements[i].type=="select"||obj.elements[i].type=="select-one"){
				getstr +=obj.name+"["+obj.elements[i].name+"]"+"="+(obj.elements[i].options[obj.elements[i].selectedIndex].value)+"&";
			}
         }   
         //alert(getstr);
      return getstr;
   }
function startNonAjax(func_name){
	if(tm)window.clearTimeout(tm);
	tm=window.setTimeout(func_name,1000);
}
function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	return ajaxRequest;
}
function checkpassword(pmin,pmax){
	var pwlen=document.getElementById("user_password").value;
	var pw_err=document.getElementById("pw_error");
	if(pwlen.length<pmin || pwlen.length>pmax){
		pw_err.innerHTML="<img src=\"images/icons/red_att.gif\" alt=\"Please rectify error\"/> Password must be "+pmin+"-"+pmax+" chars.";
		pw_err.style.display="block";
	}else{
		pw_err.innerHTML="";
		pw_err.style.display="none";
	}
}
function pleasewait(tog){
	var frms=document.forms.length-1;
	for(x=0;x<=frms;x++){
		var els=document.forms[x].elements.length;
		for(y=0;y<els;y++){
			//alert(document.forms[x].name+">"+document.forms[x].elements[y].tagName+">"+document.forms[x].elements[y].name+">"+document.forms[x].elements[y].type+">"+document.forms[x].elements[y].value);
			if(document.forms[x].elements[y].tagName!="FIELDSET"){
				if(!document.forms[x].elements[y].type.indexOf("select")){
					//document.forms[x].elements[y].disabled=true;
					document.forms[x].elements[y].style.visibility=(tog=="off"?"visible":"hidden");
				}
			}
		}
	}
	try{
		var pw=document.getElementById("waiting");
		if(!pw){alert("waiting not found try pleasewait1");}
		pw.style.left=document.body.scrollLeft;
		pw.style.top=document.body.scrollTop;
		pw.style.width=document.body.clientWidth;
		pw.style.height=document.body.clientHeight;
		pw.style.display=(tog=="off"?"none":"block");
	}catch(e){alert("Please Wait "+e);}
}
function getXfromLeft(imgID) { 
   
  //if not using IE 
  if (getBrowser()!="IE") return document.getElementById(imgID).x; 
  else return getRealLeft(imgID);//else, using Internet explorer 
} 

function getYfromTop(imgID) { 
  if (getBrowser()!="IE") return document.getElementById(imgID).y; 
  else return getRealTop(imgID); 
} 




////////////////////////// 
//These below handle Internet explorer 
///////////////////////// 

function getRealLeft(imgElem) { 
    xPos = document.getElementById(imgElem).offsetLeft; 
    tempEl = document.getElementById(imgElem).offsetParent; 
      while (tempEl != null) { 
          xPos += tempEl.offsetLeft; 
          tempEl = tempEl.offsetParent; 
      } 
    return xPos; 
} 

function getRealTop(imgElem) {// 
    yPos = document.getElementById(imgElem).offsetTop; 
    tempEl = document.getElementById(imgElem).offsetParent; 
    while (tempEl != null) { 
          yPos += tempEl.offsetTop; 
          tempEl = tempEl.offsetParent; 
      } 
    return yPos; 
} 

///  browser
var detect = navigator.userAgent.toLowerCase(); 
var browser,thestring; 


function getBrowser() 
{ 

if (checkIt('msie') || checkIt('internet explorer')) browser = "IE"; 
else if (!checkIt('compatible') || checkIt('firefox')) 
{ 
    browser = "Mozilla"; 
    if(checkIt('firefox')) 
        browser="Firefox"; 
} 
else browser = "Unknown"; 



return browser; 
} 



function checkIt(string) 
{ 
    place = detect.indexOf(string) + 1; 
    thestring = string; 
    return place; 
} 
 
function is_date(mdate){
	var dpat=/^\d{1,2}[\/|-]\d{1,2}[\/|-]\d{4}$/;
	if(mdate.match(dpat)){
		return true;
	}else{
		return false;
	}
}


//Show the properties of an object
function showProperties (o) {var r = ""; for (var p in o) {r += p + ": " + o[p] + "\t";} alert (r);}

//This uses a calendar object.
function Calendar (name, initialdate, callback, noweekends,noclose) {
	this.noclose=(noclose?true:false); //added to ensure callback get run for checking date valid ie not inpast
	this.name = name;
	this.fullname = "calendar_" + name;
	this.displaydate = new Date(); //the date to display
	//if (document[this.fullname]) { //the calendar has already been used before, get the old data
		
		//this.displaydate = document[this.fullname].displaydate;
		//this.initialdate = document[this.fullname].initialdate;
		//alert(this.displaydate+" - "+this.initialdate);
	//}
	//else {
		if (initialdate) {
		var regx=/-/g;
		initialdate=initialdate.replace(regx,"/");
					if(initialdate.search("/")>0){
						var parts=initialdate.split("/");
						var regx=/\d{4}\/\d{1,2}\/\d{1,2}/;
						//alert(initialdate.match(regx))
						if(initialdate.match(regx)){
							initialdate=parts[1]+"/"+parts[2]+"/"+parts[0];// Y/m/d - m/d/Y
						}else{
							initialdate=parts[1]+"/"+parts[0]+"/"+parts[2];
						}
					}
		this.displaydate.setTime (Date.parse (initialdate));
		} //set to the initialisation date
		this.initialdate = new Date (this.displaydate.getTime()); //store the initial date
	//}
	this.callback = callback; //the callback function which is passed the date
	this.weekends = noweekends ? false : true; //display weekends or not
	this.format(); //format this calendar
	document[this.fullname] = this; //save a copy of this object (which we will reference in links)
}

//Change the text of the calendar and display or hide it
function Calendar_change (text, visible) {
	if (!document.getElementById) return; //IE and Firefox only for now
	var el = document.getElementById(this.fullname); //get the element
	if (text) el.innerHTML = text; //set the text
	el.style.visibility = visible ? "visible": "hidden"; //show or hide it
}

//Get a link which calls a function in the calendar
function Calendar_getLink (callback, text) { 
	var r = "<a href=\"javascript:void document." + this.fullname + "."; //start the link
	r += callback + "\">" + text + "</a>"; //add the call back and text
	return r; //return the link
}

//Add a month to the calendar display date
function Calendar_addMonths (howmany) {this.displaydate.addMonths(howmany); this.format(true);}

//Return the name of the calendar and the date to the requested function. The defautl just calls
//the same page passing in the name, display time and display date.
function Calendar_returnDate (day) {
	this.displaydate.setDate(day);
	if (this.callback) eval ([this.callback] + "(this.name, this.displaydate)"); //call the call back function
	else document.location.href = document.location.pathname + "?calendarname=" + this.name + 
		"&calendartime=" + Math.floor(this.displaydate.getTime()/1000) + //because it's in milliseconds
		"&calendardate=" + this.displaydate.toGMTString();
}

//Output the table
function Calendar_format() {
	var days = new Array ("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");
	var firstcol = this.weekends ? 0 : 1; //start from day 0 if we have weekends
	var lastcol = this.weekends ? 6 : 5; //end at day 6 if we have weekends
	//////////////// display the header rows ////////////////
	var r = "<table cellspacing=\"0\">\n"; //start the table
	r += "<tr><th class=\"calendararrows\">" + this.getLink ("addMonths(-1)", "&lt;") + "</th>\n"; //back a month
	r += "<th class=\"calendarmonth\" colspan=\"" + (this.weekends ? 5 : 3) + "\">"; //colspan of the title
	r += this.displaydate.getMonthName() + " " + this.displaydate.getActualYear(); //the month and year
	r += "</th>\n<th class=\"calendararrows\">" + this.getLink ("addMonths(1)", "&gt;") + "</th>\n</tr>\n"; //add a month
	var cellwidth = Math.floor (100/ (this.weekends ? 7 : 5)); //width of each weekday column
	for (var day=firstcol; day<=lastcol; day++) {r += "<col width=\"" + cellwidth + "%\" />\n";} //width of cells
	r += "<tr>"; //start the days of the week
	for (var day=firstcol; day<=lastcol; day++) {r += "<th class=\"calendardayofweek\">" + days[day] + "</th>\n";}
	r += "</tr>\n"; //end of days of week
	//////////////// get the start and end day for this month ////////////////
	var td = new Date (this.displaydate.getTime()); //for this we will need to use a temporary date
	var initialnumber = (td.getMonth() == this.initialdate.getMonth()) && (td.getYear() == this.initialdate.getYear()) ?
		this.initialdate.getDate() : 0; //set to the initial date's number or 0
	td.setDate(1); //go to the first of the month
	var startday = td.getDay(); //get the day of the week
	td.addMonths(1); //add a month to the temporary date
	var endday = (td.getDay() + 6) % 7; //end on this day of the week (and subtract one)
	var td = new Date(); //reset to now
	var todaynumber = (td.getMonth() == this.displaydate.getMonth()) && (td.getYear() == this.displaydate.getYear()) ?
		td.getDate() : 0; //set to today's date's number or 0
	//////////////// figuring out starting week and number of weeks ////////////////
	//var numweeks = (startday==0 && endday==6) ? 5 : 6; //the number of weeks to display (4 in February)
	var startweek = 1; //which week to start with
	if (!this.weekends && startday==6) startweek=2; //start on week 2 if the first day is a Sat or Sun
	var numweeks = 6; //maximum number of weeks needed to display this month
	if (endday > startday-2) numweeks = 5; //can be displayed in 5 weeks
	if (startday == 0 && endday == 6) numweeks = 4; //a February starting on a Sunday
	var endweek = numweeks; //the last week do display (so that the last week is shown if the next statement is true)
	if (!this.weekends && (endday%6 < 1)) numweeks--; //end a week early if the last day is a Sat or Sun
	//////////////// display the numbers ////////////////
	for (var week=startweek; week<=numweeks; week++) { //for each week (4 only in February)
		r += "<tr>";
		for (var day=firstcol; day<=lastcol; day++) { //for each day of the week
			var daynumber = (week-1)*7 + day - startday + 1; //the day number
			var dayclass="normal"; var daylink=true; //the dayclass and daylink for this day
			if (week==1 && day<startday) {dayclass="blank"; daylink=false;} //before the first day
			else if (week==endweek && day>endday) {dayclass="blank"; daylink=false;} //after the last day
			else if (daynumber==todaynumber) {dayclass="today"; daylink=true;} //todays' date
			else if (daynumber==initialnumber) {dayclass="initial"; daylink=true;} //initial date
			r += "<td class=\"calendar" + dayclass + "\">";
			r += daylink ?  this.getLink ("returnDate(" + daynumber + ")", daynumber) : "&nbsp;";
			r += "</td>\n";
		}
		r += "</tr>\n";
	}
	//////////////// finish the table ////////////////
	if(!this.noclose){
		r += "<tr><th class=\"calendarclose\" colspan=\"" + (this.weekends ? 7 : 5) + "\">";
		r += this.getLink ("change('',false)", "close") + "</th></tr>\n"; //end the days of the week
	}
	r += "</table>"; //end the table
	this.change (r, true);
}

//Get the month name from a date object
function Date_getMonthName() {
	var months = new Array ("January", "February", "March", "April", "May", "June",
				"July", "August", "September", "October", "November", "December");
	return months[this.getMonth()];
}
//Get the actual year from a date object
function Date_getActualYear() {var year = this.getYear(); return year < 500 ? year + 1900 : year;}	

//Change the month of a date by adding or subtracting months
function Date_addMonths (howmany) {
	var month = this.getMonth() + howmany;
	this.setYear (this.getActualYear() + Math.floor (month / 12)); //change the year
	this.setMonth ((month+12)%12); //change the month
}

Calendar.prototype.returnDate = Calendar_returnDate;
Calendar.prototype.change = Calendar_change;
Calendar.prototype.getLink = Calendar_getLink;
Calendar.prototype.format = Calendar_format;
Calendar.prototype.addMonths = Calendar_addMonths;
Date.prototype.getMonthName = Date_getMonthName;
Date.prototype.getActualYear = Date_getActualYear;
Date.prototype.addMonths = Date_addMonths;

function process(name,date) {
	thefield="date_"+name;
	document.getElementById(thefield).value=date.getDate() +"/"+ (date.getMonth()+1) +"/" +date.getYear();
	var thecal="calendar_"+name;
	document[thecal].change('',false);
	
}
function validate_form(frm_name,required){
	if(required==null){return true;}
	var pw=false;
	var fields=required.split(",");
	var err=new Array();
	for(x=0;x<fields.length;x++){
		var elm=document.forms[frm_name].elements[fields[x]];
		if((elm.type=="select"||elm.type=="select-one")&&elm.value=="none"){
			alert("Please select an option from the list");
			elm.focus();
			return false;
		}
		if(elm.value==null||elm.value==""){err[err.length]=1;pw=true;}else{elm.style.backgroundColor="";}
	}

	if(err.length==fields.length||err.length==0){return true;}else{
		var msetfocus=0;
		for(x=0;x<fields.length;x++){
			var elm=document.forms[frm_name].elements[fields[x]];
			if(elm.value==null||elm.value==""){
				elm.style.backgroundColor="red";
				if(msetfocus==0){elm.focus();msetfocus=1;}
			}else{
				elm.style.backgroundColor="";
			}
		}
	}
	if(pw){
		var pw1=document.getElementById("pleaswait");
		var pw2=document.getElementById("pwait");
		if(pw1 && pw1.style.display=="block"){pleasewait();}
		if(pw2 && pw2.style.display=="block"){pleasewait1();}
	}
	return false;
}
function generic_get(ajaxfile,returndiv){
	var pcdivg=document.getElementById(returndiv);
	var ajaxg=ajaxFunction();
	if(!ajaxg){return false;}
	ajaxg.onreadystatechange = function(){
		if(ajaxg.readyState == 4){
				var phpreturn=ajaxg.responseText;
			if (ajaxg.status == 200) {
				if(phpreturn!=""){
					if(pcdivg){pcdivg.innerHTML=phpreturn;}else{if(eval(phpreturn)){alert(phpreturn);}}
					pleasewait1(false);
				}else{
					if(pcdivg){pcdivg.innerHTML="<p>FORM ERROR</p>".phpreturn;}
										pleasewait1(false);

				}
			}else{
				pleasewait1(false);
				if(pcdivg){pcdivg.innerHTML="Ajax GET Error - Status Code:"+ajaxg.status;}
			}
		}
	}
	ajaxg.open("GET","../ajax/"+ajaxfile,true); 
	ajaxg.send(null);
	//return false;	
	
}
function generic_post(frm,ajaxfile,returndiv,validate,mycallback,divtxt){
	if(validate){
	for(zx=0;zx<document.forms.length;zx++){
		if(document.forms[zx].name.slice(0,frm.length)==frm){
			if(!validate_form(document.forms[zx].name,validate)){return false};
		}
	}
	}
	var pcdiv=document.getElementById(returndiv);
	var ajaxd=ajaxFunction();
	if(!ajaxd){return false;}
	ajaxd.onreadystatechange = function(){
		if(ajaxd.readyState == 4){
				var phpreturn=ajaxd.responseText;
			if (ajaxd.status == 200) {
				if(phpreturn!=""){
					pcdiv.innerHTML=phpreturn;
					if(mycallback){mycallback;}
					pleasewait1(false);
					refresh_pending();
				}else{
					pleasewait1(false);
					pcdiv.innerHTML="<p>FORM ERROR</p>".phpreturn;
				}
			}else{
				pleasewait1(false);
				pcdiv.innerHTML="Ajax Error - Multi Post - Status Code:"+ajaxd.status;
			}
		}
	}
	var postdata="";
	for(z=0;z<document.forms.length;z++){
		if(document.forms[z].name.slice(0,frm.length)==frm){
			postdata+=getformdata1(document.forms[z]);
		}
	}
	ajaxd.open("POST","../ajax/"+ajaxfile,true); 
	ajaxd.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	ajaxd.send(postdata);
	if(divtxt){pcdiv.innerHTML=divtxt;}
	return false;	
	
}
function generic_post_single_form(frm,ajaxfile,returndiv,validate,mycallback){
	//alert(document.forms[frm].name);
	if(validate){if(!validate_form(document.forms[frm].name,validate)){return false};}
	if(returndiv){
		var pcdiv=document.getElementById(returndiv);
	}else{pcdiv=false;}
	var ajaxd=ajaxFunction();
	if(!ajaxd){return false;}
	ajaxd.onreadystatechange = function(){
		if(ajaxd.readyState == 4){
				var phpreturn=ajaxd.responseText;
			if (ajaxd.status == 200) {
				if(phpreturn!=""){
					if(pcdiv){pcdiv.innerHTML=phpreturn;}
					if(mycallback=="phpreturn"){mycallback=phpreturn;}
					if(mycallback){eval(mycallback);}
					refresh_pending();
					pleasewait1(false);
				}else{
					pleasewait1(false);
					if(pcdiv){
					pcdiv.innerHTML="<p>FORM ERROR</p>".phpreturn;
					}else{
						alert("<p>FORM ERROR</p>".phpreturn);
					}
				}
			}else{
				pleasewait1(false);
				if(pcdiv){
				pcdiv.innerHTML="Ajax Error - Single POST - Status Code:"+ajaxd.status;
				}else{
					alert("Ajax Error - Single POST - Status Code:"+ajaxd.status);
				}
			}
		}
	}
	var postdata="";
			postdata+=getformdata(document.forms[frm]);
	ajaxd.open("POST","../ajax/"+ajaxfile,true); 
	ajaxd.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	ajaxd.send(postdata);
	return false;	
	
}
function refresh_pending(alink){	
	if(!document.getElementById('pendr_sub')){return false;}
	if(typeof(alink)=="object"){alink.onclick=null;}
	var img=document.getElementById('img_refresh_pending');
	if(img){img.src="../images/icons/loading_stat_down.gif";}
	var md=new Date;
	generic_get('boards.php?action=pending_mod_update&ts='+md.getTime(),'pendr_sub');
}
function enable_form(frmname){
	var frm=document[frmname];
	if(!frm){return false;}
	var el=frm.elements;
	for(x=0;x<el.length;x++){
		if(el[x].disabled){		
		el[x].disabled=false;
		}
		if(el[x].readOnly){
			el[x].readOnly=false;
		}
	}
}
function disable_form(frmname){
	var frm=document[frmname];
	if(!frm){return false;}
	var el=frm.elements;
	for(x=0;x<el.length;x++){
		switch(el[x].type){
			case "select-one":
			case "submit":
			case "reset":
			case "checkbox":
			case "radio":
				el[x].disabled=true;
				break;
			default:
				el[x].readOnly=true;
		}
	}
}
function toggle_div_from_parent(mparent,divprefix,divcurrent){
	if(typeof(mparent)!="object"){
		mparent=document.getElementById(mparent);
		if(!mparent){return false;}
	}
	for(x=0;x<mparent.childNodes.length;x++){
		ch=mparent.childNodes[x];
		if(ch.id && ch.id.match("^"+divprefix+"")){
			ch.style.display=(ch.id==divprefix+divcurrent?"block":"none");			
		}
	}
}
function process_cal(name,date) {
	thefield="date_"+name;
	var outdate=date.getDate() +"/"+ (date.getMonth()+1) +"/" +date.getYear();
	var rev_outdate=date.getYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
	var ob=document.getElementById(thefield);
	if(ob.nodeName!="SPAN"){
		ob.value=outdate;
	}else{
		ob.innerHTML=outdate;
		ob=document.getElementById(thefield+'_field');
		if(ob){
			ob.value=rev_outdate;
		}
	}
	var thecal="calendar_"+name;
	document[thecal].change('',false);
	
}
function set_radios_for_cals(value,title){
	var obs=document.getElementsByTagName('input');
	for(x=0;x<obs.length;x++){
		if(obs[x].type!="radio"){continue;}
		if(obs[x].id &&obs[x].id.search("_cal")>0){
			obs[x].value=value;
			obs[x].title=title;
			obs[x].checked=true;
		}
	}
}
function process_sched_date(name,date){
	var ob_ok=name+'_cal';
	var ob=document.getElementById(ob_ok);
	var d=new Date();
	ob.value=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
	ob.title=dayname(date.getDay())+" "+date.getDate() +"/"+ (date.getMonth()+1) +"/" +date.getFullYear();
	var ob_img=name+'_cal_img';
	document.getElementById(ob_img).alt=ob.title;
	if(d>date){
		var ob_fail=name+'_default';
		document.getElementById(ob_fail).checked=true;
	}else{
		ob.checked=true;
		// Added for set all to calendar on scedule work
		if(name==""){
			set_radios_for_cals(ob.value,ob.title);
		}
	}
	var thecal="calendar_"+name;
	document[thecal].change('',false);
}
function dayname(d){
	if(d==0){return "Sun";}
	if(d==1){return "Mon";}
	if(d==2){return "Tues";}
	if(d==3){return "Wed";}
	if(d==4){return "Thur";}
	if(d==5){return "Fri";}
	if(d==6){return "Sat";}
}
function compdate(ob1,ob2){
	ob1=document.getElementById(ob1);
	ob2=document.getElementById(ob2);
	if(ob1 && ob2){
		var regx=/-/g;
		var d1=Date.parse(ob1.value.replace(regx,"/"));
		var d2=Date.parse(ob2.value.replace(regx,"/"));
		if(d1>d2){
			alert("Please check your start and end dates");
			return false;
		}
	}
	return true;
}
var disabled_checkbox;
function checkbox_disable_enable(dis){
	if(disabled_checkbox && typeof(disabled_checkbox)=="object"){
		disabled_checkbox.disabled = false;	
	}
	var ob=document.getElementById(dis);
	if(ob){
		ob.disabled=true;
		ob.checked=false;
		disabled_checkbox=ob;
	}
}
