/******************************************************************************/
/*
    © 2005-2008 Grafikstudio
    All rights reserved

    Making *ANY* changes in this document will cause loss of 
    12-month warranty for faultless site functioning and
    free of charge service during warranty period will be no 
    longer available!
    Any changes shoud be first consulted with and accepted by
    Grafikstudio representative.

    Stylesheet for ProCMS visitor-side pages.
    Version 3.0 or greater only.

    * File encoding: UTF-8
	* Script compatibility: Gecko 1.8
	* General functions are stored in scripts.js
	* Function used while building menus are stored in menus.js
*/
/******************************************************************************/
//	GLOBAL VARIABLES DEFINITIONS
var httpRequest = null;
//	FUNCTION DETECTING MSIE BROWSER
function isIE(){
	if(-1 != navigator.userAgent.indexOf("MSIE")) { return true; } else { return false; }
}
//	GENERAL DHTML FUNCTIONS MODIFYING CSS CLASSES AND STYLESD
function div_display (name) {
	document.getElementById(name).style.display="block";
}
function div_hide (name) {
	document.getElementById(name).style.display="none";
}
function hoverClass(obj) {
	var is_selected = obj.className.indexOf("Hover");
	if (  is_selected == -1 ) {
		n = obj.className;
		obj.className = n+'Hover';
	}
}
function unhoverClass(obj) {
	var n = obj.className.indexOf("Hover");
	if ( n != -1 ) {
		cls = obj.className.substring(0,n);
		obj.className = cls;
	}
}
//	FUNCTIONS USED IN SPECIFIC MODULES
function search_select_all() {
	// search engine module
	for (var c=0;c<document.forms["search_form"].elements.length;c++) {
		var e = document.forms["search_form"].elements[c];
		if (e.name != 'search_option_allbox') {
			e.checked = document.search_form.search_option_allbox.checked;
		}
	}
}
function pollVote(formname,maxpicks){
	//	polls module in main frame
	var f=document.forms[formname];
	var picks=0;
	for (i=0;i<f.elements.length;i++) {
		if ( f.elements[i].getAttribute("type")=="checkbox" && f.elements[i].checked ) { picks++; }
		if ( picks >= maxpicks ) { f.submit(); return true; }
	}
}
//	CROSS-BROWSER FUNCTIONS USED TO DETECT VARIOUS OBJECTS' PROPERTIES 
function screenWidth() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return window.innerWidth;
	} else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			return document.documentElement.clientWidth;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			return document.body.clientWidth;
			}
		}
	}
}
function screenHeight() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return window.innerHeight;
	} else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			return document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			return document.body.clientHeight;
			}
		}
	}
}
function getTextContent(elm) {
	return ( elm.textContent || elm.innerText || elm.text );
}
function getVerticalOffset() {
	if ( window.pageYOffset ) {
		return window.pageYOffset;
	} else if ( document.body.scrollTop ) {
		return document.body.scrollTop;
	} else if ( document.documentElement.scrollTop ) {
		return document.documentElement.scrollTop;
	} else {
		return 0;
	}
}
function createNewElement(sTag){
	if (isIE()) { obj = document.createElement(sTag.toUpperCase()); }
	else { obj = document.createElement(sTag); }
	return obj;
}
//	FUNCTIONS USED TO SHOW PICTURE PREVIEW FLOATING WINDOW
function pictureViewFullscreenStateChange(picID) {
	if ( httpRequest.readyState == 4 ) {
		if ( httpRequest.status == 200 ) {
			ch = httpRequest.responseXML.documentElement;
			for ( i=0;i<ch.childNodes.length;i++  ) {
				switch ( ch.childNodes[i].nodeName ){
					case "width": var imageX = getTextContent (ch.childNodes[i]); break;
					case "height":  var imageY = getTextContent (ch.childNodes[i]); break;
					case "description":  var imageDescription = getTextContent (ch.childNodes[i]); break;
				}
			}
			pictureViewFullscreenAppend(picID,imageX,imageY,imageDescription);
		} else {
			pictureViewFullscreenError();
		}
	} else {
		pictureViewFullscreenLoading();
	}
}
function pictureViewFullscreenLoading() {
	objDescription = document.getElementById ('imagePreviewDescription');
	objDescription.innerHTML = "<img class=\"imagePreviewLoading\" src=\""+jsPageAdress+"/img/loading.gif\" width=\"150\" height=\"15\" border=\"0\" alt=\"\" />";
}
function pictureViewFullscreenError() {
	alert ( "XMLHttpRequest: Error while loading XML data file." );
	objDiv = document.getElementById ('imagePreviewDiv');
	document.body.removeChild (objDiv);
}
function pictureViewFullscreen(picID) {
	if ( httpRequest ) { return false; }
	objDiv = createNewElement('div');
	objDiv.id = 'imagePreviewDiv';
	objDiv.className = 'imagePreview';
	document.body.appendChild (objDiv);
	objDescription = createNewElement('div');
	objDescription.id = 'imagePreviewDescription';
	objDescription.className = 'imagePreviewDescription';
	objDiv.appendChild (objDescription);
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (!isIE()) { httpRequest.overrideMimeType('text/xml'); }
	} else if (window.ActiveXObject) { // IE
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (!httpRequest) {
		alert ( "XMLHttpRequest: Cannot create an XMLHTTP instance." );
		return false;
	}
	httpRequest.open('GET', jsPageAdress+'/module_picxml.php?gid='+picID, true);
	httpRequest.send('gid='+picID);
	httpRequest.onreadystatechange = function(){pictureViewFullscreenStateChange(picID);};
}
function pictureViewFullscreenAppend(picID,imgWidth,imgHeight,imgAlt) {
	if ( imgWidth > (screenWidth()-25) ) {
		imgHeight = Math.floor((imgHeight/imgWidth)*(screenWidth()-25));
		imgWidth = screenWidth()-25;
	}
	if ( imgHeight > (screenHeight()-50) ) {
		imgWidth = Math.floor((imgWidth/imgHeight)*(screenHeight()-50));
		imgHeight = screenHeight()-50;
	}
	objDiv = document.getElementById ('imagePreviewDiv');
	objDescription = document.getElementById ('imagePreviewDescription');
	objDescription.innerHTML = "&nbsp;";
	objImg = createNewElement('img');
	objImg.id = 'imagePreviewImg';
	objImg.className = 'imagePreview';
	objImg.src = jsPageAdress+'/module_thumbnail.php?gid='+picID+'&x='+imgWidth+'&y='+imgHeight+'&out=jpg';
	objImg.width = imgWidth;
	objImg.height = imgHeight;
	objImg.alt = 'Click on the image to close preview.';
	objImg.title = imgAlt;
	objImg.border = '0';
	objImg.style.top = Math.floor((screenHeight()-imgHeight)/2)+getVerticalOffset()+'px';
	objImg.style.left = Math.floor((screenWidth()-imgWidth)/2)+'px';
	objImg.onclick = function(){pictureViewFullscreenClose();};
	objDiv.appendChild (objImg);
}
function pictureViewFullscreenClose() {
	httpRequest = null;
	objDiv = document.getElementById('imagePreviewDiv');
	document.body.removeChild(objDiv);
}