/* --------------------------------------------------------
   Javascript Global Functions
   global.js
   -------------------------------------------------------- */

/*
  Standards Compliant Rollover Script
  Author : Daniel Nolan
  http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
        if (!document.getElementById) return

        var aPreLoad = new Array();
        var sTempSrc;
        var aImages = document.getElementsByTagName('img');

        for (var i = 0; i < aImages.length; i++) {
                if (aImages[i].className == 'imgover') {
                        var src = aImages[i].getAttribute('src');
                        var ftype = src.substring(src.lastIndexOf('.'), src.length);
                        var hsrc = src.replace(ftype, '_o'+ftype);

                        aImages[i].setAttribute('hsrc', hsrc);

                        aPreLoad[i] = new Image();
                        aPreLoad[i].src = hsrc;

                        aImages[i].onmouseover = function() {
                                sTempSrc = this.getAttribute('src');
                                this.setAttribute('src', this.getAttribute('hsrc'));
                        }

                        aImages[i].onmouseout = function() {
                                if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
                                this.setAttribute('src', sTempSrc);
                        }
                }
        }
}

window.onload = initRollovers;

/*
 open_window()
 opens a new pop-up window
*/
function open_window(page_url, page_name, window_width, window_height, scrollbar_value, is_center) {
    // set window position
    var window_pos_x = 20;
    var window_pos_y = 20;

    // if popup is center
    if (is_center == 'yes') {
        window_pos_x = (screen.width / 2) - (window_width / 2);
        window_pos_y = (screen.height / 2) - (window_height / 2);
    }

    // open the window
    popup_window = this.open(page_url, page_name, "toolbar=no,status=no,menubar=no,location=no,scrollbars=" + scrollbar_value + ",resizable=no,width=" + window_width + ",height=" + window_height + ",screenX=" + window_pos_x + ",screenY=" + window_pos_y + ",left=" + window_pos_x + ",top=" + window_pos_y);

    // resize the window, in case successive calls are made to same window
    popup_window.resizeTo(window_width + 6, window_height + 54);

    // focus popup
    popup_window.focus();
}

/*
 anti_spam_email()
 protects email from spam bots
*/

function anti_spam_email(user,domain) {
    var username = user;
    var hostname = domain;
    var linktext = username + "&#064;" + hostname;
    document.write("<a href=" + "mail" + "to:" + username +"&#064;" + hostname + ">" + linktext + "</a>");
}

/*
 showElement()
 shows DOM element
*/

function showElement(obj){
    // verify if getElementById works
    if (!document.getElementById) return

    // get element by ID
    var my_element = document.getElementById(obj);

    // show the element
    my_element.style.display = "block";
}

/*
 hideElement()
 hides DOM element
*/

function hideElement(obj){
    // verify if getElementById works
    if (!document.getElementById) return

    // get element by ID
    var my_element = document.getElementById(obj);

    // show the element
    my_element.style.display = "none";
}

function gethttp () {
	var xmlHttp = null;
	if (window.XMLHttpRequest) {
		// If IE7, Mozilla, Safari, etc: Use native object
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) {
			// ...otherwise, use the ActiveX control for IE5.x and IE6
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function gotourl(url) {
	var x = gethttp();
	x.open("get","/getgeoip.sn");
	x.onreadystatechange = function() {
		if (x.readyState == 4) {
			str=x.responseText;
    			
			if (str.indexOf('CA')!= -1)  {
			window.open(url + x.responseText);
			} else {
			window.open(url + 'US');
                        }
			
		}
	}
	x.send(null);
}
