//---------------------------------------------
// il-vs-hs.js
//---------------------------------------------
// AJAX functions

	var http = false;
    var ajaxInProgress = false;

	if(navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}

	function divText(div_id, txt)
	{
		document.getElementById(div_id).innerHTML = txt;
	}

	function divDisplay(div_id, state)
    {
		document.getElementById(div_id).style.display = state;
    }

	function divViewSwitch(b)
    {
    	if(b){
		worldView();
	    	divDisplay('divViewWorld','block');
	        divDisplay('divViewList','none');
	        divDisplay('divTop','none');
	        divDisplay('divList','none');
	        divDisplay('divFlashWorld','block');
        } else {
	        divDisplay('divViewList','block');
	    	divDisplay('divViewWorld','none');
	        divDisplay('divFlashWorld','none');
	        divDisplay('divTop','block');
	        divDisplay('divList','block');
        }
    }

	function getHeightByID(id)
    {
		return document.getElementById(id).offsetHeight;
    }

	function httpRequest(params) {
    	if(ajaxInProgress) return false;

		http.abort();
		http.open('POST', 'sendvote.php', true);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.onreadystatechange = function() {
            if(http.readyState == 4) {
                var responseText = http.responseText.split('[]');
                divText('div_il_total', 'Total Votes: ' + responseText[1]);
				divText('div_hs_total', 'Total Votes: ' + responseText[2]);
                img = document.getElementById('secimage');
                // Change the image
                //img.src = 'captcha/create_image.php&sid=' + Math.random();
                img.src = 'captcha.jpg&sid=' + Math.random();
                document.getElementById('security_code').value='';
                if(params.indexOf('vote_to=-1')) alert(responseText[0]);
                document.getElementById('country_flag').src = responseText[3];
                divDisplay('div_work', 'none');
               	ajaxInProgress = false;
			}
		}
		divDisplay('div_work', 'block');
		http.send(params);	// if GET then null;
       	ajaxInProgress = true;
	}

	function getQueryString(form, vote_to) {
		//var form = document.forms[frm];
		qstr = 'vote_to=' + vote_to;  // NOTE: no '?' before querystring
		qstr = qstr + '&security_code=' + escape(form.security_code.value);  // NOTE: no '?' before querystring
		return qstr;
	}
	function disableKey(e, key)
	{
		var k;
		if(window.event) { // IE
			k = e.keyCode;
		} else if(e.which) { // Netscape/Firefox/Opera
			k = e.which;
		}

		if(k == key) return false;
		return true;
	}

	function dynLoadJS(url)
	{
		var e = document.createElement("script");
		e.src = url;
		e.type="text/javascript";
		document.getElementsByTagName("head")[0].appendChild(e);
	}

	function worldView()
	{
		//dynLoadJS("ammap/ammap/swfobject.js");

		// <![CDATA[
		var so = new SWFObject("ammap/ammap/ammap.swf?" + Math.random(), "ammap", "600", "316", "8", "#3A79C1");
		so.addVariable("path", "ammap/ammap/");
		so.addVariable("data_file", escape("ammap/ammap/ammap_data.xml"));
		so.addVariable("settings_file", escape("ammap/ammap/ammap_settings.xml"));
		so.addVariable("preloader_color", "#999999");
		so.write("divFlashWorld");
		// ]]>
	}

	function httpRequestStats(params)
	{
	    	if(ajaxInProgress) return false;

		http.open('POST', 'statistics-div.php', true);
		http.onreadystatechange = function() {
            		if(http.readyState == 4) {
				document.getElementById('divStats').innerHTML = http.responseText;
			            divDisplay('div_work', 'none');
	               		ajaxInProgress = false;
			}
		}
		divDisplay('div_work', 'block');
		http.send(params);
	       	ajaxInProgress = true;
	}

//---[EOF]---
