// JavaScript Document
function windowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function windowWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}



function init_calendar(idField,idButton)
{
	var cal = new Zapatec.Calendar.setup({
							
	inputField:idField,
	ifFormat:"%d/%m/%Y",
	button: idButton,
	showsTime:false
	
	});
}

function dateIsSpecial(date)
{
	
	if (document.getElementById('specialDate'+date))
	{
		return true;
	}
	else
		return false;
}

function dateChanged(calendar)
{
	date=calendar.currentDate.print('%Y-%m-%d');
	if (dateIsSpecial(date))
	{
		//brs=whichBrs();
		//if (brs=='Internet Explorer')
			
		document.location=document.getElementsByTagName('base')[0].href +'events-day/'+date+'/';
	}
	return false;
};

function init_calendar_special(idButton)
{
	var cal = new Zapatec.Calendar.setup({
	
	ifFormat:"%Y-%m-%d",
	button: idButton,
	showsTime:false,
	onSelect : dateChanged,
	dateStatusFunc : function(date, y, m, d) {
			m++;
			if (m<10) m='0'+m;
			if (d<10) d='0'+d;
			if (dateIsSpecial(y+'-'+m+'-'+d)) return "zpCalSpecialDay";
			else return false; // other dates are enabled
			// return true if you want to disable other dates
		}
	
	});
}

function submitwithaction(form,action)
{
	form.action=action;
	form.submit();
}


function todayStr()
{
	var today=new Date()
	return today.getDate()+"/"+(today.getMonth()+1)+"/"+(today.getFullYear())
}


function addEmptyTr(div,lastKey,father,idTr)
{
	document.getElementById(lastKey).value++;
	lastKey=document.getElementById(lastKey).value;
	
	var sample_text=document.getElementById(div).innerHTML;
	
	new_text=sample_text.replace(/thisisthekey/g,lastKey);
	father=document.getElementById(father);
	var new_tr=document.createElement('tr');
	new_tr.setAttribute('id',idTr+lastKey);
	new_tr.innerHTML=new_text;
	father.appendChild(new_tr);
	return false;
}

function deleteTr(key,prefixHid,father,idTr,deleteHidId)
{
	already=document.getElementById(prefixHid+key)
	father=document.getElementById(father);
	tr=document.getElementById(idTr+key);
	if (already)
	{
		deleteHid=document.getElementById(deleteHidId);
		deleteHid.value+='|'+already.value;
		tr.innerHTML='';
	}
	else
	{
		father.removeChild(tr);
	}
	return false;
}

function popup(href,top,left,width)
					
{
	window.scroll(0,0);
	var dynPageObjp = new DHTMLgoodies_scrollingPages();
	//alert(dynPageObjp.targetId);
	oLay=document.getElementById('blackOverlay');
	var arrayPageSize = getPageSize();
	oLay.style.width=arrayPageSize[0]+'px';
	oLay.style.height=arrayPageSize[1]+'px';
	oLay.style.display='block';
	cont=document.getElementById('popupContainer');
	cont.innerHTML='';
	
	cont.style.width=width;
	cont.style.left=left;
	cont.style.top=top;
	enableCache= true;
	dynPageObjp.setTargetId('popupContainer');
	dynPageObjp.setUrl(href);
	//dynPageObjp.setScrollSpeed(0);
	dynPageObjp.loadPage();
	cont.style.display='block';
	dynPageObjp=null;
	
	return false;
}

function closePopup()
{
	cont=document.getElementById('popupContainer');
	oLay=document.getElementById('blackOverlay');
	cont.innerHTML='';
	cont.style.display='none';
	oLay.style.display='none';
	return false;
}

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function swap(id1,id2)
{
	//document.getElementById(id1).innerHTML=document.getElementById(id2).innerHTML;
	document.getElementById(id1).style.display='none';
	document.getElementById(id2).style.display='block';
	document.getElementById('current').value=id2;
}

function priceOptions()
{
	sel=document.getElementById('option');
	option=sel.options[sel.selectedIndex].value;
	prefix=document.getElementById('prefix'+option).value;
	price=parseInt(document.getElementById('price'+option).value);
	oldPrice=parseInt(document.getElementById('discountPrice').value);
	if (prefix=='+')
	{
		newPrice=oldPrice+price;
	}
	else
	{
		newPrice=oldPrice-price;
	}
	
	document.getElementById('finalPrice').value=newPrice;
	document.getElementById('priceOption').innerHTML=prefix+price;
	document.getElementById('priceFinal').innerHTML=newPrice;
	return false;
}

function checkSignUp(mandatoryer,emailer,passer)
{
	form=document.signUp;
	if (form.user.value == "")
	{
		alert(mandatoryer);
		form.user.focus();
		
		return false;
	}
	
	if (form.pass.value == "")
	{
		alert(mandatoryer);
		form.pass.focus();
		
		return false;
	}
	
	if (form.pass.value != form.rpass.value)
	{
		alert(passer);
		form.pass.focus();
		
		return false;
	}
	
	if (form.name.value == "")
	{
		alert(mandatoryer);
		form.name.focus();
		
		return false;
	}
	
	if (form.surname.value == "")
	{
		alert(mandatoryer);
		form.surname.focus();
		
		return false;
	}
	
	if (form.email.value == "")
	{
		alert(mandatoryer);
		form.email.focus();
		
		return false;
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(form.email.value)))
	{ 
		alert(emailer);
		form.email.focus();
		return false;
	}
	form.submit();
}

function checkFeedback(mandatoryer,emailer)
{
	form=document.feedback;
	
	if (form.name.value == "")
	{
		alert(mandatoryer);
		form.name.focus();
		
		return false;
	}
	
	if (form.email.value == "")
	{
		alert(mandatoryer);
		form.email.focus();
		
		return false;
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(form.email.value)))
	{ 
		alert(emailer);
		form.email.focus();
		return false;
	}
	
	if (form.comment.value == "")
	{
		alert(mandatoryer);
		form.comment.focus();
		
		return false;
	}
	form.submit();
}


function checkMyProfile(mandatoryer,emailer,passer)
{
	form=document.signUp;
	
	
	if (form.pass.value != form.rpass.value&&form.pass.value!='')
	{
		alert(passer);
		form.pass.focus();
		
		return false;
	}
	
	if (form.name.value == "")
	{
		alert(mandatoryer);
		form.name.focus();
		
		return false;
	}
	
	if (form.surname.value == "")
	{
		alert(mandatoryer);
		form.surname.focus();
		
		return false;
	}
	
	if (form.email.value == "")
	{
		alert(mandatoryer);
		form.email.focus();
		
		return false;
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(form.email.value)))
	{ 
		alert(emailer);
		form.email.focus();
		return false;
	}
	
	return true;
}

function checkAnunt(mandatoryer,emailer,nonrer,bignrer)
{
	form=document.post;
	
	//alert('aaa');
	
	if (form.title.value == "")
	{
		alert(mandatoryer);
		form.title.focus();
		
		return false;
	}
	
	if (form.teaser.value == "")
	{
		alert(mandatoryer);
		form.teaser.focus();
		
		return false;
	}
	
	/*if (form.content.value == "")
	{
		alert(mandatoryer+'ddd');
		form.content.focus();
		
		return false;
	}*/
	
	if (form.validity.value == "")
	{
		alert(mandatoryer);
		form.validity.focus();
		
		return false;
	}
	
	if (!IsNumeric(form.validity.value))
	{
		alert(nonrer);
		form.validity.focus();
		
		return false;
	}
	
	if (form.validity.value>90)
	{
		alert(bignrer);
		form.validity.focus();
		
		return false;
	}
	form.submit();
}

function IsNumeric(sText)

{
var ValidChars = "0123456789";
var IsNumber=true;
var Char;


for (i = 0; i < sText.length && IsNumber == true; i++) 
  { 
  Char = sText.charAt(i); 
  if (ValidChars.indexOf(Char) == -1) 
	 {
	 IsNumber = false;
	 }
  }
return IsNumber;

}

function changeOnLevel(key,noLevel,noZones)
{
	selCurr=document.getElementById('level'+key+noLevel);
	selNext=document.getElementById('level'+key+(noLevel+1));
	if (selNext)
	{
		
		while (selNext.length)
		{
			selNext.remove(0);
		}
		idCurr=selCurr.options[selCurr.selectedIndex].value;
		for (i=0;i<noZones;i++)
		{
			if (ids[i]==idCurr)
			{
				keyCurr=i;
				break;
			}
		}
		noNewOptions=-1;
		for (i=0;i<noZones;i++)
		{
			
			if (parentInTree[i]==keyCurr)
			{
				//alert(i+' '+names[i]);
				
				noNewOptions++;
				selNext.options[noNewOptions]=new Option(names[i],ids[i]);
				/*var newOption=document.createElement('option');
				newOption.setAttribute('value',ids[i]);
				newOption.innerHTML=names[i];*/
				//selNext.add(newOption);
			}
		}
	}
	
	return false;
}


function findPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function getMousePosition(e)
{
	var IE = document.all?true:false;
	if (!IE) document.captureEvents(Event.MOUSEMOVE);

	if (IE)
	{ // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	}
	else
	{  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	}  
	// catch possible negative values in NS4
	if (tempX < 0)
	{
		tempX = 0
	}
	if (tempY < 0)
	{
		tempY = 0
	}  

	return [tempX,tempY];
}

function ratingRollOver(yellow,event)
{
	var ypos=new Array();
	
	ypos=findPos(yellow);
	mpos=getMousePosition(event);
	test=document.getElementById('ttttest');
	dif=mpos[0]-ypos[0];
	dif=Math.ceil(dif/23.4)*23.4;
	
	
	yellow.style.width=dif+'px';
	
	//test.innerHTML=test.innerHTML+' '+yellow.style.width+' ';
	
	
	return false;
}

function endRatingRollOver(yellow,width)
{
	yellow.style.width=width+'px';
	
	return false;
}

function rate(yellow,event,base,module,id)
{
	var ypos=new Array();
	
	ypos=findPos(yellow);
	mpos=getMousePosition(event);
	test=document.getElementById('ttttest');
	dif=mpos[0]-ypos[0];
	dif=Math.ceil(dif/23.4);
	
	document.location=base+module+'-rate/'+id+'-'+dif+'/';
}

function modifyPrice(obj,id)
{
	type=document.getElementById('optionType'+id).value;
	noValues=parseInt(document.getElementById('optionNoValues'+id).value);
	newPrice=0;
	switch (type)
	{
		case 'select':  sel=document.getElementById('option'+id+'-0');
						newPrice=parseInt(sel.options[sel.selectedIndex].title);
						break;
		case 'radio':   for (i=0;i<noValues;i++)
						{
							radio=document.getElementById('option'+id+'-'+i);
							if (radio.checked)
							{
								newPrice=parseInt(radio.title);
								break;
							}
						}
						break;
						
		case 'check':   for (i=0;i<noValues;i++)
						{
							check=document.getElementById('option'+id+'-'+i);
							if (check.checked)
							{
								newPrice+=parseInt(check.title);
							}
						}
						break;
						
		case 'text':    newPrice=parseInt(document.getElementById('option'+id+'-0').title);
						break;
	}
	
	oldPrice=document.getElementById('optionOldPrice'+id).value;
	productPrice=document.getElementById('productPrice').value;
	productPrice=productPrice-oldPrice+newPrice;
	document.getElementById('productPrice').value=productPrice;
	document.getElementById('optionOldPrice'+id).value=newPrice;
	currency=document.getElementById('currency').value;
	document.getElementById('optionPrice'+id).innerHTML=newPrice+' '+currency;
	document.getElementById('priceFinal').innerHTML=productPrice+' '+currency;
	
	return false;
}

function showPreviousSlide()
{
	currHid=document.getElementById('current');
	current=parseInt(currHid.value);
	noSlides=parseInt(document.getElementById('noSlides').value);
	toShow=document.getElementById('slide'+(current-1));
	document.getElementById('slide'+current).style.display='none';
	if (toShow)
	{
		
		toShow.style.display='block';
		newValCurr=current-1;
	}
	else
	{
		document.getElementById('slide'+noSlides).style.display='block';
		newValCurr=noSlides;
	}
	
	currHid.value=newValCurr;
	
	return false;
	
}

function showNextSlide()
{
	currHid=document.getElementById('current');
	current=parseInt(currHid.value);
	noSlides=parseInt(document.getElementById('noSlides').value);
	toShow=document.getElementById('slide'+(current+1));
	document.getElementById('slide'+current).style.display='none';
	if (toShow)
	{
		
		toShow.style.display='block';
		newValCurr=current+1;
	}
	else
	{
		document.getElementById('slide0').style.display='block';
		newValCurr=0;
	}
	
	currHid.value=newValCurr;
	
	return false;
	
}


function tinyMCE2Here(idTextarea,baseUrl)
{
	
tinyMCE.init({
		elements : idTextarea,
		mode : "exact",
		theme : "advanced",
		plugins : "table,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,paste,directionality,fullscreen,noneditable,contextmenu",
		theme_advanced_buttons1:"fontselect,fontsizeselect,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull",
		theme_advanced_buttons2:"bullist,numlist,outdent,indent,link,unlink,anchor,forecolor,backcolor,forecolorpicker,backcolorpicker",
		theme_advanced_buttons3:"",
		//theme_advanced_buttons1_add : "separator,cut,copy,paste,pastetext,pasteword,separator,search,replace",
		//theme_advanced_buttons2_add : "separator,insertdate,inserttime,separator,media,advhr,separator,ltr,rtl",
		//theme_advanced_buttons3_add_before : "tablecontrols,separator",
		//theme_advanced_buttons3_add : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_path_location : "bottom",
		plugin_insertdate_dateFormat : "%Y-%m-%d",
		plugin_insertdate_timeFormat : "%H:%M:%S",
		document_base_url : baseUrl,
		extended_valid_elements : "hr[class|width|size|noshade]",
		file_browser_callback : "fileBrowserCallBack",
		paste_use_dialog : false,
		theme_advanced_resizing : true,
		theme_advanced_resize_horizontal : false,
		theme_advanced_link_targets : "_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
		theme_advanced_fonts : "Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Times New Roman=times new roman, times, serif;Georgia=georgia, times new roman, times, serif;Verdana=verdana, arial, helvetica, sans-serif;Geneva=geneva, arial, helvetica, sans-serif",
		apply_source_formatting : true
	});
}


function showCalendar(href)
{
	var dynPageObj = new DHTMLgoodies_scrollingPages();
	
	cont=document.getElementById('calendarHolder');
	cont.innerHTML='';
	
	//cont.style.width=width;
	//cont.style.left=left;
	//cont.style.top=top;
	enableCache= true;
	dynPageObj.setTargetId('calendarHolder');
	dynPageObj.setUrl(href);
	//dynPageObj.setScrollSpeed(0);
	dynPageObj.loadPage();
	//cont.style.display='block';
	dynPageObj=null;
	
	return false;
}

function showToolTipNews(day)
{
	div=document.getElementById('toolTipNews');
	if (day==0)
	{
		document.getElementById('remainOn').value=1;
		div.style.display='block';
	}
	else
	{
		if (div.style.display=='block')
			div.style.display='none';
	}
	if (div.style.display=='none')
	{
		div.innerHTML='';
		dayDiv=document.getElementById('newsFrom'+day);
		div.innerHTML=dayDiv.innerHTML;
		var poz=new Array();
		poz=findPos(document.getElementById('newsLinkCalendar'+day));
		div.style.left=(poz[0]+10)+'px';
		div.style.top=(poz[1]+10)+'px';
		div.style.display='block';
	}
	return false;
}

function hideToolTipNews(day)
{
	div=document.getElementById('toolTipNews');
	if (day==0)
	{
		document.getElementById('remainOn').value=0;
		div.style.display='none';
	}
	else
	{
		if (document.getElementById('remainOn').value==0)
		{
			div.innerHTML='';
			div.style.display='none';
		}
	}
	return false;
}

function createQuery()
{
	var form=document.searchFormA;
	
	
	query=form.yeses.value;
	
	if (form.expryeses.value)
		query+=' "'+form.expryeses.value+'"';
	
	if (form.nots.value)
	{
		var notStr='';
		var nots=form.nots.value.split(' ');
		for (i=0;i<nots.length;i++) 
			notStr+='-'+nots[i];
		query+=notStr;
	}
		
	if (form.exprnots.value)
		query+=' -"'+form.exprnots.value+'"';
	
	if (form.startDate.value)
	{
		var sd=form.startDate.value.split('/');
		var sdStr=sd[2]+'-'+sd[1]+'-'+sd[0];
	}
		
	if (form.startDate.value)
	{
		var ed=form.endDate.value.split('/');
		var edStr=ed[2]+'-'+ed[1]+'-'+ed[0];
	}
	
	if (sdStr||edStr)
		query+=' data:'+sdStr+'-'+edStr+';';
	
	var strCategorie='';
	for (i=1;i<11;i++)
	{
		if (document.getElementById('categorie'+i).checked)
			strCategorie+=','+document.getElementById('categorie'+i).value;
	}
	if (strCategorie)
		query+=' categorie:'+strCategorie.substr(1)+';';
		
	//alert(query);
	return query;
}

function checkSubscribeH()
{
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(document.subscribeH.email.value)))
	{ 
		alert('Adresa de e-mail nu este valida!');
		document.subscribeH.email.focus();
		return false;
	}
	form.submit();
}