﻿function objectWrite(value){
    document.write(value);
}

function $(id){
	return document.getElementById(id);
}

function addEvent(id, eventType, eventFunction){
	if (id.attachEvent){
		id.attachEvent("on" + eventType, eventFunction);
	}else if (id.addEventListener){
		id.addEventListener(eventType, eventFunction, false);
	}else{
		id["on" + eventType] = eventFunction;
	}
}

function removeEvent(id, eventType, eventFunction){
	if (id.detachEvent){
		id.detachEvent("on" + eventType, eventFunction);
	}else if (id.removeEventListener){
		id.removeEventListener(eventType, eventFunction, false);
	}else{
		id["on" + eventType] = function(){};
	}
}

function trim(value)
{
   return value.replace(/^\s*|\s*$/g,"");
}

/*

******************************** Crosswalk Functions *********************************

String.prototype.trim = new Function("return this.replace(/^\\s+|\\s+$/g,'')");
String.prototype.isEmpty = new Function("var x = this.trim(); if (x.length == 0) { return true; } else { return false; }");
String.prototype.left = function(n){
	if (n <= 0){
	    return '';
	}else if (n > this.length){
	    return str;
	}else{
	    return this.substring(0,n);
	}
}
String.prototype.right = function(n){
    if (n <= 0){
       return '';
    }else if (n > this.length){
       return str;
    }else{
       var iLen = this.length;
       return this.substring(iLen, iLen - n);
    }
}





function stopEvent(e){
	if (e.stopPropagation){
	// for DOM-friendly browsers
		e.stopPropagation();
		e.preventDefault();
	}else{
	// For IE
		e.returnValue = false;
		e.cancelBubble = true;
	}
}





function overrideDefaultSubmit(event, control){
    if (event.keyCode == 13){
        $(control).click();
        return false;
    }
}



function hide(id){
    if (id){
        id.style.display = 'none';
	}
}

function show(id){
    if (id){
        id.style.display = 'block';
    }	
}

function setCssClass(x, cssClass){
	if (window.attachEvent && x){
		x.setAttribute("className", cssClass);
	}else if (window.addEventListener && x){
		x.setAttribute("class", cssClass);
	}
}

function AsyncRequest(){
    this.method;            //This is the form method (GET or POST).
    this.url;               //The url to request.
    this.cache = false;     //GET requests are cached by default. 
    this.data;				//This variable holds the form data in the form of a querystring without the leading "?".
    this.callback;          //This will hold the callback function if the asynchronous call responds successfully.
    this.onError = null;	//This will hold a reference to a function to call in case of an error.
   
    //The XmlHttp request object. It does all of the asynchronous sending, receiving, and state handling.
    this.xmlHttp = new function(){ 
        try{
            return new ActiveXObject("Msxml2.XMLHTTP"); 
        }catch(e){}
        try{ 
            return new ActiveXObject("Microsoft.XMLHTTP"); 
        }catch(e){}
        try{ 
            return new XMLHttpRequest(); 
        }catch(e){}
        alert("XMLHttpRequest not supported. Please contact technical support.");
        return null;
    }
    
    //This function handles sending the data via an XmlHttp transport.
    //Notice that (this) is passed in with the function. 
    //This will allow the XmlHttp object to properly handle its readyState.
    this.send = function(){ with(this) { 
        if (method == "GET"){
            if (data.left(1) != '?'){
				url = url + "?" + data;
			}else{
				url = url + data;
			}
            xmlHttp.open(method, url, true);
        }else{
            xmlHttp.open(method, url, true);
        }
        xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4){
                var responseText = xmlHttp.responseText;
                switch (xmlHttp.status){
                    case 404:
                        if (onError == null){
							alert('Page Not Found. The requested url \'' + url + '\' could not be found.');
						}else{
							onError('Page Not Found. The requested url \'' + url + '\' could not be found.');
						}
                        break;
                    case 405:
						if (onError == null){
							alert('Cannot post form data to this page. The requested url \'' + url + '\' could be missing.');
						}else{
							onError('Cannot post form data to this page. The requested url \'' + url + '\' could be missing.');
						}
                        break;
                    case 500:
                        if (onError == null){
							alert(responseText); //This will spit out the entire error received from the called page.
						}else{
							onError(responseText);
						}
                        break;
                    case 200:
                        if (responseText.indexOf('Error:') > -1 || responseText.indexOf('Debug:') > -1){
							if (onError == null){
								alert(responseText); //This is for custom debugging. Insert Error: or Debug: on the called page's response.
							}else{
								onError(responseText);
							}
                        }else{
                            callback(responseText); //Success! Call the user-defined handler and pass in the response text.
                        }
                        break;
					default:
						if (onError == null){
							alert('Undefined error code: ' + xmlHttp.status + '. Please report this to technical support');
							alert(responseText);
						}else{
							onError(responseText);
						}
                        break;
                }
            }
        }
        xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        if (!cache && method != "POST"){
            xmlHttp.setRequestHeader('If-Modified-Since', 'Fri, 5 Dec 1980 00:00:00 GMT');
        }
        if (method == "GET"){
            xmlHttp.send(null);
        }else{
            xmlHttp.send(data);
        }
    }}
}

*/