//
//  rs.js - Remote Scripting JavaScript Include File
//  
//  Rewritten from jsrsClient.js, taken from 
//    http://www.ashleyit.com/rs/jsrs/test.htm (version 2.3)
//    Copyright (C) 2001 by Brent Ashley
//  Rewrite Copyright (C) 2004 by Alvaro Mendez
//
//  Include this file inside your page like this:
//  <script language='JavaScript' src='/scripts/rs.js'></script>
//


var _val_agt=navigator.userAgent.toLowerCase();
var _val_is_major=parseInt(navigator.appVersion);
var _val_is_ie=((_val_agt.indexOf("msie")!=-1) && (_val_agt.indexOf("opera")==-1));
var _val_isNT=_val_agt.indexOf("windows nt")!=-1;
var _val_IE=(document.all);
var _val_IE4=(_val_is_ie && (_val_is_major==4) && (_val_agt.indexOf("msie 4")!=-1));
var _val_IE6=(_val_is_ie && (_val_agt.indexOf("msie 6.0")!=-1));
var _val_NS=(document.layers);
var _val_DOM=(document.getElementById);
var _val_isMac=(_val_agt.indexOf("Mac")==-1);
var _val_allString="document.";
_val_allString += (_val_IE)?"all.":(_val_DOM)?"getElementById(\"":"";
var _val_styleString=(_val_IE)?".style":(_val_DOM)?"\").style":"";
var _val_endAllString=(_val_DOM && !_val_IE)?"\")":"";
var _val_px=(_val_DOM)?"px":"";

var Page_DomValidationVer = "2";
var Page_IsValid = true;  
var Page_BlockSubmit = false;



// This is the object to use, along with the Execute function (below)

var RS = new RemoteScripting();
var calltouse=0;
// Remote Scripting class.  
// This class should NOT be instanciated -- use the global RS object. 
function RemoteScripting()
{
	this.pool = new Array();
	this.poolSize = 0;
	this.maxPoolSize = 200;
	this.usePOST = true;
	this.debug = false;

	// Sniff the browser
	if (document.layers)
		this.browser = "NS";
	else if (document.all)
	{
		var agent = navigator.userAgent.toLowerCase();
		if (agent.indexOf("opera") != -1)
			this.browser = "OPR";
		else if (agent.indexOf("konqueror") != -1)
			this.browser = "KONQ";
		else
			this.browser = "IE";
	}
	else if (document.getElementById)
		this.browser = "MOZ";
	else 
		this.browser = "OTHER";
}

// Executes a remote method found on a given URL.
// Usage: Execute(url,method,p1 ... pn,callback,error_callback)
//		  url				: url of file containing method to invoke
//		  method			: name of the Server-side method to be invoked
//		  p1...pn			: any parameters to be passed to the Server-side method
//		  callback		    : optional JavaScript function to call on successful return.
//        error_callback	: optional JavaScript function to call on failed return.  
//                            If not passed and an error occurs, an alert box is shown.
RemoteScripting.prototype.Execute = function(url, method)
{
	var call = this.getAvailableCall();	
	var args = RemoteScripting.prototype.Execute.arguments;
	var len = RemoteScripting.prototype.Execute.arguments.length;

	var methodArgs = new Array();

	for (var i = 2; i < len; i++)
	{
		if (typeof(args[i]) == 'function')
		{
			call.callback = args[i];		  
			if (i + 1 < len)
				call.error_callback = args[i + 1];
			break;
		}
		
		methodArgs[i - 2] = args[i];
	}
	
	call.showIfDebugging();

	if (this.usePOST && ((this.browser == 'IE') || (this.browser == 'MOZ')))
	{
		//alert(methodArgs);
		call.POST(url, method, methodArgs);
	}
	else
	{ 
		call.GET(url, method, methodArgs);
	}
	
	return this.id;
}

// Pops up a separate window containing Debug information.
// You can attach this to the F1 key for IE with onHelp = "return RS.showDebugInfo() in the body tag.
RemoteScripting.prototype.PopupDebugInfo = function()
{
	var doc = window.open().document;
	doc.open();
	doc.write('<html><body>Pool Size: ' + this.poolSize + '<br><font face = "arial" size = "2"><b>');
	for (var i in this.pool)
	{
		var call = this.pool[i];
		doc.write('<hr>' + call.id + ' : ' + (call.busy ? 'busy' : 'available') + '<br>');
		doc.write(call.container.document.location.pathname + '<br>');
		doc.write(call.container.document.location.search + '<br>');
		doc.write('<table border = "1"><tr><td>' + call.container.document.body.innerHTML + '</td></tr></table>');
	}
	doc.write('</table></body></html>');
	doc.close();
	return false;
}

// Retrieves an available Call object from the pool.
// This function is used internally and should be treated as private.
RemoteScripting.prototype.getAvailableCall = function()
{
	for (var i in this.poolSize)
	{
		var call = this.pool['C' + (i + 1)];
		if (!call.busy)
		{
			call.busy = true;      
			return this.pool[call.id];
		}
	}
	
	// If we got here, there are no existing free calls
	if (this.poolSize <= this.maxPoolSize)
	{
		var callID = "C" + (this.poolSize + 1);
		this.pool[callID] = new RemoteScriptingCall(callID);
		this.poolSize++;
		return this.pool[callID];
	}
	else
	{
		var call = this.pool['C' + (calltouse + 1)];
		call.busy = true;      
		return this.pool[call.id];
		calltouse=(calltouse+1)%this.maxPoolSize;
	}
	
	//alert("RemoteScripting Error: Call pool is full!");
	//return null;
}


// Remote Scripting Call class.  
// This class should NOT be instanciated -- this is used by the RS object's pool.
function RemoteScriptingCall(callID)
{
	this.id = callID;
	this.busy = true;
	this.callback = null;
	this.error_callback = null;

	switch (RS.browser)
	{
		case 'IE':
			document.body.insertAdjacentHTML("afterBegin", '<span id = "SPAN' + callID + '"></span>');
			var span = document.all("SPAN" + callID);
			var html = '<iframe style = "width:800px" name = "' + callID + '" src = ""></iframe>';
			span.innerHTML = html;
			span.style.display = 'none';
			this.container = window.frames[callID];
			break;
			
		case 'NS':
			this.container = new Layer(100);
			this.container.name = callID;
			this.container.visibility = 'hidden';
			this.container.clip.width = 100;
			this.container.clip.height = 100;
			break;
			
		case 'MOZ':
		case 'OPR':        
			var span = document.createElement('SPAN');
			span.id = "SPAN" + callID;
			document.body.appendChild(span);
			var iframe = document.createElement('IFRAME');
			iframe.id = callID;
			iframe.name = callID;
			iframe.style.width = 800;
			iframe.style.height = 200;
			span.appendChild(iframe);
			this.container = iframe;
			break;
			
		case 'KONQ':  
		default:
			var span = document.createElement('SPAN');
			span.id = "SPAN" + callID;
			document.body.appendChild(span);
			var iframe = document.createElement('IFRAME');
			iframe.id = callID;
			iframe.name = callID;
			iframe.style.width = 800;
			iframe.style.height = 200;
			span.appendChild(iframe);
			this.container = iframe;
			
			// Needs to be hidden for Konqueror, otherwise it'll appear on the page
			span.style.display = none;
			iframe.style.display = none;
			iframe.style.visibility = hidden;
			iframe.height = 0;
			iframe.width = 0;
	}	
}

// Posts to the given url to have it invoke the given method.
// This function is used internally and should be treated as private.
RemoteScriptingCall.prototype.POST = function(url, method, args)
{
	var d = new Date();
	var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
	var doc = (RS.browser == "IE") ? this.container.document : this.container.contentDocument;
	var paramSep = (url.lastIndexOf('?') < 0 ? '?' : '&');
	doc.open();
	doc.write('<html><body>');
	doc.write('<form name="rsForm" method="post" target=""');
	doc.write('action="' + url + paramSep + 'U=' + unique + '">');
	doc.write('<input type="hidden" name="RC" value="' + this.id + '">');
	
	// func and args are optional
	if (method != null)
	{
		doc.write('<input type = "hidden" name = "M" value = "' + method + '">');
		
		if (args != null)
		{
			if (typeof(args) == "string")
			{
				// single parameter
				doc.write('<input type = "hidden" name = "P0" '
					+ 'value = "[' + this.escapeParam(args) + ']">');
			}
			else 
			{
				// assume args is array of strings
				for (var i = 0; i < args.length; i++)
				{
					doc.write('<input type = "hidden" name = "P' + i + '" '
						+ 'value = "[' + this.escapeParam(args[i]) + ']">');
				}
			} // parm type
		} // args
	} // method
	
	doc.write('</form></body></html>');
	doc.close();
	//alert(doc.body.innerHTML);
	doc.forms['rsForm'].submit();
}

// Navigates to the given url to have it invoke the given method.
// This function is used internally and should be treated as private.
RemoteScriptingCall.prototype.GET = function(url, method, args)
{
	// build URL to call
	var URL = url;
	var paramSep = (url.lastIndexOf('?') < 0 ? '?' : '&');
	
	// always send call
	URL += paramSep + "RC=" + this.id;
	
	// method and args are optional
	if (method != null)
	{
		URL += "&M=" + escape(method);
		
		if (args != null)
		{
			if (typeof(args) == "string")
			{
				// single parameter
				URL += "&P0=[" + escape(args + '') + "]";
			}
			else 
			{
				// assume args is array of strings
				for (var i = 0; i < args.length; i++)
				{
					URL += "&P" + i + "=[" + escape(args[i] + '') + "]";
				}
			} // parm type
		} // args
	} // method
	
	// unique string to defeat cache
	var d = new Date();
	URL += "&U=" + d.getTime();
	
	// make the call
	switch (RS.browser)
	{
		case 'IE':
			this.container.document.location.replace(URL);
			break;
		case 'NS':
			this.container.src = URL;
			break;
		case 'MOZ':
		case 'OPR':
		case 'KONQ':
		default:
			this.container.src = '';
			this.container.src = URL; 
			break;
	}  
}

// Sets the result of the call of the remote method.
// This function is designed to be called only when the response is received.
RemoteScriptingCall.prototype.setResult = function(result)
{
	this.busy = false;
	

	if (result == true)
	{
		if (this.callback != null)
			this.callback(this.unescape(this.getPayload()), this.id);
	}
	else
	{
		if (this.error_callback == null)
			alert(this.unescape(this.getPayload()));
		else
			this.error_callback(this.unescape(this.getPayload()), this.id);
	}
		
	this.callback = null;
	this.error_callback = null;
}

// Retrieves the payload's message sent by the response.
// This function is used internally and should be treated as private.
RemoteScriptingCall.prototype.getPayload = function()
{
	switch (RS.browser)
	{
		case 'IE':
			return this.container.document.forms['rsForm']['rsPayload'].value;
		case 'NS':
			return this.container.document.forms['rsForm'].elements['rsPayload'].value;
		case 'MOZ':
			return window.frames[this.container.name].document.forms['rsForm']['rsPayload'].value; 
		case 'OPR':
		case 'KONQ':
		default:
			return window.frames[this.container.name].document.getElementById("rsPayload").value;
	}  
}

// Shows (or hides) elements on the page that assist in debugging, based on RS.debug.
// This function is used internally and should be treated as private.
RemoteScriptingCall.prototype.showIfDebugging = function()
{
	var vis = (RS.debug == true);
	switch (RS.browser)
	{
		case 'IE':
			document.all("SPAN" + this.id).style.display = (vis) ? '' : 'none';
			break;
		case 'NS':
			this.container.visibility = (vis) ? 'show' : 'hidden';
			break;
		case 'MOZ':
		case 'OPR':
		case 'KONQ':
		default:
			document.getElementById("SPAN" + this.id).style.visibility = (vis) ? '' : 'hidden';
			this.container.width = (vis) ? 250 : 0;
			this.container.height = (vis) ? 100 : 0;
			break; 
	}  
}

// Converts a string to allow it to be properly passed down as a parameter to the page.
// This function is used internally and should be treated as private.
RemoteScriptingCall.prototype.escapeParam = function(str)
{
	return str.replace(/'"'/g, '\\"');
	return str;
}

// Converts a string to allow it to be properly read back from the server.
// This function is used internally and should be treated as private.
RemoteScriptingCall.prototype.unescape = function(str)
{
	return str.replace(/\\\//g, "/");
}

function ValidatorUpdateDisplay(val) {
	//var prop = val.getAttribute("display");
	var prop = dom_getAttribute(val,"display");
	
	var style_str = "", style_prefix = "display: ";
		
    if (typeof(prop) == "string") {    
        if (prop == "None") {
            return;
        }
        if (prop == "Dynamic") {
			style_str = val.isvalid ? "none" : "inline";
            //val.setAttribute("style",style_prefix+style_str+"; ");
            val.style.display = style_str;
            return;
        }
    }
    val.style.visibility = val.isvalid ? "hidden" : "visible";
}

function ValidatorUpdateIsValid() {
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
        if (!Page_Validators[i].isvalid) {
            Page_IsValid = false;
            Page_BlockSubmit = true;
            return;
        }
   }
   Page_IsValid = true;
}

function ValidatorHookupControl(control, val) {
    if (control != null)
    {
	   if (typeof(control.Validators) == "undefined") {
            control.Validators = new Array;
	        var ev = control.onchange;
	        var new_ev;
            if (typeof(ev) == "function" ) {            
                ev = ev.toString();
                //ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
                //new_ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
                new_ev = "if (Page_IsValid || Page_BlockSubmit) {" + ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}")) + "}";
            }
            else {
                //ev = "";
                new_ev = "";
            }

//			if (new_ev != "") {
//				ev += "if (Page_IsValid || Page_BlockSubmit) {" + new_ev + "}";
				//ev += "if (true) {" + new_ev + "}";
//			}
            //var func = new Function("ValidatorOnChange('" + control.id + "'); " + ev);
            var func = new Function("ValidatorOnChange('" + control.id + "'); " + new_ev);
    //alert(control.id + " function is [" + func + "]");
	        control.onchange = func;
	    }
        control.Validators[control.Validators.length] = val;
    }
}

function ValidatorGetValue(id) {
    var control;
    //control = document.getElementById(id);
    control = dom_getElementByID(id);
    if (control == null)
		return "";

    if (typeof(control.value) == "string") {
        return control.value;
    }

    if (typeof(control.tagName) == "undefined" && typeof(control.length) == "number") {
        var j;
        for (j=0; j < control.length; j++) {
            var inner = control[j];
            if (typeof(inner.value) == "string" && (inner.type != "radio" || inner.status == true)) {
                return inner.value;
            }
        }
    }
}

function Page_ClientValidate() {
    var i,ctrl;
    for (i = 0; i < Page_Validators.length; i++) {
        ValidatorValidate(Page_Validators[i]);
    }
    ValidatorUpdateIsValid();   
    ValidationSummaryOnSubmit(); 
    Page_BlockSubmit = !Page_IsValid;
    return Page_IsValid;
}

function ValidatorCommonOnSubmit() {
///<V1.200> - Support for CausesValidation property
   var retValue = !Page_BlockSubmit;

   if (!_val_NS) {   // If we are not in crappy old Netscape 4.7 then....
      if (_val_IE)  // If its Internet Explorer, set our return event value.
         event.returnValue = retValue;
   }
   
   Page_BlockSubmit = false;

   return retValue;
}

function ValidatorOnChange(controlID) {
    //var cont = document.getElementById(controlID);
    var cont = dom_getElementByID(controlID);
    var vals = cont.Validators;
    var i;
    for (i = 0; i < vals.length; i++) {
        ValidatorValidate(vals[i]);
    }
    ValidatorUpdateIsValid();    
    return Page_IsValid;
}

function ValidatorValidate(val) {   
    val.isvalid = true;
    if (val.enabled != false)    // V2.00 change
    {
        if (typeof(val.evalfunc) == "function") {
            val.isvalid = val.evalfunc(val); 
        }
    }
    ValidatorUpdateDisplay(val);
}

function ValidatorOnLoad() {
    if (typeof(Page_Validators) == "undefined")
        return;

    var i, val;
    for (i = 0; i < Page_Validators.length; i++) {
        val = Page_Validators[i];
        //var evalFunction = val.getAttribute("evaluationfunction");
        var evalFunction = dom_getAttribute(val,"evaluationfunction");
        if (typeof(evalFunction) == "string") {
            eval("val.evalfunc = " + evalFunction + ";");
        }
        //var isValidAttribute = val.getAttribute("isvalid");
        var isValidAttribute = dom_getAttribute(val,"isvalid");
        if (typeof(isValidAttribute) == "string") {
            if (isValidAttribute == "False") {
                val.isvalid = false;                                
                Page_IsValid = false;
            } 
            else {
                val.isvalid = true;
            }
        } else {
            val.isvalid = true;
        }
        if (typeof(val.enabled) == "string") {
            val.enabled = (val.enabled != "False");
        }
        //var controlToValidate = val.getAttribute("controltovalidate");
        var controlToValidate = dom_getAttribute(val,"controltovalidate");
        if (typeof(controlToValidate) == "string") {
			ValidatorHookupControl(dom_getElementByID(controlToValidate), val);
            //ValidatorHookupControl(document.getElementById(controlToValidate), val);
        }
		//var controlhookup = val.getAttribute("controlhookup");
		var controlhookup = dom_getAttribute(val,"controlhookup");
		if (typeof(controlhookup) == "string") {
            if (controlhookup != "")    // V2.00 Change
            {
			    //ValidatorHookupControl(document.getElementById(controlhookup), val);
			    ValidatorHookupControl(dom_getElementByID(controlhookup), val);
			}
		}        
    }
    Page_ValidationActive = true;
    if (!Page_IsValid)
		ValidationSummaryOnSubmit();
		
	// IE4 hack test
    if (_val_IE4)
    {
		var ev = new Function("ValidationSummaryOnSubmit();");
		document.onreadystatechange=ev;
	}
	
}

function RegularExpressionValidatorEvaluateIsValid(val) {
    //var value = ValidatorGetValue(val.getAttribute("controltovalidate"));
    var value = ValidatorGetValue(dom_getAttribute(val, "controltovalidate"));
    if (value == "")
        return true;        
    //var rx = new RegExp(val.getAttribute("validationexpression"));
    var rx = new RegExp(dom_getAttribute(val, "validationexpression"));
    var matches = rx.exec(value);
    return (matches != null && value == matches[0]);
}

function ValidatorTrim(s) {
    //var m = s.match(/^\s*(.*\S)\s*$/);
    //return (m == null) ? "" : m[1];

    // change sent by Mathew A. Frank 11/05/2003 <V2.000> fix.
    return s.replace(/^\s+|\s+$/g, "");
}

function RequiredFieldValidatorEvaluateIsValid(val) {
    //return (ValidatorTrim(ValidatorGetValue(val.getAttribute("controltovalidate"))) != ValidatorTrim(val.getAttribute("initialvalue")));
    return (ValidatorTrim(ValidatorGetValue(dom_getAttribute(val, "controltovalidate"))) != ValidatorTrim(dom_getAttribute(val, "initialvalue")));
}


///////////////////////////////////// my stuff ////////////////////////////////////////////////////////////

function ValidatorCompare(operand1, operand2, operator, val) {
    //var dataType = val.type;
    //var dataType = val.getAttribute("type",false);
    var dataType = dom_getAttribute(val, "type");
    var op1, op2;
    if ((op1 = ValidatorConvert(operand1, dataType, val)) == null)
        return false;   
    if (operator == "DataTypeCheck")
        return true;
    if ((op2 = ValidatorConvert(operand2, dataType, val)) == null)
        return true;
    if (op2 == "")
		return true;
    switch (operator) {
        case "NotEqual":
            return (op1 != op2);
        case "GreaterThan":
            return (op1 > op2);
        case "GreaterThanEqual":
            return (op1 >= op2);
        case "LessThan":
            return (op1 < op2);
        case "LessThanEqual":
            return (op1 <= op2);
        default:
            return (op1 == op2);            
    }
}



function CompareValidatorEvaluateIsValid(val) {
    var ctrl = dom_getAttribute(val, "controltovalidate");
    if (null == ctrl)
        return true;
    var value = ValidatorGetValue(ctrl);
    if (ValidatorTrim(value).length == 0)
        return true;
    var compareTo = "";

    // V2.0 changes
    var hookupCtrl = dom_getAttribute(val, "controlhookup");
    var useCtrlToValidate = false;
    if (hookupCtrl != null)
    {
        if (typeof(hookupCtrl) == "string")
        {
		    if (hookupCtrl != "")
		        useCtrlToValidate = true;
        }
    }
    // End V2.00 changes
    
    if (!useCtrlToValidate) {  // V2.00 change
        var ctrl_literal = dom_getAttribute(val, "valuetocompare");
        if (typeof(ctrl_literal) == "string") {
            compareTo = ctrl_literal;  // V2.00 change
         }
    }
    else {
        compareTo = ValidatorGetValue(dom_getAttribute(val, "controlhookup"));
    }
    operator = dom_getAttribute(val, "operator");
    return ValidatorCompare(value, compareTo, operator, val);
}

function CustomValidatorEvaluateIsValid(val) {
    var value = "";
    //var ctrl = val.getAttribute("controltovalidate");
    var ctrl = dom_getAttribute(val, "controltovalidate");
    if (typeof(ctrl) == "string") {
		if (ctrl != "") {
			value = ValidatorGetValue(ctrl);
			if (value == "")
				return true;
        }
    }
    var valid = true;
    //var func_str = val.getAttribute("clientvalidationfunction");
    var func_str = dom_getAttribute(val, "clientvalidationfunction");
    if (typeof(func_str) == "string") {
        if (func_str != "") {
            eval("valid = (" + func_str + "(val, value) != false);");
        }
    }        
    return valid;
}

// Added for V2.0 changes - 27/1/2002 - Glav
function RangeValidatorEvaluateIsValid(val) {
	var value;    
    var ctrl = dom_getAttribute(val, "controltovalidate");
    if (typeof(ctrl) == "string") {
		if (ctrl != "") {
			value = ValidatorGetValue(ctrl);
			if (value == "")
				return true;
        }
    }

    var minval = dom_getAttribute(val,"minimumvalue");
    var maxval = dom_getAttribute(val,"maximumvalue");

	if (minval == null && maxval == null)
        return true;
    
    if (minval == "")
		minval = 0;
	if (maxval == "")
		maxval = 0;
	
    return ( (parseFloat(value) >= parseFloat(minval)) && (parseFloat(value) <= parseFloat(maxval)));
}

function ValidatorConvert(op, dataType, val) {
    function GetFullYear(year) {
        return (year + parseInt(val.century)) - ((year < val.cutoffyear) ? 0 : 100);
    }
    var num, cleanInput, m, exp;
    if (dataType == "Integer") {
        exp = /^\s*[-\+]?\d+\s*$/;
        if (op.match(exp) == null) 
            return null;
        num = parseInt(op, 10);
        return (isNaN(num) ? null : num);
    }
    else if(dataType == "Double") {
        exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + val.decimalchar + "(\\d+))?\\s*$");
        m = op.match(exp);
        if (m == null)
            return null;
        cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
        num = parseFloat(cleanInput);
        return (isNaN(num) ? null : num);            
    } 
    else if (dataType == "Currency") {
        exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + val.groupchar + ")*)(\\d+)"
                        + ((val.digits > 0) ? "(\\" + val.decimalchar + "(\\d{1," + val.digits + "}))?" : "")
                        + "\\s*$");
        m = op.match(exp);
        if (m == null)
            return null;
        var intermed = m[2] + m[5] ;
        cleanInput = m[1] + intermed.replace(new RegExp("(\\" + val.groupchar + ")", "g"), "") + ((val.digits > 0) ? "." + m[7] : 0);
        num = parseFloat(cleanInput);
        return (isNaN(num) ? null : num);            
    }
    else if (dataType == "Date") {
        var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$");
        m = op.match(yearFirstExp);
        var day, month, year;
        if (m != null && (m[2].length == 4 || val.dateorder == "ymd")) {
            day = m[6];
            month = m[5];
            year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10))
        }
        else {
            if (val.dateorder == "ymd"){
                return null;		
            }						
            var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");
            m = op.match(yearLastExp);
            if (m == null) {
                return null;
            }
            if (val.dateorder == "mdy") {
                day = m[3];
                month = m[1];
            }
            else {
                day = m[1];
                month = m[3];
            }
            year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10))
        }
        month -= 1;
        var date = new Date(year, month, day);
        return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
    }
    else {
        return op.toString();
    }
}


function ValidationSummaryOnSubmit() {
    if (typeof(Page_ValidationSummaries) == "undefined") 
        return;
    var summary, sums, s, summ_attrib, hdr_txt, err_msg;
    for (sums = 0; sums < Page_ValidationSummaries.length; sums++) {
        summary = Page_ValidationSummaries[sums];
        summary.style.display = "none";
        if (!Page_IsValid) {
			//summ_attrib = summary.getAttribute("showsummary",false);
			summ_attrib = dom_getAttribute(summary, "showsummary");
            if (summ_attrib != "False") {
                summary.style.display = "";
                if (typeof(summary.displaymode) != "string") {
                    summary.displaymode = "BulletList";
                }
                switch (summary.displaymode) {
                    case "List":
                        headerSep = "<br>";
                        first = "";
                        pre = "";
                        post = "<br>";
                        final_block = "";
                        break;
                        
                    case "BulletList":
                    default: 
                        headerSep = "";
                        first = "<ul>";
                        pre = "<li>";
                        post = "</li>";
                        final_block = "</ul>";
                        break;
                        
                    case "SingleParagraph":
                        headerSep = " ";
                        first = "";
                        pre = "";
                        post = " ";
                        final_block = "<br>";
                        break;
                }
                s = "";
                //hdr_txt = summary.getAttribute("headertext",false);
                hdr_txt = dom_getAttribute(summary, "headertext");
                if (typeof(hdr_txt) == "string") {
                    s += hdr_txt + headerSep;
                }
                var cnt=0;
                s += first;
                for (i=0; i<Page_Validators.length; i++) {
                    //err_msg = Page_Validators[i].getAttribute("errormessage",false);
                    err_msg = dom_getAttribute(Page_Validators[i], "errormessage");
                    if (!Page_Validators[i].isvalid && typeof(err_msg) == "string") {
						if (err_msg != "") {
							cnt++;
							s += pre + err_msg + post;
						}
                    }
                }   
                s += final_block;
            
		// IE4 work around
                if (_val_IE4)
                {
					if (document.readyState == "complete")
					{
						summary.innerHTML  = s;
						window.scrollTo(0,0);
						summary.style.visibility = "visible";
					}
				} else
				{
					summary.innerHTML = s; 
					window.scrollTo(0,0);
					summary.style.visibility = "visible";
				}
            }
            //summ_attrib = summary.getAttribute("showmessagebox",false);
            summ_attrib = dom_getAttribute(summary, "showmessagebox");
            
            if (summ_attrib == "True") {
                s = "";
                //hdr_txt = summary.getAttribute("headertext",false);
                hdr_txt = dom_getAttribute(summary, "headertext");
                if (typeof(hdr_txt) == "string") {
                    //s += hdr_txt + "<BR>";
                    s += hdr_txt + "\n";
                }
                for (i=0; i<Page_Validators.length; i++) {
					//err_msg = Page_Validators[i].getAttribute("errormessage",false);
					err_msg = dom_getAttribute(Page_Validators[i], "errormessage");
                    if (!Page_Validators[i].isvalid && typeof(err_msg) == "string") {
                        switch (summary.displaymode) {
                            case "List":
                                //s += err_msg + "<BR>";
                                s += err_msg + "\n";
                                break;
                                
                            case "BulletList":
                            default: 
                                //s += "  - " + err_msg + "<BR>";
                                s += "  - " + err_msg + "\n";
                                break;
                                
                            case "SingleParagraph":
                                s += err_msg + " ";
                                break;
                        }
                    }
                }
                //span = document.createElement("SPAN");
                //span.innerHTML = s;
                //s = span.getAttribute("innerText",false);
                alert(s);
            }
        }
    }
}

////////////////////////--- Funtions to work in IE4 and DOM ---/////////////////////////////////

function dom_getAttribute(control,attribute)
{
	var attrib;
	if (_val_DOM)
		attrib = control.getAttribute(attribute, false);
	else
		attrib = eval(_val_allString + control.id + "." + attribute + _val_endAllString);
	return attrib;
}

function dom_getElementByID(id)
{
	var element = eval(_val_allString + id + _val_endAllString);
	return element;
}