/* ================================================ */
/*                                                  */
/*            Regus Business Centers JS             */
/*             Version 0.1 -- 12.2004               */
/*                                                  */
/* ================================================ */

//wwww
function fnWindowOpen(url, name, options){
	if(!options) options="resizable=1,scrollbars=1";
	newWindow = window.open(url, name, options);
	newWindow.focus();
}



// Browser sniff
function BrowserCheck()
{
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b;
	var c = navigator.appVersion;
	this.AOL = (c.indexOf('AOL')>0);
	this.v = parseInt(c);
	this.ns = (this.b=="ns" && this.v>=4);
	this.ns5 = (this.b=="ns" && this.v==5);
	this.ns6 = (this.b=="ns" && this.v==5);
	this.ie = (this.b=="ie" && this.v>=4);
	this.ie5b = (navigator.userAgent.indexOf('MSIE 5.5')>0);
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0);
	this.gecko = (navigator.userAgent.indexOf('Gecko') > 0);
	if (this.ie5) this.v = 5;
	if (this.ie6) this.v = 6;
}

// automatically create the "is" object
is = new BrowserCheck();

/* toggle an elements display attribute, assumes element is off by default */

function toggleDisplay (v) {
	var element = (typeof v == "string") ? document.getElementById(v) : v;
	menuToClear = v;
	if (element.style.display == 'block') {
		element.style.display = 'none';
	} else {
		element.style.display = 'block';
	}
	
}

// us home page javascript

// swap the ole search boxes on the ole us home page

var lastSearch = 'officesSearch';
var lastSearchLink = 'officesLink';

function swapSearch (id, link) {

	var toShow = document.getElementById(id);
	if (toShow.style.display != 'block') {
		document.getElementById(lastSearch).style.display = 'none';
		lastSearch = id;
		
		document.getElementById(lastSearchLink).className = '';
		lastSearchLink = link;
		
		toShow.style.display = 'block';
		document.getElementById(link).className = 'active';
	} 
	
}

function getSelectedSearchTab()
{
	var tabs = new Array('officesSearch','meetingRoomsSearch','virtualOfficesSearch');
	for(var c=0;c<tabs.length;c++){if( document.getElementById(tabs[c]).style.display==('block'))return tabs[c];}
	return '';
}

// Clone of above function for proximity search

var pLastSearch = 'quickFindSearch';
var pLastSearchLink = 'quickFindLink';

function pSwapSearch (id, link) {

	var toShow = document.getElementById(id);
	if (toShow.style.display != 'block') {
		document.getElementById(pLastSearch).style.display = 'none';
		pLastSearch = id;
		
		document.getElementById(pLastSearchLink).className = '';
		pLastSearchLink = link;
		
		toShow.style.display = 'block';
		document.getElementById(link).className = 'active';
	} 
	
}

function pGetSelectedSearchTab()
{
	var tabs = new Array('quickFindSearch','addressSearch','POISearch','centerSearch');
	for(var c=0;c<tabs.length;c++){if( document.getElementById(tabs[c]).style.display==('block'))return tabs[c];}
	return '';
}


// swap the ole grid photos on yon right side

var lastParent = 'oList';
var lastGridImage = 'offices';

function swapgrid (id, parent) {
	document.getElementById(lastParent).className = 'productList';
	lastParent = parent;
	document.getElementById(parent).className = 'productList activeList';
	document.getElementById(lastGridImage + '2x4grid').style.display = 'none';
	lastGridImage = id;
	document.getElementById(id + '2x4grid').style.display = 'block';
}

/* forms */

// enable/disable controls in the same ASP.NET container.
function enableDisableSiblings(source,siblingIds,enable)
{
	var prefix=source.id.substr(0,source.id.lastIndexOf('_')+1);
	var ids=siblingIds.split('|');
	for(var c=0;c<ids.length;c++) document.getElementById(prefix+ids[c]).disabled=(!enable);
}


/* sml addition: 
	without replacing or adding a function, 
	allow function to accept objects in addition to objects' id
	v:variant - argument with unknown type
*/
function getAbsoluteLeft(v) {
	var o = (typeof v == "string") ? document.getElementById(v) : v;
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	oLeft = o.offsetLeft            // Get left position from the parent object
	//alert(o.id+": "+oLeft);
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		//alert(oParent + ": "+oParent.offsetLeft);
		o = oParent;
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(v) {
	var o = (typeof v == "string") ? document.getElementById(v) : v;
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	oTop = o.offsetTop; 			// Get left position from the parent object
	//alert(o.id+": "+oTop);
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oTop += oParent.offsetTop 	// Add parent left position
		//alert(oParent + ": "+oParent.offsetTop);
		o = oParent;
	}
	// Return top postion
	return oTop;
}



/* widgets on location details page */
function switchWidget(id) {
	document.getElementById('photoGal').className = "";
	document.getElementById('virtualTour').className = "";
	document.getElementById('floorPlan').className = "";
	
	document.getElementById(id).className = "active";
}

/* tab info area on details page */
function switchTab(id) {
	// display only current info box
	var tabs = new Array('about','pricing','maps','amenities','nearby');
	
	for(i=0;i<tabs.length;i++) {
		document.getElementById(tabs[i]).style.display = "none";
	}
	document.getElementById(id).style.display = "block";
	
	// set current tab to active, set the next one (if exists) to pastActive,
	// set last one to last
	
	// remove all classes
	for(i=0;i<tabsCollection.length;i++) {
		document.getElementById(tabsCollection[i]).className = "";
		
	}
	
	// set which one is active
	for(i=0;i<tabs.length;i++) {
		if(tabs[i] == id) {
			document.getElementById(tabsCollection[i]).className = "active";
		}
	}
	// find out what the next one is, if any (grumble grumble no array.indexOf support)
	var activeIndex=-1;
	for(i=0;i<tabs.length;i++) {
		if(tabs[i] == id) {
			activeIndex = i;
		}
	}
	// set pastActive
	if((activeIndex != -1) && (activeIndex != tabs.length-1)) {
		document.getElementById(tabsCollection[activeIndex+1]).className = "pastActive";
	}
	// and set last
	var j;
	for(i=0;i<tabsCollection.length;i++) {
		if (document.getElementById(tabsCollection[i]).style.display != "none")
		{
			j = i;
		}	
	}
	document.getElementById(tabsCollection[j]).className += " last";
}

/* switching package area colors (confirmation_step1.htm) */

function switchPackage(side) {
	if(side=="left") {
		document.getElementById('tr').className="";
		document.getElementById('br').className="";
		document.getElementById('tl').className="active";
		document.getElementById('bl').className="active";
	}
	if(side=="right") {
		document.getElementById('tr').className="active";
		document.getElementById('br').className="active";
		document.getElementById('tl').className="";
		document.getElementById('bl').className="";
	}
}


function switchCard(which) {
	if(which=="left") {
		document.getElementById('tr').className="";
		document.getElementById('br').className="";
		document.getElementById('tc').className="";
		document.getElementById('bc').className="";
		document.getElementById('tl').className="active";
		document.getElementById('bl').className="active";
	}
	if(which=="right") {
		document.getElementById('tr').className="active";
		document.getElementById('br').className="active";
		document.getElementById('tl').className="";
		document.getElementById('bl').className="";
		document.getElementById('tc').className="";
		document.getElementById('bc').className="";
	}
	if(which=="center") {
		document.getElementById('tr').className="";
		document.getElementById('br').className="";
		document.getElementById('tl').className="";
		document.getElementById('bl').className="";
		document.getElementById('tc').className="active";
		document.getElementById('bc').className="active";
	}
}


// =====================================================================
/* sml 2004.12.10 */
// static animation easing helper
function sml_easing_Regular_easeOut(t,b,c,d)
{ 
	return -c *(t/=d)*(t-2) + b; 
}
// dom helpers


// z sorting
function sml_domApi_initDepths()
{
	sml.domApi.__z = 1000;
}
function sml_domApi_getNextHighestDepth()
{
	return ++sml.domApi.__z;
}
function sml_domApi_moveToHighest(v)
{
	var o = (typeof(v)== "string") ? document.getElementById(v) : v;
	if (document.body.style)
		o.style.zIndex = sml.domApi.getNextHighestDepth();
}
var sml = {};
sml.easing = {};
sml.easing.Regular = {};
sml.easing.Regular.easeOut = sml_easing_Regular_easeOut;
sml.domApi = {};

sml.domApi.__z=0;
sml.domApi.__depthInited=false;
sml.domApi.initDepths          = sml_domApi_initDepths;
sml.domApi.getNextHighestDepth = sml_domApi_getNextHighestDepth;
sml.domApi.moveToHighest       = sml_domApi_moveToHighest;

// =====================================================================
// Recent Location: RecentLoc
// =====================================================================



function RecentLoc(o) //dropDown, toggleLink, id
{
	this.dropDownId   = o.dropDownId;
	this.toggleLinkId = o.toggleLinkId;
	
	
	this.id    = o.id; // unique id by collection
	
	this.borderStyle = "";
	this.state = RecentLoc.STATE_OFF;
	this.tween = {interval:null, t:0, b:null, c:null, d:20};
	
	this.dropDown = null;
	this.toggleLink = null;
	
	this.boxHeight = null;
	this.boxPos = {x0:null, y0:null, x1:null, y1:null};
	this.affectedSelectBoxArray = null;
}
// static func

function RecentLoc_toggleLinkHandler()
{
	var rlc = RecentLocCollection.instance;
	var i = rlc.rl_arr.length;
	while (i--)
	{
		if (this==rlc.rl_arr[i].toggleLink)
		{
			rlc.rl_arr[i].toggleDropDown();
			RecentLocCollection.activeRL = rlc.rl_arr[i];
			break;
		}
	}
	return false;
}
function RecentLoc_animateActiveRL()
{
	var activeRL = RecentLocCollection.activeRL;
	var dd = activeRL.dropDown;
	
	with (activeRL.tween)
	{
		dd.style.height = Math.floor(sml.easing.Regular.easeOut(t, b, c, d))+"px";
		if (t==0) 
		{
			clearInterval(activeRL.tween.interval);
			activeRL.tween.interval = setInterval(RecentLoc.animateActiveRL, 20);
		}
		else if (t==d)
		{
			clearInterval(activeRL.tween.interval);
			
			activeRL.state = (activeRL.state == RecentLoc.STATE_TO_ON) ? RecentLoc.STATE_ON : RecentLoc.STATE_OFF;
			// make sure that the border doesn't stay on when set to off state
			if (activeRL.state == RecentLoc.STATE_ON)
			{
				dd.style.visibility =  "visible";
			}
			else
			{
				if (activeRL.affectedSelectBoxArray)
					for (var i=0; i<activeRL.affectedSelectBoxArray.length; i++)
						activeRL.affectedSelectBoxArray[i].style.visibility = "visible";
				dd.style.visibility =  "hidden";
				RecentLocCollection.activeRL = null;
			}
		}
		t++;
	}
};
RecentLoc.mouseoutTO = 0;
// PAGE UI AFTER INTERACTION
function RecentLoc_mouseOutHandler(e)
{
	if (RecentLocCollection.activeRL)
		RecentLoc.mouseoutTO = setTimeout(RecentLoc.mouseOutLimiter, 500);
}
function RecentLoc_mouseOutLimiter()
{
	if (RecentLocCollection.activeRL)
		RecentLocCollection.activeRL.toggleDropDown();
}
function RecentLoc_mouseOverHandler(e)
{
	if (RecentLocCollection.activeRL)
		clearTimeout(RecentLoc.mouseoutTO);;
}
// method
function RecentLoc_p_init()
{


	var dropDown   = document.getElementById(this.dropDownId);
	var toggleLink = document.getElementById(this.toggleLinkId);
	
	//validate
	if (dropDown && toggleLink)
	{
		this.dropDown = dropDown;
		this.toggleLink = toggleLink;
		this.toggleLink.onclick = RecentLoc.toggleLinkHandler;
		return true;
	}
	return false;	
}

function RecentLoc_p_animate()
{
	if (RecentLocCollection.activeRL != null && RecentLocCollection.activeRL != this)
		RecentLocCollection.activeRL.stopAnimate();
	RecentLocCollection.activeRL = this;
	RecentLoc.animateActiveRL();
}
function RecentLoc_p_stopAnimate()
{
	clearInterval(this.tween.interval);
	this.state = RecentLoc.STATE_OFF;
	if (this.affectedSelectBoxArray)
		for (var i=0; i<this.affectedSelectBoxArray.length; i++)
			this.affectedSelectBoxArray[i].style.visibility = "visible";
	this.dropDown.style.height = "0px";
	this.dropDown.style.visibility = "hidden";
}
function RecentLoc_p_toggleDropDown()
{
	// if animating, let it get done before toggling
	if (this.state != RecentLoc.STATE_OFF && this.state != RecentLoc.STATE_ON)
		return;
	
	clearTimeout(RecentLoc.mouseoutTO);
	var dd = this.dropDown;
	if (this.boxHeight == null)
	{
		dd.style.visibility = "hidden";
		dd.style.display = "block";
		this.boxHeight = dd.offsetHeight;
		dd.style.height = "0";
	
	}
	
	dd.style.visibility = "visible";
	sml.domApi.moveToHighest(dd);
	
	// create select box array only if necessary
	if (!this.affectedSelectBoxArray)
		this.initAffectedSelectBoxArray();

	if (this.affectedSelectBoxArray)
	{	
		// once we have the value, we can toggle display by changing its height property
		if (this.state == RecentLoc.STATE_TO_ON || this.state == RecentLoc.STATE_OFF)
		{
			this.state = RecentLoc.STATE_TO_ON;
			this.tween = {t:0, b:parseInt(dd.style.height), c:this.boxHeight-parseInt(dd.style.height), d:10};
			for (var i=0; i<this.affectedSelectBoxArray.length; i++)
				this.affectedSelectBoxArray[i].style.visibility = "hidden";
			this.trackMouseOut(true);
		}	
		else
		{
			this.state = RecentLoc.STATE_TO_OFF;
			this.tween = {t:0, b:parseInt(dd.style.height), c:-parseInt(dd.style.height), d:10};
			// select box turn on post animation
			this.trackMouseOut(false);
		}
	}
	this.animate();
	
	
}
function RecentLoc_p_initAffectedSelectBoxArray()
{
	// find the dropDown's position
	var box = this.dropDown;
	var boxPos_y = getAbsoluteTop(box);

	var return_arr = new Array();
	var arr = document.getElementsByTagName("select");

	
	// if the element's coordinates overlap with the box, it's affected
	for (var i=0; i<arr.length; i++)
	{
		var selObj = arr[i];
		var selObj_y = getAbsoluteTop(selObj);
		
		var fail = Math.abs(selObj_y-boxPos_y) < this.boxHeight;
		
		if (fail)
			return_arr.push(arr[i]);
	}
	
	this.affectedSelectBoxArray = return_arr
}
function RecentLoc_p_trackMouseOut(track)
{
	if (RecentLocCollection.activeRL)
	{
		clearTimeout(RecentLoc.mouseoutTO);
		this.dropDown.onmouseout  = track ? RecentLoc.mouseOutHandler  : null;
		this.dropDown.onmouseover = track ? RecentLoc.mouseOverHandler : null;
	}
}

RecentLoc.STATE_OFF = 0;
RecentLoc.STATE_TO_ON = 1;
RecentLoc.STATE_ON = 2;
RecentLoc.STATE_TO_OFF = 3;

RecentLoc.animateActiveRL  = RecentLoc_animateActiveRL;
RecentLoc.mouseOverHandler = RecentLoc_mouseOverHandler;
RecentLoc.mouseOutHandler  = RecentLoc_mouseOutHandler;
RecentLoc.mouseOutLimiter  = RecentLoc_mouseOutLimiter;
RecentLoc.toggleLinkHandler = RecentLoc_toggleLinkHandler;

RecentLoc.prototype.init            = RecentLoc_p_init;
RecentLoc.prototype.animate         = RecentLoc_p_animate;
RecentLoc.prototype.stopAnimate     = RecentLoc_p_stopAnimate;
RecentLoc.prototype.toggleDropDown  = RecentLoc_p_toggleDropDown;
RecentLoc.prototype.trackMouseOut   = RecentLoc_p_trackMouseOut;
RecentLoc.prototype.initAffectedSelectBoxArray = RecentLoc_p_initAffectedSelectBoxArray;


// =====================================================================
// Recent Location : RecentLocCollection
// =====================================================================
function RecentLocCollection()
{
	this.rl_arr = new Array();
	this.className = "RecentLocCollection";
	RecentLocCollection.instance = this;
}
function RecentLocCollection_p_addItem(o)
{
	var rl = new RecentLoc(o);
	if (rl.init())
	{
		this.rl_arr.push(rl);
	}
}

RecentLocCollection.instance = null;
RecentLocCollection.activeRL = null;
RecentLocCollection.prototype.addItem = RecentLocCollection_p_addItem;



// =====================================================================
// Context Help 
// =====================================================================
function ContextHelpItem(o)
{
	this.id      = o.id;      // controlled by ContextHelp
	this.linkId  = o.linkId;  // created on html
	this.blockId = o.blockId; // created on html
	this.closeId = o.closeId; // created on html
	this.oLink  = null;
	this.oBlock = null;
	this.oClose = null;
}
function ContextHelpItem_p_init()
{
	
	if (document.getElementById)
	{
		var oLink  = document.getElementById(this.linkId);
		var oBlock = document.getElementById(this.blockId);
		var oClose = document.getElementById(this.closeId);
	}
	
	if (!(oLink && oBlock && oClose))
 	{
 		return false;
 	}
	
	this.oLink  = oLink;
	this.oBlock = oBlock;
	this.oClose = oClose; 	

 	this.oLink.onclick  = ContextHelp.linkHandler;
	this.oClose.onclick = ContextHelp.closeHandler;
	
 	return true;
 }
function ContextHelpItem_p_activate(x,y)
{
	if (this.oBlock.style)
	{
		this.oBlock.style.display = "block";
		this.oBlock.style.left = x + "px";
		this.oBlock.style.top  = y + "px";
	}
}
function ContextHelpItem_p_deactivate()
{
	this.oBlock.style.display = "none";
}
ContextHelpItem.prototype.init       = ContextHelpItem_p_init;
ContextHelpItem.prototype.activate   = ContextHelpItem_p_activate;
ContextHelpItem.prototype.deactivate = ContextHelpItem_p_deactivate;

function ContextHelp()
{
	this.chiArray   = new Array();
	this.activeItem = undefined;
	ContextHelp.instance = this;
}
ContextHelp.instance = undefined;
function ContextHelp_linkHandler(e)
{
	ContextHelp.instance.onItemLink(this);
	return false;
}
function ContextHelp_closeHandler(e)
{
	ContextHelp.instance.onItemClose(this);
	return false;
}
function ContextHelp_getOffendingContainer()
{
	var divTwoCol = document.getElementById("quickSearchTwoCol");
	var divOneCol = document.getElementById("quickSearchOneCol");
	return (divTwoCol || divOneCol);
}
// prototype
function ContextHelp_p_onItemLink(o)
{
	for (var i=0; i<this.chiArray.length; i++)
	{
		if (this.chiArray[i].oLink==o)
		{
			if (typeof(this.activeItem)!='undefined')
			{
				this.activeItem.deactivate();
			}
			this.activeItem = this.chiArray[i];
			var x = getAbsoluteLeft(o)-2;
			var y = getAbsoluteTop(o) -2;
			
			var offendingDiv = ContextHelp.getOffendingContainer();
			if (offendingDiv)
			{
				x -= getAbsoluteLeft(offendingDiv);
				y -= getAbsoluteTop (offendingDiv);
			}
			this.activeItem.activate(x,y);
		}
	}
}
function ContextHelp_p_onItemClose(o)
{
	for (var i=0; i<this.chiArray.length; i++)
	{
		if (typeof(this.activeItem)!='undefined')
		{
			this.activeItem.deactivate();
			this.activeItem = undefined;
		}

	}
}
function ContextHelp_p_addItem(o)
{
	if (document.getElementById)
	{
		o.id = this.chiArray.length;
		var item = new ContextHelpItem(o);
		if (item.init())
		{
			this.chiArray.push(item);
		}
	}
}


ContextHelp.linkHandler           = ContextHelp_linkHandler;
ContextHelp.closeHandler          = ContextHelp_closeHandler;
ContextHelp.getOffendingContainer = ContextHelp_getOffendingContainer;

ContextHelp.prototype.onItemLink  = ContextHelp_p_onItemLink;
ContextHelp.prototype.onItemClose = ContextHelp_p_onItemClose;
ContextHelp.prototype.addItem     = ContextHelp_p_addItem;

// =====================================================================
// for ie5/pc

if(!Array.prototype.push) 
{
	Array.prototype.push = function()
	{
		for (var i=0; i<arguments.length; i++)
		{
			this[this.length] = arguments[i];
		}
		return this.length;
	}
}

// =====================================================================
// init
// =====================================================================
window.onload = function()
{
	sml.domApi.initDepths();
}


/* jeff stuff */

function setGLTimeout() {
	document.getElementById('globalList').timeout = setTimeout(toggleGL,1000);
}

function killGLTimeout() {
	clearTimeout(document.getElementById('globalList').timeout);
}

function toggleGL() {
	toggleDisplay('globalList');
}

// form validation
function check_required(myForm) {
	var requiredFields = myForm._required.value.split("|");
	var errorString = '';
	for (var i=0; i<requiredFields.length; i++) {
		var parts = requiredFields[i].split(",");
		var field = parts[0]; var title = parts[1];
		for (var j=0; j<myForm.elements.length; j++) {
			var myElement = myForm.elements[j];
			var isNull = false;
			if (myElement.name == field && myElement.style.display != "none") {
				if (myElement.type == "select-one" || myElement.type == "select-multiple") {
					if ((myElement.options[myElement.selectedIndex].value == null || myElement.options[myElement.selectedIndex].value == '') && errorString.indexOf(title) == -1) {
						isNull = true;
					}
				} else if ((myElement.value == null || myElement.value.search(/\w/) == -1) && errorString.indexOf(title) == -1) {
					isNull = true;
				}
				
				if (isNull) {
					errorString += title + ", ";
					if (document.getElementById('label_'+myElement.name)) { document.getElementById('label_'+myElement.name).className="er"; }
					myElement.className="erInput";
				} else {
					if (document.getElementById('label_'+myElement.name)) {
						document.getElementById('label_'+myElement.name).className="";
					}
					myElement.className="";
				}
			}
		}
	}
	if (errorString != '') {
		errorString = errorString.slice(0,errorString.length-2);
		window.alert("Please fill in the following required fields before submitting this form:\n\n"+errorString)
		return false;
	}
	else {
		return true;
	}
}

function submitForm(myForm) {
	if ( !check_required(myForm) ) { return false; }
	if ( !validZip(myForm.zip) ) { return false; }
	if ( !validAreaCode(myForm.area_code) ) { return false; }
	if ( !validPhone(myForm.phone) ) { return false; }
	if (myForm.From.value) {
		if ( !validEmail(myForm.From) ) { return false; }
	}
}

/*
 +-------------------------------------------------------------------+
 |                  J S - C H E C K F O R M   (v1.2)                 |
 |                                                                   |
 | Copyright Gerd Tentler               www.gerd-tentler.de/tools    |
 | Created: Oct. 23, 2001               Last modified: Jan. 24, 2006 |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+

======================================================================================================

 ARGUMENTS:

  - form-name or -number
  - 'field:title:type:minimum length'[, ...]  (type = number / mail / url / date(format) / [none])

 Example:

 checkForm('frm1', 'name:::2', 'age::number:1', 'eMail:e-mail:mail:1', 'homepage::url:0',
           'birthday::date(dmy):1');

------------------------------------------------------------------------------------------------------
 This script was tested with the following systems and browsers:

 - Windows XP: IE 6, NN 7, Opera 7, Firefox 1
 - Mac OS X:   IE 5, Safari 1

 If you use another browser or system, this script may not work for you - sorry.

 NOTE: Safari 1 on Mac OS X does only accept dates between Jan. 1, 1901 and Dec. 31, 2037 as valid.
======================================================================================================
*/
//--------------------------------------------------------------------------------------------------------
// Language settings
//--------------------------------------------------------------------------------------------------------

var msgNumber  = "must be a number";
var msgEMail   = "must be an e-mail address";
var msgURL     = "must be a web address";
var msgDate    = "must be a date";
var msgFillOut = "Please fill out";
var msgNoForm  = "Form does not exist";
var msgNoField = "Field does not exist";

//--------------------------------------------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------------------------------------------

function _trim(str) {
  if(str) {
    str = str.replace(/^\s+/, "");
    str = str.replace(/\s+$/, "");
  }
  return str;
}

function _isDate(year, month, day) {
  month--;
  if(year < 100) year += 2000;
  var d = new Date(year, month, day);
  return ((day == d.getDate()) && (month == d.getMonth()) && (year == d.getFullYear()));
}

function checkForm() {
  var args = checkForm.arguments;
  var f = args[0];
  var msg = "";
  var arr, field, title, type, minLength, elem, val, cnt, i, j;
  var format, d, day, month, year;

  var valid_url = /^(https?|ftp):\/\/([a-z0-9._-]+:[a-z0-9._-]+@)?[a-z0-9äöüÄÖÜ#._\/~% -]+(\?([a-z0-9_-]+(=[a-zA-Z0-99äöüÄÖÜß+%?_-]+&?)?)*)?$/i;
  var valid_mail = /^[a-z0-9._-]+@[a-z0-9äöüÄÖÜ.-]+\.[a-z]{2,4}$/i;

  if(document.forms[f]) {
    for(i = 1; i < args.length; i++) {
      arr = args[i].split(":");
      field = _trim(arr[0]);
      title = _trim(arr[1]);
      if(!title) title = field;
      type = _trim(arr[2].toLowerCase());
      minLength = _trim(arr[3]);
      elem = document.forms[f].elements[field];

      if(elem) {
        val = _trim(elem.value);

        if(val != "") {
          if(type == "number") {
            val = val.replace(",", ".");
            if(isNaN(val)) msg += '"' + title + '" ' + msgNumber + "\n";
          }
          else if(type == "mail" && val.search(valid_mail) == -1) msg += '"' + title + '" ' + msgEMail + "\n";
          else if(type == "url" && val.search(valid_url) == -1) msg += '"' + title + '" ' + msgURL + "\n";
          else if(type.indexOf("date") != -1) {
            if(type.indexOf("(") != -1) format = type.substr(type.indexOf("("));
            else format = "(dmy)";
            d = val;

            for(j = 1; j < format.length - 1; j++) {
              cnt = d.search(/[^0-9]/);
              if(cnt == -1) cnt = d.length;

              switch(format.charAt(j)) {
                case "d": day = parseInt(d.substr(0, cnt)); d = d.substr(cnt + 1); break;
                case "m": month = parseInt(d.substr(0, cnt)); d = d.substr(cnt + 1); break;
                case "y": year = parseInt(d.substr(0, cnt)); d = d.substr(cnt + 1); break;
              }
            }
            if(!_isDate(year, month, day)) msg += '"' + title + '" ' + msgDate + "\n";
          }
        }

        if(minLength) {
          if(elem.length) {
            if(elem.options) {
              for(j = cnt = 0; j < elem.options.length; j++) {
                if(elem.options[j].selected && elem.options[j].value != "") cnt++;
              }
            }
            else for(j = cnt = 0; j < elem.length; j++) {
              if(elem[j].checked) cnt++;
            }
          }
          else if(elem.type == "checkbox") cnt = elem.checked ? 1 : 0;
          else cnt = val.length;
          if(cnt < minLength) msg += msgFillOut + ' "' + title + '"\n';
        }
      }
      else msg += msgNoField + ': "' + field + '"\n';
    }

    if(msg) alert(msg);
    else document.forms[f].submit();
  }
  else alert(msgNoForm + ': "' + f + '"');
}

//--------------------------------------------------------------------------------------------------------
