
// 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 isDec(number){
        validChar = "01234567890.";
        strlen = number.length;
    
        for(i=0; i<strlen; i++){
            if(validChar.indexOf(number.charAt(i))<0){
                return false;
            }
        }
        return true;
    }
    
    function isPhone(number){
        validChar = "0123456789-+.( )";
        strlen = number.length;
    
        for(i=0; i<strlen; i++){
            if(validChar.indexOf(number.charAt(i))<0){
                return false;
            }
        }
        return true;
    }
    
    //isSub to validate sub-category, by validating the selected text
    //Match the subLabel Ex. ----> [Selected text]
    //subLabel = "---->"
    function isSub(selected_text, subLabel){

        if(selected_text.match(subLabel)){
            return true;
        }
        else{
            return false;
        }
    }

    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(email) {
		// return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

        // check to make sure there's @ appear
        // some text appear before and after @
        // also if it contains dot, must follow by 2 or 4 characters.

        var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
        if (filter.test(email)){
            return true;
        }
        else {
            return false;
        }
	}

	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];
			}
		} 
	}
	
	function confirmFormReset(formObj) {
        if (confirm("Are you sure you want to clear form?")) {
            formObj.reset();
        }    
    }

    function clearDate(formInput) {
        formInput.value = "";
    }
	
	
    // browser detection function	
	function getInternetExplorerVersion() {
	// Returns the version of Windows Internet Explorer or a -1
	// (indicating the use of another browser).
	
	   var rv = -1; // Return value assumes failure.
	   if (navigator.appName == 'Microsoft Internet Explorer'){
		  var ua = navigator.userAgent;
		  var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		  if (re.exec(ua) != null)
			 rv = parseFloat( RegExp.$1 );
	   }
	   return rv;
	}
	
	function checkIEVersion(){
	   var msg = "You're not using Windows Internet Explorer.";
	   var ver = getInternetExplorerVersion();
	   
	   if ( ver> -1 ) {
		  if ( ver >= 8.0 )
			 msg = "You're using Windows Internet Explorer 8.";
		  else if ( ver == 7.0 )
			  msg = "You're using Windows Internet Explorer 7.";
		  else if ( ver == 6.0 )
			  msg = "You're using Windows Internet Explorer 6.";
		  else
			  msg = "You should upgrade your copy of Windows Internet Explorer";
		}
		
		return ver;
	   //alert(ver);	
	   //alert( msg );	   	   
	}	
	
	function isIE6() {
		if (checkIEVersion() == 6) {
			return true;
		}	
		else {return false;}
	}