/* Utils. Copyright by ADenis (adeniss@ukr.net) */

/* --------------------------------------------------
	Coordinates routine
-------------------------------------------------- */

function getX(object){
	return findPos(object)[0];
}

function getY(object){
	return findPos(object)[1];
}

function findPos(obj, _debug) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		curleft -= obj.scrollLeft;
		curtop -= obj.scrollTop;
		
		var obj2 = obj;
		
		while (obj2 = obj2.parentNode) {
			if (obj2.tagName && obj2.tagName != "HTML" && obj2 != document.body) {
				//if (_debug)	debug(obj2 + " " + obj2.tagName + " : " + obj2.offsetTop + " + " + obj2.scrollTop + "    " + obj2.offsetLeft + " + " + obj2.scrollLeft);
				curleft -= (obj2.scrollLeft) ? obj2.scrollLeft : 0;
				curtop -= (obj2.scrollTop) ? obj2.scrollTop : 0;
			}
		}
		
		while (obj = obj.offsetParent) {
			if (_debug)	debug(obj + " " + obj.tagName + " : " + obj.offsetTop + " + " + obj.scrollTop + "    " + obj.offsetLeft + " + " + obj.scrollLeft);
			curleft += (obj.offsetLeft) ? obj.offsetLeft : 0;
			curtop += (obj.offsetTop) ? obj.offsetTop : 0;
			curleft += (obj.currentStyle && !isNaN(parseInt(obj.currentStyle.borderLeftWidth))) ? parseInt(obj.currentStyle.borderLeftWidth) : 0;
			curtop += (obj.currentStyle && !isNaN(parseInt(obj.currentStyle.borderTopWidth))) ? parseInt(obj.currentStyle.borderTopWidth) : 0;
			
			/*
			curleft -= (obj.scrollLeft) ? obj.scrollLeft : 0;
			curtop -= (obj.scrollTop) ? obj.scrollTop : 0;*/
		}
	}
	
	return [curleft,curtop];
}

function getMouseX(object){
	if(object && MOUSE){
		var x = getX(object);
		return MOUSE.x - x;	
	}
	return false;
}

function getMouseY(object){
	if(object && MOUSE){
		var y = getY(object);
		return MOUSE.y - y;	
	}
	return false;
}

/* --------------------------------------------------
	DOM nodes
-------------------------------------------------- */

function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(element);
  }
  return results.length < 2 ? results[0] : results;
}

function isChildOf(object, child){
	if(object){
		var childs = object.childNodes;
		var length = childs.length;
		
		for (var i = 0; i < length; i++) {
			if(childs[i] == child)
				return true;
			else
			if(isChildOf(childs[i], child))
				return true;
		}
	}
	return false;
}

function getChildById(object, id){
    if(!object) {
        return false;
    }
	if(object.id)
	if(object.id == id)
		return object;
		
	if(object){
		var childs = object.childNodes;
		var length = childs.length;
		
		for (var i = 0; i < length; i++) {
			var result = getChildById(childs[i], id);
			if(result)
				return result;
		}
	}
	return false;
}

function getChildByName(object, name){
	if(object.name){
		if(object.name == name)
			return object;
	}else{
		if(object.getAttribute)
		if(object.getAttribute("name") == name)
			childs.push(object);
	}
		
	if(object){
		var childs = object.childNodes;
		var length = childs.length;
		
		for (var i = 0; i < length; i++) {
			var result = getChildByName(childs[i], name);
			if(result)
				return result;
		}
	}
	return false;
}

function getChildsByName(object, name){
	var childs = new Array();
	
	if(object.name){
		if(object.name == name){
			childs.push(object);
		}
	}else{
		if(object.getAttribute)
		if(object.getAttribute("name") == name)
			childs.push(object);
	}
	
	if(object){
		var _childs = object.childNodes;
		var length = _childs.length;
		
		for (var i = 0; i < length; i++) {
			var array = new Array();
			array = getChildsByName(_childs[i], name);
			for(var j in array){
				childs.push(array[j]);
			}
		}
	}
	
	return childs;	
}

function getParentByClassName(object, className) {
	while (object = object.parentNode) {
		if (hasClass(object, className)) {
			return object;
		}
	}	
	return null;
}

function getChildByClassName(object, className) {
	var childs = object.childNodes;
	var count = childs.length;
	
	for (var i = 0; i < count ; i++) {
		if(hasClass(childs[i], className)){
			return childs[i];
		}
	}
	
	return null;
}

function findChildByClassName(object, className)
{
    if (object == null) return null;
	if(object.className)
    if(object.className.toLowerCase() == className.toLowerCase()) return object;
    if (object.nodeType != 1) return null;
    if (!object.hasChildNodes()) return null;
    var kids = object.childNodes;
    var theKid = null;
    for (var i = 0; i < kids.length; ++i)
    {
        theKid = findChildByClassName(kids[i], className);
        if (theKid != null) break;
    }
    return theKid;
}

function getChildsByClassName(object, className) {
	var childs = object.childNodes;
	var count = childs.length;
	var array = new Array();
	
	for (var i = 0; i < count ; i++) {
		if(hasClass(childs[i], className)){
			array.push(childs[i]);
		}
	}
	
	return array;
}

function getObjectByName(name){
	var array = document.getElementsByName(name);
	return array[0];
}

function getObjectById(id){
	var object = document.getElementById(id);
	return object;
}

function getParentByTagName (object, tagName) {
	while (object = object.parentNode) {
		if (object.tagName && object.tagName.toLowerCase() == tagName.toLowerCase()) {
			return object;
		}
	}	
	
	return null;
}

function getElementsById(sId) {
    var outArray = new Array();	
    if(typeof(sId)!='string' || !sId) {
        return outArray;
    }
   
    if (document.evaluate) {
        var xpathString = "//*[@id='" + sId.toString() + "']"
        var xpathResult = document.evaluate(xpathString, document, null, 0, null);
        while ((outArray[outArray.length] = xpathResult.iterateNext())) { }
        outArray.pop();
    } else if (document.getElementsByTagName) {
        var aEl = document.getElementsByTagName('*');	
        for (var i=0,j=aEl.length; i<j; i+=1) {
            if(aEl[i].id == sId ) {
                outArray.push(aEl[i]);
            }
        }
    } else if (document.all) {
        for (var i=0,j=document.all[sId].length; i<j; i+=1) {
            outArray[i] =  document.all[sId][i];
        }
    }
   
    return outArray;
}

/* --------------------------------------------------
	DOM attributes
-------------------------------------------------- */

function setAttribute(object, attribute, value){
	try{
		if(object[attribute] != value){
			object[attribute] = value;
			_fireEvent(object, "on"+attribute, value);
			return true;
		}
	}catch(e){
		//alert("Error on setAttribute("+object+","+attribute+","+value+")");
	}	
	return false;
}

function setNodeAttribute(object, attribute, value){
	return setAttribute(object, attribute, value);
}

function getNodeAttribute(node, attributeName, defaultValue){
	var value = node.getAttribute(attributeName)
	
	if(value == undefined || value == null)
		value = defaultValue;
	
	return value;
}

function _fireEvent(object, _event, data){
	if(object[_event]){
		object[_event](data);
	}
}

function getValueSuffix(value){
	var num = (parseFloat(value)).toString();
	var suffix = "";
	if(!isNaN(num))
	if(num.length < (value.toString()).length)
		suffix = value.substr(value.indexOf(num) + num.length, value.length - num.length);
	return suffix;
}

/* --------------------------------------------------
	Data updater
-------------------------------------------------- */

function formToRequest(form){
	var str = "";
	var objects = form.elements;
	
	var count = objects.length;
	for(var i=0; i<count; i++){
		if(objects[i])
		if(objects[i].tagName)
		if(((objects[i].tagName == "INPUT") &&
			(objects[i].type == "hidden" ||
			 objects[i].type == "text" ||
			 objects[i].type == "checkbox" ||
			 objects[i].type == "radio" ||
			 objects[i].type == "password")) ||
		     objects[i].tagName == "SELECT" ||
			 objects[i].tagName == "TEXTAREA"){
			
			if(objects[i].disabled)
				continue;
			
			if(objects[i].tagName == "SELECT" && objects[i].multiple){
				var z = 0;
				var length = objects[i].childNodes.length;
				
				for (var j = 0; j < length; j++) {
					if(objects[i].childNodes[j].tagName)
					if(objects[i].childNodes[j].tagName == "OPTION"){
						if(str != "")
							str += "&";

						if(objects[i].childNodes[j].selected){							
							//alert(objects[i].childNodes[j].value + " " + objects[i].childNodes[j].selected);
							str = str + objects[i].name + "[" + z + "]=" + replaceSystemSymbols(objects[i].childNodes[j].value);
						}else{
							str = str + objects[i].name + "[" + z + "]=";
						}
						z++;
					}
				}				
			}else{
				if(objects[i].tagName == "TEXTAREA"){
					try{
						var oEditor = FCKeditorAPI.GetInstance(objects[i].name);
						if(oEditor){
							objects[i].value = oEditor.GetXHTML();
							//alert(objects[i].value);
						}
							
					}catch(e){						
					}
				}

				if((objects[i].type == "radio") && !objects[i].checked){
					continue;
				}
				
				if(objects[i].type == "checkbox" && !objects[i].checked)
					objects[i].value = "";

				if(str != "")
					str += "&";
				str = str + objects[i].name + "=" + replaceSystemSymbols(objects[i].value);
			}
		}
		j++;
	}
	
	//alert(escape("\""));
	//alert(str);
	
	return str;
}

function replaceSystemSymbols(value){
	/*value = customReplace(value, "<", "");
	value = customReplace(value, ">", "");
	value = customReplace(value, "&quot;", "");
	value = customReplace(value, "&laquo;", "");
	value = customReplace(value, "&raquo;", "");
	value = customReplace(value, "&mdash;", "");
	value = customReplace(value, "&dash;", "");
	value = customReplace(value, "&hellip;", "");
	value = customReplace(value, "&", "");
	value = customReplace(value, "/", "");
	value = customReplace(value, "\\", "");
	value = customReplace(value, ":", "");*/
	value = customReplace(value, "&", "@amp@");
		
	return value;
}

function showErrorMessage(name, message){
	alert(message);
	
	setFocusByNameWithDelay(name, 100);
}

function reloadMediaLoadFrame(loaderId, className, template, id){				
	var frame = document.getElementById(loaderId);
	var location = window.frames[0].document.location.href;
	if(location.indexOf(frame.src) < 0){
		window.frames[0].document.location.href = frame.src;
		
		dataUpdater.updateObject(className, template, false, "/?"+className+"[action]=edit", id, false, false);
	}				
}

function reloadMediaUploadFrame(loaderId, className, template, id){				
	reloadMediaLoadFrame(loaderId, className, template, id);				
}

/* --------------------------------------------------
	Forms
-------------------------------------------------- */

function checkBoxesByName (name, checked) {
	var checkboxes = document.getElementsByName(name);
	
	for (var i = 0; i < checkboxes.length; i++) {
		var checkbox = checkboxes[i];
		checkbox.checked = checked;
		if (checkbox.onclick)
			checkbox.onclick();
		if (checkbox.onchange)
			checkbox.onchange();
	}
}

function getCheckedBoxesValuesById (id) {
	var checkboxes = getElementsById(id);
	var values = new Array();
	
	for (var i = 0; i < checkboxes.length; i++) {
		var checkbox = checkboxes[i];
		if (checkbox.checked)
			values.push(checkbox.value);
	}
	
	return values;
}

function getCheckedBoxesValuesByName (name) {
	var checkboxes = document.getElementsByName(name);
	var values = new Array();
	
	for (var i = 0; i < checkboxes.length; i++) {
		var checkbox = checkboxes[i];
		if (checkbox.checked)
			values.push(checkbox.value);
	}
	
	return values;
}

function getRadioValue(name) {
	var radios = document.getElementsByName(name);
	for (var i = 0; i < radios.length; i++) {
		if(radios[i].checked)
			return radios[i].value;
	}
}

function initRichText(name){
	var oFCKeditor = new FCKeditor(name) ;
	oFCKeditor.BasePath = "templates/js/FCKeditor/";
	oFCKeditor.Width = "100%";
	oFCKeditor.Height = "100%";
	oFCKeditor.ReplaceTextarea();
}

function setFocusByNameWithDelay(name, delay){
	setTimeout("setFocusByName('"+name+"')", delay);
}

function setFocusByName(name){
	var object =  getObjectByName(name);
	if(!object){
		object = getObjectById(name);
	}
	
	if(object){
		try{
			object.focus();
		}catch(e){
		}
	}
}

function isFieldsMatch(field1, field2, message){

	if($(field1) && $(field2) && $(field1).value != $(field2).value){
		alert(message);
		$(field2).focus();
		return false;
	}else{
		return true;
	}
}

function getSelectedOptions(select) {
	var length = select.childNodes.length;
	var options = new Array();
	
	for (var i = 0; i < length; i++) {
		if(select.childNodes[i].tagName)
		if(select.childNodes[i].tagName == "OPTION"){
			if(select.childNodes[i].selected){							
				options.push(select.childNodes[i]);
			}
		}
	}	
	
	return options;	
}

function fromStringToBoolean(value) {
	var boolean = value;
	if (value == "false" || value == "0" || value === 0) {
		boolean = false;
	} else if (value == "true" || value == "1" || value === 1){
		boolean = true;
	}
	
	return boolean;
}

function disableControl(button, disabled) {
	var previouslyDisabled = (button.className.indexOf("disabled") > -1);
	(disabled === false) ?  removeClass($(button), "disabled") : addClass($(button), "disabled");
	
	if (button.tagName == "A") {
		if (disabled === false && (!getNodeAttribute(button, "_onclick", false) && !getNodeAttribute(button, "_href", false))) {
			return;
		}
		
		/*
		debug("disableControl");
		debug("previouslyDisabled " + previouslyDisabled);
		debug("disabled " + disabled);
		debug("onclick " + button["onclick"]);
		debug("href " + button["href"]);
		debug("_onclick " + getNodeAttribute(button, "_onclick", false));
		debug("_href " + getNodeAttribute(button, "_href", false));
		*/
		
		if (button["onclick"] && disabled !== false && !previouslyDisabled) {
			button.setAttribute("_onclick", button["onclick"]);
		}
		if (disabled !== false && !previouslyDisabled) {
			button.setAttribute("_href", button.href);
		}
		
		
		button["onclick"] = (disabled === false) ? button.getAttribute("_onclick") : "return false";
		button.href = (disabled === false) ? button.getAttribute("_href") : "javascript:void(0)";
		/*
		debug("onclick " + button["onclick"]);
		debug("href " + button["href"]);
		debug("_onclick " + getNodeAttribute(button, "_onclick", false));
		debug("_href " + getNodeAttribute(button, "_href", false));
		*/
	} else {
		button.disabled = (disabled === false) ? false : true;
	}
}

function switchBooleanCheckboxValue (checkbox) {
	checkbox.value = (checkbox.value == "true")?"false":"true";
}

function setFocusOnInput(id) {
   if ($(id)) {
       $(id).select();
       $(id).focus();
   }
}

function applyListFilter(input, list) {
	if (input && list) {
		var value = input.value.toLowerCase();
		var items = list.childNodes;
		var count = items.length;
		
		for (var i = 0; i < count; i++) {
			if (items[i] && getNodeAttribute(items[i], "value", null)) {
				var itemValue = getNodeAttribute(items[i], "value", null).toLowerCase();
				(value == "" || itemValue.indexOf(value) == 0 || itemValue.indexOf(" " + value) > -1) ? removeClass(items[i], "hidden") : addClass(items[i], "hidden");
			}
		}
	}
}

/* --------------------------------------------------
	Styles related
-------------------------------------------------- */

function toPx(value) {
	return Math.round(value) + "px";
}

function hasClass (objId, className) {
	var obj = $(objId);
	if(obj && obj.className) {
		if(obj.className.indexOf(className) > -1 ) return true;
	}
	
	return false
}

function addClass (objId, className) {
	var obj = $(objId);
	if(obj) {
		if(obj.className.indexOf(className) < 0 ) obj.className += " " + className;
	}
}

function removeClass (objId, className) {
	var obj = $(objId);
	if(obj) {
		if(obj.className.indexOf(className) > -1 ) {
			obj.className = obj.className.replace(className, "");
			obj.className = obj.className.trim();
		};
	}
}

function showChilds(object, show){
	var display = show?"block":"none";
	var childs = object.childNodes;
	var length = childs.length;
	
	for (var i = 0; i < length; i++) {
		childs[i].style.display = display;
	}
}

function displayChilds(object, display, nodeType){	
	var childs = object.childNodes;
	var length = childs.length;
	
	for (var i = 0; i < length; i++) {

		if(childs[i].style)
		if(!nodeType || (nodeType && childs[i].tagName == nodeType)){
			childs[i].style.display = display;
		}
	}
}

var UIStates = new Array();

function saveUIState(object){
	UIStates[object.id] = new Object();
	
	UIStates[object.id].className = object.className;
	
	if (object.tagName) {
		if (object.tagName.toLowerCase() == "input" || object.tagName.toLowerCase() == "button") {
			UIStates[object.id].value = object.value;
			UIStates[object.id].disabled = object.disabled;
			UIStates[object.id].checked = object.checked;
			UIStates[object.id].selected = object.selected;
			UIStates[object.id].innerHTML = object.innerHTML;
		}
	}
}

function restoreUIStates() {
	for(var i in UIStates) {
		var object = $(i);
		if (object) {
			object.className = UIStates[i].className;
			
			if (object.tagName) {
				if (object.tagName.toLowerCase() == "input" || object.tagName.toLowerCase() == "button") {
					object.value = UIStates[i].value;
					object.disabled = UIStates[i].disabled;
					object.checked = UIStates[i].checked;
					object.selected = UIStates[i].selected;
					if (object.innerHTML && object.innerHTML != "") {
						object.innerHTML = UIStates[i].innerHTML;
					}
				}
			}			
		}
	}	
}

/* --------------------------------------------------
	Events
-------------------------------------------------- */

function disableEventPropagation(event) {
    event = (event) ? event : (window.event);
    event.cancelBubble = true;
    if (event.stopPropagation) {
        event.stopPropagation();
    }

    event.returnValue = false;

    if (event.preventDefault) {
        event.preventDefault();
    }
}

/* --------------------------------------------------
	Misc
-------------------------------------------------- */

function customReplace(str, search, replace){	
	var array = str.split(search);
	var count = array.length;
	var newStr = "";
	if(count > 0){
		for(var i=0; i<count; i++){
			if(i > 0)
				newStr += replace;
			newStr += array[i];
		}
	}else{
		newStr = str;
	}
	return newStr;
}

function sendMail(user, server, subject){
	var url = "mailto:"+user+"@"+server;
	if(subject)
		url += "?subject="+subject;
	window.location.href = url;
	
	return false;
}

function isFlashPlayerInstalled() {	
	var flashPlayerIsInstalled = false;
	var msie7 = (parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5)) == 7);
	
	if (msie7)
		flashPlayerIsInstalled = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			flashPlayerIsInstalled = true;
		}
	}
	
	return flashPlayerIsInstalled;	
}

function parseFunction(expression) {
	if (typeof(expression) == "string") {
		expression = new Function(expression);
	}
	
	return expression;
}

function getTimestamp() {
	return (new Date()).getTime();
}


/* --------------------------------------------------
	JS extensions
-------------------------------------------------- */

String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}

String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}

Array.prototype.indexOf = function (value) {	
	for (var i in this) {
		if(value == this[i]) {
			return i;
		}
	}
	
	return -1;
};

Array.prototype.max = function (subElement) {	
	var max = (this.length) ? ((subElement) ? this[0][subElement] : this[0]) : null;
	for (var i in this) {
		var value = (subElement) ? this[i][subElement] : this[i];
		max = (value > max) ? value : max;
	}	
	return max;
};

Array.prototype.min = function (subElement) {	
	var min = (this.length) ? ((subElement) ? this[0][subElement] : this[0]) : null;
	for (var i in this) {
		var value = (subElement) ? this[i][subElement] : this[i];
		min = (value < min) ? value : min;
	}	
	return min;
};

Date.prototype.getWeek = function () {
	var determinedate = new Date(this.getFullYear(), this.getMonth(), this.getDate());
	var D = determinedate.getDay();
	if(D == 0) D = 7;
	determinedate.setDate(determinedate.getDate() + (4 - D));
	var YN = determinedate.getFullYear();
	var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
	var WN = 1 + Math.floor(ZBDoCY / 7);
	return WN;
}

/*
Object.prototype.merge = function(target) {
	for (var i in target) {
		this[i] = target[i];
	}
}
*/

/* --------------------------------------------------
	Debug
-------------------------------------------------- */

var debugPopup = null;
function showInDebugWindow(str){
	if(!debugPopup || debugPopup.closed){
		debugPopup = window.open("about:blank");
	}	
	debugPopup.document.body.innerHTML += str;
}

var debugDiv = null;
function showInDebugDiv(str){
	if(!debugDiv){
		debugDiv = document.createElement("DIV");
		debugDiv.style.position = "absolute";
		debugDiv.style.left = "0px";
		debugDiv.style.top = "0px";
		debugDiv.style.border = "1px solid black";
		document.body.appendChild(debugDiv);
		
	}	
	debugDiv.innerHTML += str;
}

function displayAttributes(object){
	var str = "";
	
	if(object){
		if(object.tagName)
			str += object.tagName + ": " + object + ": ";
		for(var i in object.attributes){
			str += object.attributes[i].name + "="+ object.attributes[i].value + " ";
		}
	}
	alert(str);
}

function displayArray(object){
	var str = "";
	
	if(object){
		if(object.tagName)
			str += object.tagName + ": " + object + ": ";
			
		for(var i in object){
			try{
				str += (i + "="+ object[i] + " ") + "\n";
			}catch(e){
				str += "Unable to get " + i + "\n";
				str += e + "\n";
			}
		}
		//var popup = window.open("");
		//popup.document.write(str);
	}
	alert(str);
}

var debugTimers = new Array();

function initiateTimer(timerName) {
	debugTimers[timerName] =  new Date();
}

function getTimerValue(timerName) {
	var timer = (debugTimers[timerName]) ? debugTimers[timerName] : new Date();
	
	return ((new Date()).getTime() - timer.getTime());
}

// FUNCTION: parseHTMLArgs()
//
// DESCRIPTION: Returns a string of param/value pairs from the 
// location.search query string
////////////////////////////////////////////////////////////////////////////////
function parseHTMLArgs()
{
    if( document.location.search.length > 0 )
    {
	    //skip the '?'
        args = parseArgs(document.location.search.substring(1));

        return args;
    }
    else return "";
}

////////////////////////////////////////////////////////////////////////////////
// FUNCTION: parseArgs(string)
//
// DESCRIPTION: Returns JS object of param/value pairs from "string" of syntax
// "foo=bar&fee=bat&fie=bas"
////////////////////////////////////////////////////////////////////////////////
function parseArgs(string)
{
    var args = new Object();
    var pairs = string.split("&");
        
    for(var i = 0; i < pairs.length; i++)
    {
        // Look for "name=value"
        var pos = pairs[i].indexOf('='); 
        // if not found, skip to next
        if (pos == -1) continue; 
        // Extract the name
        var argname = pairs[i].substring(0,pos); 
    
        // Extract the value
        var value = unescape( pairs[i].substring(pos+1) );
        // Store as a property
        args[argname] = value; 
    
        //alert(argname + " = " + value);
    }
    return args;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

 var xScroll, yScroll;

 if (window.innerHeight && window.scrollMaxY) {
 xScroll = document.body.scrollWidth;
 yScroll = window.innerHeight + window.scrollMaxY;
 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
 xScroll = document.body.scrollWidth;
 yScroll = document.body.scrollHeight;
 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
 xScroll = document.body.offsetWidth;
 yScroll = document.body.offsetHeight;
 }

 var windowWidth, windowHeight;
 if (self.innerHeight) { // all except Explorer
 windowWidth = self.innerWidth;
 windowHeight = self.innerHeight;
 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
 windowWidth = document.documentElement.clientWidth;
 windowHeight = document.documentElement.clientHeight;
 } else if (document.body) { // other Explorers
 windowWidth = document.body.clientWidth;
 windowHeight = document.body.clientHeight;
 }

 // for small pages with total height less then height of the viewport
 if(yScroll < windowHeight){
 pageHeight = windowHeight;
 } else {
 pageHeight = yScroll;
 }

 // for small pages with total width less then width of the viewport
 if(xScroll < windowWidth){
 pageWidth = windowWidth;
 } else {
 pageWidth = xScroll;
 }


 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
 return arrayPageSize;
}

function isIE() {
	if(navigator.userAgent.indexOf('MSIE ')>=0 && navigator.userAgent.indexOf('Opera')<0) return true;
	return false;
}


function isIE6() {
	if(navigator.userAgent.indexOf('MSIE 6.0')>=0 && navigator.userAgent.indexOf('Opera')<0) return true;
	return false;
}

function printPage() {
    if (window.print) {
        window.print();
    } else {
        alert("Sorry, your browser doesn't support this feature.");
    }
}
