function openwindow(theurl,windowname,features) { window.open(theurl,windowname,features); }

function number_format(a,b,c,d) {
a=Math.round(a*Math.pow(10, b))/Math.pow(10,b);
e=a+'';
f=e.split('.');
if(!f[0]) { f[0]='0'; }
if(!f[1]) { f[1]=''; }
if(f[1].length<b) {
g=f[1];
for(i=f[1].length+1;i<=b;i++) { g+='0'; }
f[1]=g;
}
if (d!='' && f[0].length>3) {
h=f[0];
f[0]='';
for (j=3;j<h.length;j+=3) {
i=h.slice(h.length-j,h.length-j+3);
f[0]=d+i+f[0]+'';
}
j=h.substr(0,(h.length%3==0) ? 3 : (h.length % 3));
f[0]=j+f[0];
}
c=(b <= 0) ? '': c;
return f[0] + c + f[1];
}

function capitalizeit(subject) {
tmp=eval(subject).value;
len=tmp.length;
if (len>0) {
val=eval(subject).value;
val1=val.charAt(0);
val2=val.substr(1,len-1);
CapVal=val1.toUpperCase()+val2;
eval(subject).value=CapVal;
}
}

function convertToEntities(form) {
for (var j=form.elements.length-1;j>=0;--j) {
var tstr=form.elements[j].value;
var bstr='';
for(i=0;i<tstr.length;i++) { if (tstr.charCodeAt(i)>127) { bstr+='&#'+tstr.charCodeAt(i)+';'; } else { bstr+=tstr.charAt(i); } }
form.elements[j].value=bstr;
}
}

function loadselectdescription(id) {
if (id.options[id.selectedIndex].title) {
document.getElementById('selectdescription').style.top=topoffset(id);
document.getElementById('selectdescription').style.left=leftoffset(id)+id.offsetWidth;
document.getElementById('selectdescription').innerHTML=id.options[id.selectedIndex].title+"<p align=center><a href='javascript:closeselectdescription();'>Close</a></p>";
document.getElementById('selectdescription').style.display='';
} else {
closeselectdescription();
}
}

function closeselectdescription() {
if (document.getElementById('selectdescription').style.display=='') { document.getElementById('selectdescription').style.display='none'; }
}

var datetoday=new Date;
var months=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var days=new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var dayofweek=new Array('S','M','T','W','T','F','S');
var currentcalendar; var path;


function loadcalendar(id,loadmonth,loadyear) {
if (currentcalendar) { closecalendar(); } else { creatediv('calendar'); }
currentcalendar=id;
hideselects();
if (document.getElementById(currentcalendar+"_month").value>0) { loadmonth=document.getElementById(currentcalendar+"_month").value; } else if (loadmonth==undefined) { loadmonth=datetoday.getMonth()+1; }
if (document.getElementById(currentcalendar+"_year").value>0) { loadyear=document.getElementById(currentcalendar+"_year").value; } else if (loadyear==undefined) { loadyear=datetoday.getFullYear(); }
button=document.getElementById(currentcalendar+"_btn");
button.src='/images/btn_date_down.gif';
var calendarpopup=document.getElementById("calendar");
calendarpopup.style.zIndex=101;
calendarpopup.style.position='absolute';
calendarpopup.style.background='#FFFFFF';
calendarpopup.innerHTML=makeCalendar(loadmonth,loadyear);
calendarpopup.style.top=topoffset(button)+21+'px';
calendarpopup.style.left=leftoffset(button)+'px';
calendarpopup.style.display='';
}


function setdate(day,month,year) {
document.getElementById(currentcalendar+"_day").value=day;
document.getElementById(currentcalendar+"_month").value=month+1;
document.getElementById(currentcalendar+"_year").value=year;
closecalendar();
}


function closecalendar() {
showselects();
document.getElementById(currentcalendar+"_btn").src='/images/btn_date_up.gif';
document.getElementById("calendar").style.display='none';
currentcalendar=false;
}

function topoffset(obj) {
var top=obj.offsetTop;
var parent=obj.offsetParent;
while (parent!=document.body) { top+=parent.offsetTop; parent=parent.offsetParent; }
return top;
}
     
function leftoffset(obj) {
var left=obj.offsetLeft;
var parent=obj.offsetParent;
while (parent!=document.body) { left+=parent.offsetLeft; parent=parent.offsetParent; }
return left;
}

function makeCalendar(thismonth,thisyear) {
thismonth=thismonth-1;
html='<table width=180 cellspacing=1 cellpadding=0 bgcolor=#999999><tr bgcolor=#CCCCCC>';
html+='<td colspan=7 align=center width=100% style="padding:1px">&nbsp;&nbsp;<a style="cursor:pointer" onclick="javascript:changemonth(\''+thismonth+'\',\''+thisyear+'\');">&lt;&lt;</a>&nbsp;<select id="newmonth" class="selectbox" onChange="changemonth(this.options[this.selectedIndex].value,\''+thisyear+'\');">';
for (i=0;i<12;i++) { if (i==thismonth) { html+='<option value="'+(i+1)+'" selected>'+months[i]+'<\/option>'; } else { html+='<option value="'+(i+1)+'">'+months[i]+'<\/option>'; } }
html+='<\/select><select id="newyear" class="selectbox" onChange="changemonth(\''+(thismonth+1)+'\',this.options[this.selectedIndex].value);">';
for (i=datetoday.getFullYear()-100;i<datetoday.getFullYear()+15;i++) { if (i==thisyear) { html+='<option value="'+i+'" selected>'+i+'<\/option>'; } else { html+='<option value="'+i+'">'+i+'<\/option>'; } }
html+='<\/select>&nbsp;<a style="cursor:pointer" onclick="javascript:changemonth(\''+(thismonth+2)+'\',\''+thisyear+'\');">&gt;&gt;</a>&nbsp;&nbsp;<a href="javascript:closecalendar();"><img src="/images/btn_close_small.gif" border="0" width="12" height="10"></a><\/td><\/tr>';
firstDay=new Date(thisyear,thismonth,1);
startDay=firstDay.getDay();
if (((thisyear%4==0) && (thisyear%100!=0)) || (thisyear%400==0)) { days[1]=29; } else { days[1]=28; }
html+='<tr bgcolor=#CCCCCC>';
for (i=0;i<7;i++) { html+='<td class=headercell width=14% align=center>'+dayofweek[i]+'<\/td>'; }
html+='<\/tr><tr bgcolor=#FFFFFF>';
var intColumn=0;
var lastmonth=thismonth-1;
var lastyear=thisyear;
if (lastmonth==-1) { lastmonth=11; lastyear=lastyear-1;}
for (i=0;i<startDay;i++,intColumn++) { html+='<td height=22>&nbsp;<\/td>'; }
for (i=1;i<=days[thismonth];i++,intColumn++) { html+='<td class=maincell onmouseover="this.className=\'maincellover\'" onmouseout="this.className=\'maincell\'">' + '<a style="padding:4px;line-height:22px" onclick="javascript:setdate('+i+','+thismonth+','+thisyear+');">'+i+'<\/a>'+'<\/td>'; if (intColumn==6) { html+='<\/tr><tr bgcolor=#FFFFFF>'; intColumn=-1; } }
if (intColumn>0) { for (intColumn;intColumn<7;intColumn++) { html+="<td>&nbsp;</td>"; } } else { html=html.substr(0,html.length-20); }
return html;
}	

function changemonth(newmonth,newyear) {
if (newmonth>12) { newyear++; newmonth=1; }
if (newmonth<1) { newyear--; newmonth=12; }
document.getElementById("calendar").innerHTML=makeCalendar(newmonth,newyear);
}

function creatediv(id) { 
var newdiv=document.createElement('div');
newdiv.setAttribute('id', id);
newdiv.style.display='none';
document.body.appendChild(newdiv);
}

function hideselects() {
	if (typeof document.body.style.maxHeight=='undefined') {
		var elements=document.getElementsByTagName('select');
		for (i=0;i<elements.length;i++) { elements[i].style.visibility='hidden'; }
	}
}

function showselects(){
	if (typeof document.body.style.maxHeight=='undefined') {
		var elements=document.getElementsByTagName('select');
		for (i=0;i<elements.length;i++) { elements[i].style.visibility='visible'; }
	}
}