DOM = (document.getElementById)? true : false;
IE = (navigator.userAgent.indexOf("MSIE") != -1);

ocsMenu = ocItem = function(id){
	if(DOM){
		cNode = document.getElementById(id);
		if(cNode){
			cStatus = (cNode.className.indexOf('opened') != -1);
			if(cStatus){
				re = /opened/
				cNode.className = cNode.className.replace(re,"");
				re = /(\s)+/
				cNode.className = cNode.className.replace(re," ");
			}else{
				cNode.className += " opened";
			}
		}
	}
}

openVoteWindow = function(){
	nw= window.open("","voteWindow","width=250,height=350,scrollbars=yes,resizable=yes")
}

function formatNumber (num, decplaces) {
    // convert in case it arrives as a string value
    num = parseFloat(num);
    // make sure it passes conversion
    if (!isNaN(num)) {
        // multiply value by 10 to the decplaces power;
        // round the result to the nearest integer;
        // convert the result to a string
        var str = "" + Math.round (eval(num) * Math.pow(10,decplaces));
        // exponent means value is too big or small for this routine
        if (str.indexOf("e") != -1) {
            return "Out of Range";
        }
        // if needed for small values, pad zeros
        // to the left of the number
        while (str.length <= decplaces) {
            str = "0" + str;
        }
        // calculate decimal point position
        var decpoint = str.length - decplaces;
        // assemble final result from: (a) the string up to the position of
        // the decimal point; (b) the decimal point; and (c) the balance
        // of the string. Return finished product.
        return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
    } else {
        return "NaN";
    }
}


function IsEmailValid(email){
	var reg = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$/i;
	if(reg.test(email)) return true;
	else return false;
}


removeClassName = function(node, className){
	re = new RegExp("(^|\\s+)" + className + "(\\s+|$)", "g");
	node.className = node.className.replace(re, "");
	node.className = node.className.replace(/\s+/, " ");
}

showMap = function(id){
	if ( window.activeMapRegion ) {
		window.activeMapRegion.className += " hiddenBlock";
	}
	if ( window.activeMapRegionData ) {
		window.activeMapRegionData.className += " hiddenBlock";
	}
	var tmpNode = document.getElementById("region_"+id);
	if ( tmpNode ) {
		removeClassName(tmpNode, "hiddenBlock");
		window.activeMapRegion = tmpNode;
	}
	var tmpNode = document.getElementById("representative_"+id);
	if ( tmpNode ) {
		removeClassName(tmpNode, "hiddenBlock");
		window.activeMapRegionData = tmpNode;
	} else {
		var tmpNode = document.getElementById("representative_none");
		if ( tmpNode ) {
			removeClassName(tmpNode, "hiddenBlock");
			window.activeMapRegionData = tmpNode;
		}
	}

}