//######################################################################################

//#

//# GENERAL JS FUNCTIONS - Xavier Spriet <xavier@eliquid.com>

//# Copyright (c) Xavier Spriet <xavier@eliquid.com>

//#

//######################################################################################


// Mouseovers

<!--

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_findObj(n, d) { //v4.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && document.getElementById) x=document.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

//-->

// Open Window

<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->


// Tracks all opened pop-up windows

var popup_id = 0;



// Keeps track of locked input fields to make CSS play nicely

var fields = new Array();



// Opens the formatted help window

function showXHelp(title, message) {

	xWin = window.open("", "Xhelp" + popup_id, 'width=200,height=200,toolbar=no,menubar=no,directories=no,resizable=yes,status=no,scrollbars=yes');

	xWin.document.write("<link href='style.css' rel='stylesheet' type='text/css'>");

	xWin.document.write("<table bgcolor='#eeeeee' border='0' align='center' width='100%' style='border: solid 1px'><tr>" +

	"<td align='center' bgcolor='#cccccc' background='images/borderup.jpg'><b>Help: "+unescape(title)+"</b></td></tr><tr><td align='left'>");

	xWin.document.write("<div style='padding:0.6em;'>");

	xWin.document.write(unescape(message));

	xWin.document.write("</div></tr><tr><td align='center' background='images/borderdown.jpg' style='border-top: 1px solid'><a href='javascript:self.close()'>Close Help</a></td></tr></table>");

	xWin.document.bgColor="#ffffff";

	xWin.document.close();

	popup_id++;

}



// Wrapper for showXhelp

// Deprecated?!?

function showHelp(title, message) {

	showXHelp(title, message);

}



// Displays the help icon as a link to launch showHelp

function showHelpIcon(title, message) {

	document.writeln("<a href=\"#\"><img valign=\"bottom\" style=\"cursor:help;\" src=\"images/icon-note.gif\" onMouseOver=\"src=\'images/icon-note-on.gif\';\" onMouseOut=\"src=\'images/icon-note.gif\';\" title=\""+message+"\" onClick=\"showXHelp(\'"+escape(title)+"\', \'"+escape(message)+"\');\" border=\"0\"></a>");

}



// Uses URL encoding to make sure the icon will display within a javascript context



// Is this deprecated? I don't remember where I used this.

function showHelpIcon2(title, message) {

	return("<a style=cursor:pointer;cursor:hand;><img valign=\"middle\" src=\"images/help.gif\" title=\""+message+"\" onClick=\"showXHelp(\'"+escape(title)+"\', \'"+escape(message)+"\');\" border=\"0\"></a>");

}



// Advanced pop-up script that can detect if pop-up blocking is enabled.

// It is also known to work well on dual-head systems

function popup(uri, width, height, id) {

	x = (window.screen.availWidth - width)/4;

	y = (window.screen.availHeight - height)/2;

	popup_window = window.open(uri, 'eli'+id+popup_id, 'width='+width+',height='+height+',toolbar=no,menubar=no,directories=no,resizable=yes,status=no,scrollbars=yes,left='+x+',top='+y+',screenX='+x+',screenY='+y);

	if (!popup_window) {

		alert("Pop-up Windows must be allowed in order to perform this action. Please turn off pop-up blocking in your web-browser.");

	} else {

		popup_id += 1;

	}

}



//######################################################################################

//#

//# USER SELECTION FUNCTIONS - Xavier Spriet <xavier@eliquid.com>

//#

//######################################################################################



var ie4 = false; if(document.all) { ie4 = true; }

function getObject(id) { if (ie4) { return document.all[id]; } else { return document.getElementById(id); } }





// Return true if the second parameter is part of the array in parameter 1

function in_array(array, val) {

	var i;

	for (i = 0; i < array.length; i++) {

		if (array[i] == val) {

			return true;

		}

	}

	return false;

}



// Deletes the array element in argument 1 that has the value passed in argument 2

function array_del(array, val) {

	var i;

	for (i = 0; i < array.length; i++) {

		if (array[i] == val) {

			array[i] = '';

		}

	}

}



// Pushes the value of argument 2 in array in argument 1

function array_push(array, val) {

	array[array.length] = val;

}



// Returns the human-readable representation of an array's content

function dump(array) {

	var temp = '';

	var i;

	

	for (i = 0; i < array.length; i++) {

		temp += i + " => " + array[i] + "\n";

	}

	

	return temp;

}



// Returns the last element of the array that has a value, then deletes it.

function array_pop(array) {

	var i;

	for (i = array.length; i > 0; i--) {

		if (array[i] != '') {

			var temp = array[i];

			array[i] = '';

			return temp;

		}

	}

}



// Expand/Collapse the DIV layer passed as argument

function toggle(divId) { 

	var d = getObject(divId);

	if (in_array(expanded, divId)) {

		// collapsing

		d.style.display = 'none';

		array_del(expanded, divId);

		

	} else {

		// expanding

		d.style.display = 'block';

		array_push(expanded, divId);	

	}

	//var tf = getObject('txt');

	//tf.value = dump(expanded);

}



// Returns True if a field is in locked state, false otherwise

function is_locked(field) {

	return in_array(fields, field);

}



// Sets a field in lock state.

// This prevents onMouseOut to override onFocus and onBlur

function lock_field(field) {

	array_push(fields, field);

}



// Unlocks a field (use this on onBlur)

function unlock_field(field) {

	array_del(fields, field);

}





function isValidEmail(str) {

	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;

	return(email.test(str));

}



//######################################################################################

//#

//# Calendar Date-picker code - Xavier Spriet <xavier@eliquid.com>

//#

//######################################################################################



// This calendar is a customized version of the AK_Datepicker from AK WebTools

// All the changes were performed by Xavier Spriet <xavier@eliquid.com>



//AK DatePicker License (based on BSD license)

//Copyright (c) 2004, akwebtools.com

//All rights reserved.

                                                                                                                                          

//Redistribution and use in source and binary forms, with or without modification, are permitted

//provided that the following conditions are met:

                                                                                                                                          

//1. Redistributions of source code must retain the above copyright notice, this list of

//conditions and the following disclaimer.

                                                                                                                                          

//2. Redistributions in binary form must reproduce the above copyright notice, this list

//of conditions and the following disclaimer in the documentation and/or other materials

//provided with the distribution.

                                                                                                                                          

//3. Neither the name of the akwebtools.com nor the names of its contributors may be used

//to endorse or promote products derived from this software without specific prior written

//permission.

                                                                                                                                          

                                                                                                                                          

//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS

//OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY

//AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR

//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

//DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF

//USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN

//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



		var directory = "";

		var today = new Date();

		var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

		var hiddenArray = new Array(35);

		

		var currentyear = today.getYear();

		var currentmonth = today.getMonth();

		var currenttime = today.getHours() + ":" + today.getMinutes( ) + ":" + today.getSeconds();

		if (currentyear < 1000) {currentyear += 1900;} 

		var dp_dir = "";

		var newWin_doc = null;

		var newWin = null;

		var txtboxObj = null;

		

		function formatdate(dd,mm,yy){

			var strf = newWin_doc.getElementById('dateformat').value;

			var chr = '/';

			var dstr = "";

			if (strf.charAt(3)== '1') {chr = '-';}

			else if (strf.charAt(3)== '3') {chr = '.';}

			

			for (var a=0; a<3; a++){

				if (strf.charAt(a)== 'd') {dstr += dd;}

				else if (strf.charAt(a)== 'm') {dstr += mm;}

				else if (strf.charAt(a)== 'y') {dstr += yy;}

				

				if (a < 2) {dstr += chr;}

			}	

			if (newWin_doc.getElementById('including').checked) {

				dstr += " " + newWin_doc.getElementById('time').value;

			}		

			return dstr;

		}

	

		function returndate(indx){

	   		if(hiddenArray[indx] > 0) {

				if (txtboxObj) {

					document.getElementById(txtboxObj).value = formatdate(hiddenArray[indx],newWin_doc.getElementById('months').options.selectedIndex+1,parseInt(newWin_doc.getElementById('years').value));

				}

				newWin.close();

			}

	   		

		}

		function updateoutput() {

			var ml = newWin_doc.getElementById('months').options.selectedIndex;

			var sday = new Date(parseInt(newWin_doc.getElementById('years').value),ml,01)

			var startindex = sday.getDay();

			var numberOfDays = monthLength[ml];

			if (startindex==0) {startindex = 7;}

			

			if (ml==1 && (parseInt(newWin_doc.getElementById('years').value)%4) == 0){numberOfDays = 29;}

			

			for (var n=0; n<35; n++) {

				var str = "c"+n;

				newWin_doc.getElementById(str).src =dp_dir + "0.gif";

				hiddenArray[n] = 0;

			}

			

			for (var m=0; m<numberOfDays; m++)

			{

				var str = "c"+((startindex+m-1)%35);

				newWin_doc.getElementById(str).src =dp_dir + (m+1) + ".gif";

				hiddenArray[((startindex+m-1)%35)] = (m+1);

			}

		}

		

		function updateyears()

		{

			var tempyear = newWin_doc.getElementById('years').value;

			var styear = tempyear - 10;

			for (var i=0; i <= 20; i++) {

				var s = "yopt"+i;

				newWin_doc.getElementById(s).text = (styear+i);

				newWin_doc.getElementById(s).value = (styear+i);

			}

			for (var i = 0; i < newWin_doc.getElementById('years').options.length; i++ )

			{

				if (newWin_doc.getElementById('years').options[i].value == ""+tempyear)

				{

			  		newWin_doc.getElementById('years').options.selectedIndex = i;

					break;

				}

			}

		}	



		

function show_calendar(textfieldname, dir) {

	if (dir) {dp_dir = dir;}

	newWin = window.open("", "Calendar", "width=218,height=208,status=no,resizable=no, scrollbars=no,top=200,left=300");

	newWin.opener = self;

	newWin_doc = newWin.document;

	txtboxObj = textfieldname;

	

	

	newWin_doc.writeln('<html><head><title>DatePicker</title></head>');

	newWin_doc.writeln('<body  style="margin: 2px;" scroll=no  onBlur="self.focus()">');

	newWin_doc.writeln('<div align=\"center\"><table bgcolor="#003399" width="200" cellpadding="0" cellspacing="0"><tr><td align="center" height="35">');

	newWin_doc.writeln('<select id="months" onchange="window.opener.updateoutput();">');

	newWin_doc.writeln('<option value="1">Jan</option>');

	newWin_doc.writeln('<option value="2">Feb</option>');

	newWin_doc.writeln('<option value="3">Mar</option>');

	newWin_doc.writeln('<option value="4">Apr</option>');

	newWin_doc.writeln('<option value="5">May</option>');

	newWin_doc.writeln('<option value="6">Jun</option>');

	newWin_doc.writeln('<option value="7">Jul</option>');

	newWin_doc.writeln('<option value="8">Aug</option>');

	newWin_doc.writeln('<option value="9">Sep</option>');

	newWin_doc.writeln('<option value="10">Oct</option>');

	newWin_doc.writeln('<option value="11">Nov</option>');

	newWin_doc.writeln('<option value="12">Dec</option>');

	newWin_doc.writeln('</select>&nbsp;');

	

	newWin_doc.getElementById('months').options.selectedIndex = parseInt(currentmonth);

	

	newWin_doc.writeln('<select id="years" onchange="window.opener.updateoutput();window.opener.updateyears();">');

	var styear = currentyear - 10;

	for (var i=0; i <= 20; i++) {

		newWin_doc.write("<option id=\"yopt"+ i +"\" value=\""+ (styear+i) +"\">" + (styear+i) +"</option>\n");

	}

	newWin_doc.writeln('</select>&nbsp;');

	

	for (var i = 0; i < newWin_doc.getElementById('years').options.length; i++ )

	{

		if (newWin_doc.getElementById('years').options[i].value == ""+currentyear)

		{

	  		newWin_doc.getElementById('years').options.selectedIndex = i;

			break;

		}

	}



	newWin_doc.writeln('<div style="display: none"><select id="dateformat" class="choice">');

	newWin_doc.writeln('<option value="mdy1">m-d-y</option>');

	newWin_doc.writeln('<option selected value="mdy2">m/d/y</option>');

	newWin_doc.writeln('<option value="mdy3">m.d.y</option>');

	newWin_doc.writeln('<option value="dmy1">d-m-y</option>');

	newWin_doc.writeln('<option value="dmy2">d/m/y</option>');

	newWin_doc.writeln('<option value="dmy3">d.m.y</option>');

	newWin_doc.writeln('<option value="ymd1">y-m-d</option>');

	newWin_doc.writeln('<option value="ymd2">y/m/d</option>');

	newWin_doc.writeln('<option value="ymd3">y.m.d</option>');

	newWin_doc.writeln('</select></div>');

	newWin_doc.writeln('</td></tr>');

	newWin_doc.writeln('<tr><td>');

	

	newWin_doc.writeln('<TABLE width="100%" cellpadding="1px" cellspacing="1px">');

	newWin_doc.writeln('<TBODY>');

	newWin_doc.writeln('<TR>');

	newWin_doc.writeln('<TD align="center" width="25" bgcolor="#52d9f5"><img src="'+ dp_dir + 'd_mon.gif" width="25" height="20" alt="" border="0"></TD>');

	newWin_doc.writeln('<TD align="center" width="25" bgcolor="#52d9f5"><img src="'+ dp_dir + 'd_tue.gif" width="25" height="20" alt="" border="0"></TD>');

	newWin_doc.writeln('<TD align="center" width="25" bgcolor="#52d9f5"><img src="'+ dp_dir + 'd_wed.gif" width="25" height="20" alt="" border="0"></TD>');

	newWin_doc.writeln('<TD align="center" width="25" bgcolor="#52d9f5"><img src="'+ dp_dir + 'd_thu.gif" width="25" height="20" alt="" border="0"></TD>');

	newWin_doc.writeln('<TD align="center" width="25" bgcolor="#52d9f5"><img src="'+ dp_dir + 'd_fri.gif" width="25" height="20" alt="" border="0"></TD>');

	newWin_doc.writeln('<TD align="center" width="25" bgcolor="#52d9f5"><img src="'+ dp_dir + 'd_sat.gif" width="25" height="20" alt="" border="0"></TD>');

	newWin_doc.writeln('<TD align="center" width="25" bgcolor="#52d9f5"><img src="'+ dp_dir + 'd_sun.gif" width="25" height="20" alt="" border="0"></TD>');

	newWin_doc.writeln('</TR>');

	newWin_doc.writeln("<tr>");

	for (var j=1;j<=35;j++){

		if (j==6 || j==7 || j==13 || j==14 || j==20 || j==21 || j==27 || j==28 || j==34 || j==35) {

			newWin_doc.writeln("<td align=\"center\" valign=\"middle\" width=\"25px\" bgcolor='#c6eafd' onmouseover=\"this.bgColor='#b79eeb';\" onmouseout=\"this.bgColor='#c6eafd'\"><a href=\"#\"><img id=\"c"+(j-1)+"\" src=\""+ dp_dir + "0.gif\" onclick=\"window.opener.returndate("+(j-1)+");\" border=\"0\"></a></td>");

		} else {

			newWin_doc.writeln("<td align=\"center\" valign=\"middle\" width=\"25px\" bgcolor='#ffffff' onmouseover=\"this.bgColor='#b79eeb';\" onmouseout=\"this.bgColor='#ffffff'\"><a href=\"#\"><img id=\"c"+(j-1)+"\" src=\""+ dp_dir + "0.gif\" onclick=\"window.opener.returndate("+(j-1)+");\" border=\"0\"></a></td>");

		}

		if ((j % 7) == 0) {newWin_doc.writeln("</tr>");}

	}

	newWin_doc.writeln("</tr>");

		

//			newWin_doc.writeln("<tr>");

//			newWin_doc.writeln("<td colspan=\"7\" align=\"center\" valign=\"top\"><font face=\"Arial\" size=\"-1\" color=\"#ffffff\"><strong>Time:</strong> <input type=\"Text\" id=\"time\" value=\""+ currenttime +"\" size=\"6\">");

	newWin_doc.writeln("<div style=\"display: none\"><input type=\"Checkbox\" id=\"including\" value=\"yes\"></div></td>");			

//			newWin_doc.writeln("</tr>");			

	newWin_doc.writeln('</TBODY></TABLE>');

	

	newWin_doc.writeln('</td></tr></table></div>');

	

	updateoutput();

	newWin_doc.writeln('</body></html>');

	

	

	if(navigator.appName != "Microsoft Internet Explorer")

  	{

		newWin_doc.close();

  	}

}







