function fix(id,min){
	//alert(window.navigator.userAgent);
	if(window.navigator.userAgent.indexOf("MSIE")<0)return;
	document.getElementById(id).style.width=((window.innerWidth||document.body.clientWidth)>min)?"100%":min+"px";
}

function fixHeight(){
	if(document.getElementById('header') && document.getElementById('main') && document.getElementById('home')){
		var winHeight = parseInt(document.body.clientHeight);
		var header = parseInt(document.getElementById('header').offsetHeight);
		var mainHeight = parseInt(document.getElementById('main').offsetHeight);
		if(winHeight > (mainHeight + header)){
			document.getElementById('home').style.height	= winHeight - header -1 + "px";
		}
		else{
			document.getElementById('home').style.height = mainHeight + "px";
		}
		if (document.getElementById('white_block')){
			h = document.getElementById('white_block').offsetHeight;
			if (h < 408){
				h = 408;
				if (document.getElementById('content_menu'))
					h-=41;
				document.getElementById('white_block').style.height = h+'px';
				document.getElementById('textbox').style.height = h-97+'px';
				document.getElementById('home').style.height = h+387+'px';
			}
		}
	}
}

function heightfix(){
	if(window.navigator.userAgent.indexOf("Opera") >=0){
		setTimeout('fixHeight()',100);
	}
	else{
		fixHeight();
	}
}



var illLargeCurrent = null;
var illLargeNew = null;
var illActiveLink = null;
var illCurrentLink = null;
function showIllustration(illId) {
	illLargeNew = document.getElementById('ill-large-' + illId);
	illActiveLink = document.getElementById('ill-small-' + illId);
	if(illLargeNew != illLargeCurrent) {
		if(illLargeCurrent) {
			illLargeCurrent.style.display = 'none';
			illCurrentLink.style.backgroundColor = '';
		}
		if(illLargeNew) {
			illLargeNew.style.display = 'block';
			illActiveLink.style.backgroundColor = '#FFB607';
			illLargeCurrent = illLargeNew;
			illCurrentLink = illActiveLink;
		}
	}
}

function closeIllustration(illId) {
	illLargeCurrent = document.getElementById('ill-large-' + illId);
	illLargeCurrent.style.display = 'none';
	illCurrentLink = document.getElementById('ill-small-' + illId);
	illCurrentLink.style.backgroundColor = '';
	illLargeCurrent = null;
	illCurrentLink = null;
}

function mshover() { 
	if (document.all&&document.getElementById("nav")) { 
		navRoot = document.getElementById("nav"); 
		for (i=0; i<navRoot.childNodes.length; i++) { 
			node = navRoot.childNodes[i]; 
			//alert(node.className);
			if (node.nodeName=="DIV" && node.className=="nav_item") { 
				node.onmouseover=function() {
					this.className+=" over"; 
				} 
				node.onmouseout=function() { 
					this.className=this.className.replace
					(" over", ""); 
				}
				
			}
		}
	}
}
//////////////////////////////////////////////////////////
//NICE
//////////////////////////////////////////////////////////
/*#############################################################
Name: Niceforms
Version: 1.1
Author: Paul Blazhievsky
Feel free to use and modify but please provide credits.
#############################################################*/
//Global Variables
var niceforms = document.getElementsByTagName('form'); 
var inputs = new Array(); 
var labels = new Array(); 
var radios = new Array(); 
var radioLabels = new Array(); 
var checkboxes = new Array(); 
var checkboxLabels = new Array(); 
var texts = new Array(); 
var textareas = new Array(); 
var selects = new Array(); 
var selectText = "please select"; 
var agt = navigator.userAgent.toLowerCase(); this.ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); 
var hovers = new Array(); 
var buttons = new Array(); 
var isMac = new RegExp('(^|)'+'Apple'+'(|$)');
var selectedSelect=null;
//Theme Variables - edit these to match your theme
var selectRightSideWidth = 21;
var selectLeftSideWidth = 5;
var selectAreaHeight = 21;
var selectAreaOptionsOverlap = 1;
var imagesPath = "/img/";

//Initialization function - if you have any other 'onload' functions, add them here
function init_f() {
	if(!document.getElementById) {return false;}
//	preloadImages();
	getElements();
	separateElements();
//	replaceRadios();
//	replaceCheckboxes();
	replaceSelects();
	if(!isMac.test(navigator.vendor)) {
		replaceTexts();
		replaceTextareas();
//		buttonHovers();
	}
}


function getElements() {
	//var re = new RegExp('(^| )'+'niceform'+'(.*$)');
	var re = new RegExp('(^| )'+'niceform'+'( |.*$)'); 
	//var re = new RegExp('(^| )'+'niceform'+'( |$)'); 
	for (var nf = 0; nf < document.getElementsByTagName('form').length; nf++) {
		if(re.test(niceforms[nf].className)) {
			for(var nfi = 0; nfi < document.forms[nf].getElementsByTagName('input').length; nfi++) {
				inputs.push(document.forms[nf].getElementsByTagName('input')[nfi]);
				inputs[inputs.length-1].parentClass=document.forms[nf].className;
			}
			for(var nfl = 0; nfl < document.forms[nf].getElementsByTagName('label').length; nfl++) {
				labels.push(document.forms[nf].getElementsByTagName('label')[nfl]);
				labels[labels.length-1].parentClass=document.forms[nf].className;
			}
			for(var nft = 0; nft < document.forms[nf].getElementsByTagName('textarea').length; nft++) {
				textareas.push(document.forms[nf].getElementsByTagName('textarea')[nft]);
				textareas[textareas.length-1].parentClass=document.forms[nf].className;
			}
			for(var nfs = 0; nfs < document.forms[nf].getElementsByTagName('select').length; nfs++) {
				selects.push(document.forms[nf].getElementsByTagName('select')[nfs]);
				selects[selects.length-1].parentClass=document.forms[nf].className;
			}
		}
	}
}
//separating all the elements in their respective arrays
function separateElements() {
	var r = 0; var c = 0; var t = 0; var rl = 0; var cl = 0; var tl = 0; var b = 0;
	for (var q = 0; q < inputs.length; q++) {
		if(inputs[q].type == 'radio') {
			radios[r] = inputs[q]; ++r;
			for(var w = 0; w < labels.length; w++) {if(labels[w].htmlFor == inputs[q].id) {if(inputs[q].checked) {labels[w].className = "chosen";} radioLabels[rl] = labels[w]; ++rl;}}
		}
		if(inputs[q].type == 'checkbox') {
			checkboxes[c] = inputs[q]; ++c;
			for(var w = 0; w < labels.length; w++) {if(labels[w].htmlFor == inputs[q].id) {if(inputs[q].checked) {labels[w].className = "chosen";} checkboxLabels[cl] = labels[w]; ++cl;}}
		}
		if((inputs[q].type == "text") || (inputs[q].type == "password")) {texts[t] = inputs[q]; ++t;}
		if((inputs[q].type == "submit") || (inputs[q].type == "button")) {buttons[b] = inputs[q]; ++b;}
	}
}

function replaceSelects() {
    for(var q = 0; q < selects.length; q++) {
		var index=selects[q].parentClass.substring(8);
		var selectArea = document.createElement('div');
		var left = document.createElement('div');
		var right = document.createElement('div');
		var center = document.createElement('div');
		var button = document.createElement('a');
		var text = document.createTextNode(selectText);
		center.id = "mySelectText"+q;
		var selectWidth = parseInt(selects[q].className.replace(/width_/g, ""));
		center.style.width = selectWidth - 10 + 'px';
		selectArea.style.width = selectWidth + selectRightSideWidth + selectLeftSideWidth + 'px';
		button.style.width = selectWidth + selectRightSideWidth + selectLeftSideWidth + 'px';
		button.style.marginLeft = - selectWidth - selectLeftSideWidth + 'px';
		button.href = "javascript:showOptions("+q+")";
		button.onkeydown = selectEvent;
		button.className = "selectButton"; //class used to check for mouseover
		selectArea.className = "selectArea"+index;
		selectArea.id = "sarea"+q;
		left.className = "left";
		right.className = "right";
		center.className = "center";
		right.appendChild(button);
		center.appendChild(text);
		selectArea.appendChild(left);
		selectArea.appendChild(right);
		selectArea.appendChild(center);
		//hide the select field
        selects[q].style.display='none'; 
		//insert select div
		selects[q].parentNode.insertBefore(selectArea, selects[q]);
		//build & place options div
		var optionsDiv = document.createElement('div');
		optionsDiv.style.width = selectWidth + 1 + 'px';
		optionsDiv.className = "optionsDivInvisible"+index;
		//alert("->"+optionsDiv.className+"<-");
		optionsDiv.id = "optionsDiv"+q;
		optionsDiv.style.left = findPosX(selectArea) + 'px';
		optionsDiv.style.top = findPosY(selectArea) + selectAreaHeight - selectAreaOptionsOverlap + 'px';
		//get select's options and add to options div
		for(var w = 0; w < selects[q].options.length; w++) {
 			//alert(selects[q].options[w].label);
			var optionHolder = document.createElement('p');
			var optionIcon = document.createElement('img');
			var optionLink = document.createElement('a');
			var optionTxt = document.createTextNode(selects[q].options[w].text);
			optionLink.href = "javascript:showOptions("+q+"); selectMe('"+selects[q].id+"',"+w+","+q+");";
			if(selects[q].options[w].label){
				optionIcon.src=selects[q].options[w].label;
				optionLink.appendChild(optionIcon);
			}
			optionLink.appendChild(optionTxt);
			optionHolder.appendChild(optionLink);
			optionsDiv.appendChild(optionHolder);
			optionHolder.noWrap=true;
			//check for pre-selected items
			if(selects[q].options[w].selected) {selectMe(selects[q].id,w,q);}
		}
		//insert options div
		document.getElementsByTagName("body")[0].appendChild(optionsDiv);
	}
}
function showOptions(g) {
		em = document.getElementById("optionsDiv"+selectedSelect);
		if(em){
			if(elem.className.indexOf("optionsDivVisible")>=0) {
			//alert(em.className);
			em.className ="optionsDivInv"+em.className.substring(11);
			//alert(em.className);
			selectedSelect=null;
			}
		}
		//
		if(g==null)return;
		if(g==selectedSelect)return;
		if(g<0)return;

		elem = document.getElementById("optionsDiv"+g);
		if(elem.className.indexOf("optionsDivInvisible")>=0) {
			elem.className = "optionsDivV"+elem.className.substring(13);
			selectedSelect=g;
		}
		elem.onmouseout = hideOptions;
}
function hideOptions(e) { //hiding the options on mouseout
//return;
	if (!e) var e = window.event;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	if(((reltg.nodeName != 'A') && (reltg.nodeName != 'DIV')) || ((reltg.nodeName == 'A') && (reltg.className=="selectButton") && (reltg.nodeName != 'DIV'))) {
		showOptions(-1);
	};
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}
function selectMe(selectFieldId,linkNo,selectNo) {
	//feed selected option to the actual select field
	selectField = document.getElementById(selectFieldId);
	for(var k = 0; k < selectField.options.length; k++) {
		if(k==linkNo) {selectField.options[k].selected = "selected";}
		else {selectField.options[k].selected = "";}
	}
	//show selected option
	textVar = document.getElementById("mySelectText"+selectNo);
	var optionHolder = document.createElement('div');
	var optionIcon = document.createElement('img');
	if(selectField.options[linkNo].label){
		optionIcon.src=selectField.options[linkNo].label;
		optionHolder.appendChild(optionIcon);
	}
	var optionTxt = document.createTextNode(selectField.options[linkNo].text);
	optionHolder.appendChild(optionTxt);
	optionHolder.noWrap=true;
	textVar.replaceChild(optionHolder, textVar.childNodes[0]);
	if(selectField.onchange)selectField.onchange();
	showOptions(-1);
}
function selectEvent(e) {
	if (!e) var e = window.event;
	var thecode = e.keyCode;
	switch(thecode){
		case 40: //down
			var fieldId = this.parentNode.parentNode.id.replace(/sarea/g, "");
			var linkNo = 0;
			for(var q = 0; q < selects[fieldId].options.length; q++) {if(selects[fieldId].options[q].selected) {linkNo = q;}}
			++linkNo;
			if(linkNo >= selects[fieldId].options.length) {linkNo = 0;}
			selectMe(selects[fieldId].id, linkNo, fieldId);
			break;
		case 38: //up
			var fieldId = this.parentNode.parentNode.id.replace(/sarea/g, "");
			var linkNo = 0;
			for(var q = 0; q < selects[fieldId].options.length; q++) {if(selects[fieldId].options[q].selected) {linkNo = q;}}
			--linkNo;
			if(linkNo < 0) {linkNo = selects[fieldId].options.length - 1;}
			selectMe(selects[fieldId].id, linkNo, fieldId);
			break;
		default:
			break;
	}
}
function replaceTexts() {
	for(var q = 0; q < texts.length; q++) {
		texts[q].style.width = texts[q].size * 10 + 'px';
		txtLeft = document.createElement('img'); txtLeft.src = imagesPath + "input_left.gif"; txtLeft.className = "inputCorner";
		txtRight = document.createElement('img'); txtRight.src = imagesPath + "input_right.gif"; txtRight.className = "inputCorner";
		texts[q].parentNode.insertBefore(txtLeft, texts[q]);
		texts[q].parentNode.insertBefore(txtRight, texts[q].nextSibling);
		texts[q].className = "textinput";
	}
}

function replaceTextareas() {
	for(var q = 0; q < textareas.length; q++) {
		var where = textareas[q].parentNode;
		var where2 = textareas[q].previousSibling;
		textareas[q].style.width = textareas[q].cols * 10 + 'px';
		textareas[q].style.height = textareas[q].rows * 10 + 'px';
		//create divs
		var container = document.createElement('div');
		container.className = "txtarea";
		container.style.width = textareas[q].cols * 10 + 20 + 'px';
		container.style.height = textareas[q].rows * 10 + 20 + 'px';
		var topRight = document.createElement('div');
		topRight.className = "tr";
		var topLeft = document.createElement('img');
		topLeft.className = "txt_corner";
		topLeft.src = imagesPath + "txtarea_tl.gif";
		var centerRight = document.createElement('div');
		centerRight.className = "cntr";
		var centerLeft = document.createElement('div');
		centerLeft.className = "cntr_l";
		if(!this.ie) {centerLeft.style.height = textareas[q].rows * 10 + 10 + 'px';}
		else {centerLeft.style.height = textareas[q].rows * 10 + 12 + 'px';}
		var bottomRight = document.createElement('div');
		bottomRight.className = "br";
		var bottomLeft = document.createElement('img');
		bottomLeft.className = "txt_corner";
		bottomLeft.src = imagesPath + "txtarea_bl.gif";
		//assemble divs
		container.appendChild(topRight);
		topRight.appendChild(topLeft);
		container.appendChild(centerRight);
		centerRight.appendChild(centerLeft);
		centerRight.appendChild(textareas[q]);
		container.appendChild(bottomRight);
		bottomRight.appendChild(bottomLeft);
		//insert structure
		where.insertBefore(container, where2);
	}
}
//Useful functions
function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft-2;
}
function reinit(){
//
//visiblereturn;
 	for(var q = 0; q < selects.length; q++) {
		var optionsDiv=document.getElementById("optionsDiv"+q);
		var selectArea = document.getElementById("sarea"+q);
		optionsDiv.style.left = findPosX(selectArea) + 'px';
		optionsDiv.style.top = findPosY(selectArea) + selectAreaHeight - selectAreaOptionsOverlap + 'px';
		
	}
}
window.onresize=reinit;
document.onclick=function(){reinit();showOptions(-1);}

function init_form(){
	setTimeout('init_f()',1000);
}


/////
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) {
		clearInterval(_timer);
		_timer = null;
	}
	// insert stuff here
	//heightfix();
	//fix('root', 900);
	//mshover();
	//init_form();	
	// end of insert
};
/* for Mozilla */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 500);
}


/* for other browsers */
window.onload = init;

