
// Window function

	function openWindow(winname, url, width, height, tbar, sbar, resize){
		var options = "toolbar="+"tbar"+",scrollbars="+sbar+",resizable="+resize+",width="+width+",height="+height;

		var newWind = window.open(url, winname, options);
		newWind.focus();

		if (newWind.opener == null) {
			newWind.opener = window;
		}
	}

// utility functions
    
    function trim(str){
       return str.replace(/^\s+|\s+$/g,'');
    }

    function formError(msg, obj) {
        alert(msg);
        obj.focus();
        // can extend to highligh form color
        // or show small msg below etc
    }

    function isAlphaNumeric(str){
        validChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
        strlen = str.length;

        for(i=0; i<strlen; i++){
            if(validChar.indexOf(str.charAt(i))<0){
                return false;
            }
        }
        return true;
    }

    function toggleLayer( whichLayer ){
        var elem, vis;
        if( document.getElementById ) // this is the way the standards work
            elem = document.getElementById( whichLayer );
        else if( document.all ) // this is the way old msie versions work
            elem = document.all[whichLayer];
        else if( document.layers ) // this is the way nn4 works
            elem = document.layers[whichLayer];
        vis = elem.style;
        // if the style.display value is blank we try to figure it out here
        if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
            vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
        vis.display = (vis.display==''||vis.display=='block')?'none':'block';
    }
    
	function isValidEmail(str) {
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}

	function getQueryVariable(variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");
        
		for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
            	return pair[1];
			}
		} 
	}