﻿
DivSwitcher.prototype.CurrentDiv = -1;

function DivSwitcher() {
    this.CurrentDiv = -1;

}

DivSwitcher.prototype.ShowDiv = function(id) {
    if (this.CurrentDiv != -1)
        this.HideDiv(CurrentDiv);

    this.CurrentDiv = id;
    $("#" + id).show();
}

DivSwitcher.prototype.HideDiv = function(id) {
    this.CurrentDiv = -1;
    $("#" + id).hide();
}

function foo() {

}

function isChild(ancestor, candidate) {
    if (!ancestor || !ancestor.parentNode || !candidate) return false;
    while (candidate && candidate != ancestor.parentNode) {
        if (candidate == ancestor) return true;
        try {
            candidate = candidate.parentNode;
        } catch (c) { return false }
    }
}

function createContextFunction(context, method, method2) {
    return (function(x) {
        method = (method == "post") ? method2 : method;
        eval("context." + method + "(x)");
        return false;
    });
}

function createContextFunction_v2(context, method, method2) {
    return (function(x) {
        method = (method == "post") ? method2 : method;
        eval("context." + method);
        return false;
    });
}

function addEventHandler(element, type, handler) {
    try {
        element.addEventListener(type, handler, false);
    } catch (inferiorBrowserException) {
        if (element.attachEvent)
            element.attachEvent('on' + type, handler);
        else
            element['on' + type] = handler;
    }
    return [element, type, handler];
}

function isSafari() {
    return (/safari/i).test(navigator.userAgent);
}

function removeEventHandler(o, eventName, handler) {
    if (o.removeEventListener) {
        o.removeEventListener(eventName, handler, true);
    } else {
        o.detachEvent("on" + eventName, handler);
    }
}

function cancelEvent(e) {
    try {
        e.preventDefault();
        e.stopPropagation();
    } catch (someException) {
        e.cancelBubble = true;
        e.returnValue = false;
    }
    if (isSafari()) {
        var target = e.target;
        while (target.nodeType > 1) target = target.parentNode;
        if (/^a$/i.test(target.nodeName)) {
            target.onclick = function() {
                return false;
            };
        }
    }
    return false;
}


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){		    
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		    
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){		    
		    return false
		 }

 		 return true					
	}

	function isNummeric(strString) {

	    var strValidChars = "0123456789.-+";
	    var strChar;
	    var blnResult = true;

	    if (strString.length == 0) return false;

	    //  test strString consists of valid characters listed above
	    for (i = 0; i < strString.length && blnResult == true; i++) {
	        strChar = strString.charAt(i);
	        if (strValidChars.indexOf(strChar) == -1) {
	            blnResult = false;
	        }
	    }
	    return blnResult;
	    
	}
