var isMozilla = (navigator.appName == "Netscape" || !/msie|opera/i.test(navigator.userAgent)) ? true : false;
/*******************************************************************/
//slidedown menu

if (isMozilla) var survey_slideSpeed = 20;	// Higher value = faster
else var survey_slideSpeed = 10;
var survey_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var survey_bctiveId = false;
var survey_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(survey_slideInProgress)return;
	survey_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var blockDiv = document.getElementById('survey_a' + numericId);

	objectIdToSlideDown = false;

	if(!blockDiv.style.display || blockDiv.style.display=='none'){
		if(survey_bctiveId &&  survey_bctiveId!=numericId){
			objectIdToSlideDown = numericId;
			slideContent(survey_bctiveId,(survey_slideSpeed*-1));
		}else{

			blockDiv.style.display='block';
			blockDiv.style.visibility = 'visible';

			slideContent(numericId,survey_slideSpeed);
		}
	}else{
		slideContent(numericId,(survey_slideSpeed*-1));
		survey_bctiveId = false;
	}
}

function slideContent(inputId,direction)
{

	var obj =document.getElementById('survey_a' + inputId);
	var contentObj = document.getElementById('survey_bc' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',survey_timer);
	}else{
		if(height<=1){
			obj.style.display='none';
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('survey_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('survey_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,survey_slideSpeed);
			}else{
				survey_slideInProgress = false;
			}
		}else{
			survey_bctiveId = inputId;
			survey_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='survey_title'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'survey_q'+divCounter;
			var block = divs[no].nextSibling;
			while(block && block.tagName!='DIV'){
				block = block.nextSibling;
			}
			block.id = 'survey_a'+divCounter;
			contentDiv = block.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='survey_block_content';
			contentDiv.id = 'survey_bc' + divCounter;
			block.style.display='none';
			block.style.height='1px';
			divCounter++;
		}
	}
}
//window.onload = initShowHideDivs;

/*******************************************************************/




function $(sId)
{
	if (!sId) return null;

	var returnObj = document.getElementById(sId);
	if (!returnObj && document.all) returnObj = document.all[sId];
	return returnObj;
}

function SetAllValue(sIdPrefix,mValue,sExcludeId,sElement,sObjType)
{
	if(!sElement) sElement = "INPUT";
	
	var objs = document.getElementsByTagName(sElement);
	for(i=0;i<objs.length;i++){
		if(objs[i].id!=sExcludeId && objs[i].id.substr(0,sIdPrefix.length)==sIdPrefix) {
			if(!sObjType || objs[i].type==sObjType ) {
				if(objs[i].type=='checkbox' || objs[i].type=='radio') objs[i].checked = mValue;
				else objs[i].value = mValue;
				if(objs[i].onchange) objs[i].onchange();
			}
		}
	}
}

function CreateElement(sId,sParentId,sElement)
{
	if(!sElement) sElement = "DIV";
	
	var objParent = $(sParentId);
	if(objParent) {
		var objNew = document.createElement(sElement);
		objNew.id = sId;
		
		objParent.appendChild(objNew);
	}
	
	return objNew;
}

function DropElement(sId)
{
	var objElm = $(sId);
	if(objElm && objElm.parentNode) objElm.parentNode.removeChild(objElm);
}

function closeFreeBox(boxId)
{
	var divObj = document.getElementById(boxId);
	if(divObj) {
		var parentObj = divObj.parentNode;
		parentObj.removeChild(divObj);
	}
}

function initCalendar(inputField, triggerField, dateFormat){
	if (!dateFormat) dateFormat = "%Y-%m-%d";
	Calendar.setup(
    	{
      inputField  : 	inputField,         
      ifFormat    :	dateFormat,
      button      : 	triggerField,
      singleClick : 	"true",
      firstDay  : 	1,
      weekNumbers : 	false,
      align : "br"
    }
  );
}

function addTRItem(element){
    if(document.getElementById) {
        while (element.tagName != 'TR') element = element.parentNode;
        element = element.previousSibling;
        if (isMozilla) element = element.previousSibling;
        var newElem=element.cloneNode(true);
        newElem.getElementsByTagName('INPUT')[0].value='';
        element.parentNode.insertBefore(newElem,element.nextSibling);
    }
}


function removeTRItem(element){
    if(document.getElementById) {
        row = element;
        while (row.tagName != 'TR') row = row.parentNode;
        row.parentNode.removeChild(row);
    }
}

function openChatWnd(senderId, recipientId, ROOT_DOMAIN){
	var url = "http://"+ROOT_DOMAIN+"/"+senderId+"/chat/"+recipientId+"/";
	var name = "chat_"+senderId+"_"+recipientId;
	var w=window.open(url, name, "width=500,height=580,resizable=1,toolbar=0,location=0,status=0,menubar=0,directories=0,scrollbars=yes,top=100,left=100");
	w.focus();
}

function openWnd(name, url, width, height){
	if (!name) name='_blank';
	var w=window.open(url, name, "width="+width+",height="+height+",resizable=1,toolbar=1,location=1,status=1,menubar=1,directories=1,scrollbars=yes");
	w.focus();
}

function HideLeft4MyQ () {
    document.getElementById("contentLeft").style.display="none";
    document.getElementById("contentMain").className="";
}

function HideFooterLeft() {
	document.getElementById("footerLeft").style.display="none";
}

function WndOpen(url) {
	alert(parent);
	parent.window.open(url, 'Wnd', "width=300,height=250,resizable=1,toolbar=0,location=0,status=0,menubar=0,directories=0,scrollbars=yes,top=100,left=100");
}

