/* ========================================================================= */
/* ****	Website Builder - Copyright (C)2007-2009 by EasyStar Software
/* ========================================================================= */

/* Utility functions */

function getMyWidth() {
	var myWidth = 0;
	
	if (typeof(window.innerWidth) == 'number') {
		//Non-IE
		myWidth = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	
	return myWidth;
}

function getMyHeight() {
	var myHeight = 0;
	
	if (typeof(window.innerHeight) == 'number') {
		//Non-IE
		myHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	
	return myHeight;
}

function getOffsetX() {
	var scrOfX = 0;

	if (typeof(window.pageYOffset) == 'number') {
		//Netscape compliant
		scrOfX = window.pageXOffset;
	} else if (document.body && document.body.scrollLeft) {
		//DOM compliant
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement && document.documentElement.scrollLeft) {
		//IE6 standards compliant mode
		scrOfX = document.documentElement.scrollLeft;
	}

	return scrOfX;
}

function getOffsetY() {
	var scrOfY = 0;

	if (typeof(window.pageYOffset) == 'number') {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if (document.body && document.body.scrollTop) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}

	return scrOfY;
}

function leftOffset(bodyWidth) {
	return Math.floor((getMyWidth() - bodyWidth) / 2);
}

function rePosition(elementID, bodyWidth, addToOffset) {
	document.getElementById(elementID).style.left = (leftOffset(bodyWidth) + addToOffset) + 'px';
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function toggle_visibility(id) {
    var t = document.getElementById(id);
    if (t.style.display == 'inline')
        t.style.display = 'none';
    else
        t.style.display = 'inline';
}

function toggle_replace(id, replaceId, replaceTxtVis, replaceTxtInVis) {
    var t = document.getElementById(id);
    var r = document.getElementById(replaceId);
    if (t.style.display == 'inline') {
        t.style.display = 'none';
        r.innerHTML = replaceTxtInVis;
    } else {
        t.style.display = 'inline';
        r.innerHTML = replaceTxtVis;
    }
}

function toggle_img(id, replaceId, replaceImgSrcVis, replaceImgSrcInVis) {
    var t = document.getElementById(id);
    var r = document.getElementById(replaceId);
    if (t.style.display == 'inline') {
        t.style.display = 'none';
        r.src = replaceImgSrcInVis;
    } else {
        t.style.display = 'inline';
        r.src = replaceImgSrcVis;
    }
}

function ajaxCall(url, param, value, after) {
    ajaxObj = new sack();
    ajaxObj.requestFile = url;
    ajaxObj.setVar(param,value);
    ajaxObj.onCompletion = after;
    ajaxObj.runAJAX();
}
