var windowHeight;
var windowWidth;

function fixLayout() {
	windowWidth = document.documentElement.clientWidth;
	if (window.opera) windowWidth = document.body.clientWidth;
	if (navigator.appVersion.indexOf("Safari") != -1) windowWidth = self.innerWidth;

	windowHeight = document.documentElement.clientHeight;
	if (window.opera) windowHeight = document.body.clientHeight;
	if (navigator.appVersion.indexOf("Safari") != -1) windowHeight = self.innerHeight;

}

function onLoad() {
	MM_preloadImages('images/home-on.gif',
					 'images/products-on.gif',
					 'images/see-in-action-on.gif',
					 'images/register-copy-on.gif',
					 'images/download-on.gif',
					 'images/support-on.gif',
					 'images/developers-on.gif');
}

function trim(str) {
	if (str == null) return null;
	return str.replace(/^\s*|\s*$/g,"");
}


function showHideDiv(id) {
	var obj = MM_findObj(id);
	if (obj.style.display == 'none') {
		obj.style.display = '';
	} else {
		obj.style.display = 'none';
	}
}

function showDiv(id) {
	var obj = MM_findObj(id);
	obj.style.display = '';
}

function hideDiv(id) {
	var obj = MM_findObj(id);
	obj.style.display = 'none';
}


function emailCheck(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
		return (true)
	}
	return (false)
}

function submitForm(formName) {
    var f1 = MM_findObj(formName);
    try {
        if (!f1.onsubmit()) {
        	return;
        }
    } catch (e) {
        // do nothing sier.
    }
    f1.submit();
}

function undoHtmlSpecialChars(str) {
	str = str.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
	return str;
}

function nl2br(str) {
	str = str.replace(/\n/g, "<br />");
	return str;
}

function br2nl(str) {
	str = str.replace(/<br \/>/g, "\n");
	str = str.replace(/<br>/g, "\n");
	str = str.replace(/<br\/>/g, "\n");
	return str;
}

function getWidth(obj) {
	var w = obj.getOffsetWidth;
	if (w == null || w == 0) {
		var sw = obj.style.width;
		
		if (sw != null && sw.indexOf("px") > 0) {
			w = sw.substr(0, sw.indexOf("px"));
		}
	}
	return parseInt(w);
}

function getHeight(obj) {
	var w = obj.getOffsetHeight;
	if (w == null || w == 0) {
		var sw = obj.style.height;
		if (sw != null && sw.indexOf("px") > 0) {
			w = sw.substr(0, sw.indexOf("px"));
		}
	}
	return parseInt(w);
}

function getAbsolutePosition(element){
    var ret = new Point();
    for(; 
        element && element != document.body;
        ret.translate(element.offsetLeft, element.offsetTop), element = element.offsetParent
        );
        
    return ret;
}

function Point(x,y){
        this.x = x || 0;
        this.y = y || 0;
        this.toString = function(){
            return '('+this.x+', '+this.y+')';
        };
        this.translate = function(dx, dy){
            this.x += dx || 0;
            this.y += dy || 0;
        };
        this.getX = function(){ return this.x; }
        this.getY = function(){ return this.y; }
        this.equals = function(anotherpoint){
            return anotherpoint.x == this.x && anotherpoint.y == this.y;
        };
}

function myEncode(str) {
	if (str == null) {
		return "";
	}
	str = encodeURI(str);
	str = str.replace(new RegExp("&",'g'), "%26");
	str = str.replace(new RegExp(";",'g'), "%3B");
	str = str.replace(new RegExp("[?]",'g'), "%3F");
	return str;
}

if (window.addEventListener) {
	window.addEventListener("resize",fixLayout,false);
	window.addEventListener("load",onLoad,false);
} else if (window.attachEvent && !window.opera){
	window.attachEvent("onresize",fixLayout);
	window.attachEvent("onload",onLoad);
}
