a=function(module,mode){if(mode==null||mode!=true)var mode=false;if(window.XMLHttpRequest)xmlhttp=new XMLHttpRequest;else if(window.ActiveXObject)xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open('POST',module,mode);xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){var r=xmlhttp.responseText;}}};xmlhttp.send('ajax=1'); return xmlhttp.responseText;};
a2=function(data,module,mode){if(mode==null||mode!=true)var mode=false;if(window.XMLHttpRequest)xmlhttp=new XMLHttpRequest;else if(window.ActiveXObject)xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open('POST','/'+sys_lang+'/'+module+'/',mode);xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){var r=xmlhttp.responseText;}}};xmlhttp.send(data); return xmlhttp.responseText;};
loadXML=function(txt){try{xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.loadXML(txt);return(xmlDoc);}catch(e){try{parser=new DOMParser();xmlDoc=parser.parseFromString(txt,"text/xml");return(xmlDoc);}catch(e){}}return(null);};
in_array=function(needle,haystack){var found=false,key;for(key in haystack){if(haystack[key]==needle){found=true;break;}}return found;};
is_array=function(value){var key='';if(!value)return false;if(typeof value==='object'){if(value.hasOwnProperty){for(key in value){if(false===value.hasOwnProperty(key)){return false;}}return true;} return false;}};
urlencode=function(str){string=encodeURIComponent(str).replace(/~/g,'%7E');return string.replace(/%20/g,'+');};
urldecode=function(str){return decodeURIComponent(str.replace(/\+/g, '%20'))};
isMail=function(str){var filter=/^.+@.+\..{2,3}$/; return filter.test(str)};
initChackbox=function() {
	$('.checkbox').click(function(){
		if(!/disabled/.test($(this).attr('className'))){
			if(/act/.test($(this).attr('className'))){
				$(this).removeClass('act')
			}else{
				$(this).addClass('act')
			}		
		}
	});
}

reload=function(m){
	var dur=(parseFloat($('#content').css('margin-left').replace('px',''))>=0)?600:1;
	location.hash=m;
	$('#content').animate(
		{'margin-left':$('#content').width()*-1}, 
		dur,
		function(){
			xml=loadXML(a(m,0));
			var content=urldecode(xml.getElementsByTagName('content')[0].getAttribute('data'));
			var title=urldecode(xml.getElementsByTagName('title')[0].getAttribute('data'));
			$('#pageMiddle').html(content);
			switch(xml.getElementsByTagName('content')[0].getAttribute('type')) {
				case 'rezervesana': initBookingForm(); break;
			}
			$('#content').animate({'margin-left':0},600)
		}
	);
};


drawCalendarDates=function(id,month,year){
	var si=$('#'+id).attr('selectedIndex');
	$('#'+id+'>*').remove();
	var days=32-new Date(year,month,32).getDate();
	for(var i=1;days>=i;i++){$('<option value="'+i+'">'+i+'</option>').appendTo($('#'+id))}
	if(si <= parseFloat($('#'+id).attr('length')) && si>0){$('#'+id).attr({'selectedIndex':si})}else{$('#'+id).attr({'selectedIndex':0})}
};
initGallery=function(){
	$('.gallery-images-list>li>a').lightBox();
};
initBookingForm=function(){
	drawCalendarDates('rez_d1',$('#rez_d2').val(),$('#rez_d3').val());
	drawCalendarDates('rez_d4',$('#rez_d5').val(),$('#rez_d6').val());
	$('#rez_d2, #rez_d3').change(function(){drawCalendarDates('rez_d1',$('#rez_d2').val(),$('#rez_d3').val())});
	$('#rez_d5, #rez_d6').change(function(){drawCalendarDates('rez_d4',$('#rez_d5').val(),$('#rez_d6').val())});
	initChackbox();
	$('.radiobutton').click(function(){
		if(/specoffer/.test($(this).attr('className'))){
			$('.specoffer').addClass('act');
			$('.room').removeClass('act');
			$('#building_type, #room_type, #room_number').attr('selectedIndex',0);
			$('#special_offer').attr({'disabled':false});
			$('#building_type, #room_type, #room_number, #rez_descr').attr({'disabled':true});
			$('.additional').removeClass('act').addClass('disabled');
		}else if(/room/.test($(this).attr('className'))){
			$('.specoffer').removeClass('act');
			$('.room').addClass('act');
			$('#special_offer').attr({'disabled':true});
			$('#special_offer').attr('selectedIndex',0);
			$('#building_type, #room_type, #room_number, #rez_descr').attr({'disabled':false});
			$('.additional').removeClass('disabled');
		}
	});
	
	$('.room').addClass('act');
	$('.specoffer').removeClass('act');
	$('.room').addClass('act');
	$('#special_offer').attr({'disabled':true});
	$('#special_offer').attr('selectedIndex',0);
	$('#building_type, #room_type, #room_number').attr({'disabled':false});
	$('.additional').removeClass('disabled');
	
	$('#booking').bind('submit', function(event){
		event.preventDefault();
		
		var p='act=booking';
		p+='&rez[term][from][day]='+$('#rez_d1').val();
		p+='&rez[term][from][month]='+(parseFloat($('#rez_d2').val())+1);
		p+='&rez[term][from][year]='+$('#rez_d3').val();
		p+='&rez[term][till][day]='+$('#rez_d4').val();
		p+='&rez[term][till][month]='+(parseFloat($('#rez_d5').val())+1);
		p+='&rez[term][till][year]='+$('#rez_d6').val();
		
		p+='&rez[pers][adult]='+$('#rez_adult').val();
		p+='&rez[pers][child]='+$('#rez_child').val();
		
		if(/room/.test($('.radiobutton.act').attr('className'))) {
			p+='&rez[method]=room';
			p+='&rez[type][building]='+$('#building_type').val();
			p+='&rez[type][room]='+$('#room_type').val();
			p+='&rez[type][number]='+$('#room_number').val();
			var s=[]; $('.additional.act').each(function(){s[s.length]=$(this).attr('rel')});
			p+='&rez[additional_services]='+s.join(',');
			p+='&rez[]='+s.join(',');
			p+='&rez[type][descr]='+urlencode($('#rez_descr').val());
		} else if(/specoffer/.test($('.radiobutton.act').attr('className'))) {
			p+='&rez[method]=specialOffer';
			p+='&rez[special_offer]='+$('#special_offer').val();
		} else {
			alert(lng[0]); return false;
		}
		if($('#rez_name').val()==''){alert(lng[0]); return false;}
		if($('#rez_phone').val()==''){alert(lng[0]); return false;}
		if($('#rez_email').val()==''){alert(lng[0]); return false;}
		
		p+='&rez[contact][name]='+$('#rez_name').val();
		p+='&rez[contact][phone]='+$('#rez_phone').val();
		p+='&rez[contact][mail]='+$('#rez_email').val();
		p+='&rez[contact][text]='+$('#rez_text').val();
		var r=a2(p,'rezervesana',0);
		alert(r);
	})
};

initPrintButton=function() {
	var bolWebPartFound = false;
	if(document.getElementById != null){
		var htm = '<HTML>\n<HEAD>\n';
		if (document.getElementsByTagName != null){
			var HeadData=document.getElementsByTagName("HEAD");
			if(HeadData.length>0)htm+=HeadData[0].innerHTML;
		}
		htm += '<link rel="stylesheet" type="text/css" href="/style.css" /><meta charset="UTF-8">';
		htm += '<style type="text/css">body{padding: 20px;}</style>';
		htm += '\n</HEAD>\n<BODY style="background: #FFFFFF; color: #000000;" onload="print()">\n';
		var WebPartData = document.getElementById('pageContent');
		if (WebPartData != null){
			htm+='<div id="pageContent" class="singleArticle">'+WebPartData.innerHTML+'</div>';
			bolWebPartFound=true;
		}else{
			bolWebPartFound = false;
		}
	}
	htm += '\n</BODY>\n</HTML>';
	if (bolWebPartFound){
		var size_x=800;
		var size_y=600;
		LeftPosition=(screen.width) ? (screen.width-size_x)/2 : 0;
		TopPosition=(screen.height) ? (screen.height-size_y)/2 : 0;
		var msgWindow=window.open("about:blank", "PrintWebPart", "width=800,height=600, top="+TopPosition+", left="+LeftPosition+", resizable=no, status=no, toolbar=no, menubar=no, scrollbars=yes ");
		if(msgWindow!=null){
			var doc = msgWindow.document.open('text/html', 'replace' );
			doc.write(htm);
			$('*').css({'color':'#000000'});
			doc.close();
		}
	}
}






function popup(https,name, options){
alert("show "+https);
shopWin = open(https, name, "scrollbars=yes,resizable=yes,width="+wid+",height="+hei+"");
        shopWin.focus();
}








