function removeMe(el) {
	if (el) {
		var parent = el.parentNode;
		parent.removeChild(el);
		el = parent = null;
	}
}


function doTabs(id) {
    if (document.getElementById('content_images')) {
    	document.getElementById('content_images').style.visibility = 'visible';
    }
	for(i=0;i<30;i++){
		if (document.getElementById('tab'+i)) {
			document.getElementById('tab'+i).style.borderBottomColor = document.getElementById('color').value;
		}
	}
	if (document.getElementById(id)) { document.getElementById(id).style.borderBottomColor = 'white'; }
}
function doTabse(id) {
    if (document.getElementById('content_images')) {
    	document.getElementById('content_images').style.visibility = 'visible';
    }
	for(i=0;i<30;i++){
		if (document.getElementById('tabe'+i)) {
			document.getElementById('tabe'+i).style.borderBottomColor = document.getElementById('color').value;

		}
	}
	if (document.getElementById(id)) { document.getElementById(id).style.borderBottomColor = 'white'; }
	//document.getElementById('tab_container').value = 'fff';
	//alert(tab);
}

// simple js to pickup element values on the page for insertion into the database. by nedzad hasovic.
// this will also inject all elements into sessions because they need to remain there if you wish to change the amount of paragraphs
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function elementSaver(option) {
		if (document.getElementById('horisontal_menu')) {
			var horisontal_menu = document.getElementById('horisontal_menu').value;
		}
		if (document.getElementById('menuList')) {
			var menuList = document.getElementById('menuList').value;
		}
		if (document.getElementById('subMenuList')) {
			var subMenuList = document.getElementById('subMenuList').value;
		}
		if (document.getElementById('subSubMenuList')) {
			var subSubMenuList = document.getElementById('subSubMenuList').value;
		}
		
		var theID;
		var news;
		var language = document.getElementById('language').value;
		//alert (language);
		if (subMenuList <= 0 || !subMenuList) { theID = menuList; }
		else if (subSubMenuList <= 0 || !subSubMenuList) { theID = subMenuList; }
		else { theID = subSubMenuList; }
		
	// the problem is that server doesn't always finish refreshing before the loop is initiated, this must be server side.
		if (option != 'session') {
			showUser('../classes/processor.php','saver',theID,language,'refresh');
			//wait(2000);
			alert ('Your changes have been saved!');
		}
		if (document.getElementById('horisontal_menu')) {
			var is;
			//now we are reading each horizontal paragraph
			for(is=1;is<=horisontal_menu;is++) {
				//textarea retrieval
				if (document.getElementById('image_menu'+is)) { 
					pictureMenu = document.getElementById('image_menu'+is).value;
					encoded_textarea = encode64almost(escape(encode_utf8(document.getElementById('textarea'+is).value)));
					decoded_textarea = decode64almost(encoded_textarea);
					//alert (encode_utf8(document.getElementById('textarea'+is).value));
					//alert(encoded_textarea+theID+pictureMeny); 
					//alert (is+encoded_textarea+'woooot:'+decoded_textarea);
					//alert(escape("&"));
					if (option != 'session') {
						showUser('../classes/processor.php','saver',theID,language,'save',pictureMenu,encoded_textarea);
					}
					else if (option = 'session') { showUser('../classes/processor.php','saver',theID,language,'session',pictureMenu,encoded_textarea); }
				}
			}
		}
		
		else if (document.getElementById('textarea_vertical1')) {
			encoded_textarea1 = encode64almost(escape(encode_utf8(document.getElementById('textarea_vertical1').value)));
			encoded_textarea2 = encode64almost(escape(encode_utf8(document.getElementById('textarea_vertical2').value)));

			showUser('../classes/processor.php','saver',theID,language,'save_vertical','',encoded_textarea1);
			showUser('../classes/processor.php','saver',theID,language,'save_vertical','',encoded_textarea2);
		}

}


// send sane data to php, which can then send it to database normally!
function encode_utf8( s ) {
  return unescape( encodeURIComponent( s ) );
}
function decode_utf8( s ) {
  return decodeURIComponent( escape( s ) );
}



//convert base64 almost :) format, ripped some of the logic from google tutorials. by nedzad hasovic.
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64almost(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);
	  
      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64almost(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

  function swap_src(image_id,suffix) {
  	getElementById(image_id).src = suffix;
  }  



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}






function calendarClose(id){calendarResult=id;if(id)
{date=id.split('-');day=document.theForm.selDay;day.selectedIndex=date[2]-1;month=document.theForm.selMonth;month.selectedIndex=date[1]-1;year=document.theForm.selYear;for(i=0;i<year.options.length;i++){if(year.options[i].value==date[0]){year.options[i].selected=true;}}}
calendarRemove();calcDay('theForm','selDay','selMonth','selYear','StartDay');document.documentElement.onclick=null;}
function calendarRemove(){var div=document.getElementById('calendarPopup');if(div)
{div.style.display='none';}
targetId='';}
var calendarResult='';var Classes=new Array();var targetId='';function calendar(){if(document.getElementById('advanced')){if(optShown){showHideAdditonal();}}
date=document.theForm.selYear.options[document.theForm.selYear.selectedIndex].value+'-'+(document.theForm.selMonth.selectedIndex+1)+'-'+(document.theForm.selDay.selectedIndex+1);inputBoxId='CalendarDate';var quickRunAway=(targetId==inputBoxId);calendarRemove();if(quickRunAway){return;}
targetId=inputBoxId;var div=document.getElementById('calendarPopup');if(!div){div=document.createElement('div');div.setAttribute('id',"calendarPopup");var CalImg=document.getElementById('CalendarImage');CalImg.parentNode.appendChild(div);}
var textBox=document.getElementById(targetId);if(navigator.userAgent.indexOf("Firefox")!=-1){div.style.position='absolute';}else{div.style.position='absolute';}
div.style.zIndex=2100;document.documentElement.onclick=function(e){if(clickedOutsideElement('CalendarImage',e)&&clickedOutsideElement('calendarPopup',e)){calendarClose(0);}}
calendarPopulate(date);}
function calendarPopulate(date){var dayNames=new Array('Mo','Tu','We','Th','Fr','Sa','Su');var monthNames=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');var id;var styleClass='';var table='';var events='onClick="calendarClose(this.id);" onMouseOver="this.className=\'calendarHighlight\';" onMouseOut="this.className=Classes[this.id];"';var dateArray=date.split('-');today=new Date();blah=new Date();blah.setYear(dateArray[0]);blah.setDate(1);blah.setMonth(dateArray[1]-1);zarg=new Date();zarg.setYear(blah.getFullYear());zarg.setDate(1);zarg.setMonth(blah.getMonth()-1);if(zarg.getMonth()+1==today.getMonth()){zarg.setYear(today.getFullYear()+1);}
prevMonth="&laquo;&nbsp;<a href='javascript:calendarPopulate(\""+zarg.getFullYear()+"-"+(zarg.getMonth()+1)+"-"+zarg.getDate()+"\")'>"+monthNames[zarg.getMonth()]+"</a>";zarg.setYear(blah.getFullYear());zarg.setDate(1);zarg.setMonth(blah.getMonth()+1);if(zarg.getMonth()==today.getMonth()){zarg.setYear(today.getFullYear());}
nextMonth="<a href='javascript:calendarPopulate(\""+zarg.getFullYear()+"-"+(zarg.getMonth()+1)+"-"+zarg.getDate()+"\")'>"+monthNames[zarg.getMonth()]+"</a>&nbsp;&raquo;";nextYear="<a href='javascript:calendarPopulate(\""+(blah.getFullYear()+1)+"-"+(blah.getMonth()+1)+"-01\")'>&laquo;"+(blah.getFullYear()+1)+"</a>";prevYear="<a href='javascript:calendarPopulate(\""+(blah.getFullYear()-1)+"-"+(blah.getMonth()+1)+"-01\")'>"+(blah.getFullYear()-1)+"&raquo;</a>";table+='<table class=calendar>\n';table+='<tr><td colspan=7 class=calendarMonthTitle align=center>'
table+=prevMonth+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';table+=monthNames[blah.getMonth()]+'&nbsp;'+blah.getFullYear()+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';table+=nextMonth+'</td>';table+='</tr>\n';table+='<tr>';for(i=0;i<5;i++)table+='<td class=calendarWeekdayHeading align=center>'+dayNames[i]+'</td>';for(;i<7;i++)table+='<td class=calendarWeekendHeading align=center>'+dayNames[i]+'</td>';table+='</tr>\n';table+='<tr>';if(blah.getDay()!=1)
{var i=-(blah.getDay()+5)%7;for(;i<1;i++)
{workingDate=new Date(blah);workingDate.setDate(i);if((month=(workingDate.getMonth()+1))<10)
{month='0'+month;}
if((day=(workingDate.getDate()))<10)
{day='0'+day;}
id=workingDate.getFullYear()+'-'+month+'-'+day;if(today.getDate()==workingDate.getDate()&&today.getMonth()==workingDate.getMonth()&&today.getFullYear()==workingDate.getFullYear())
{styleClass='calendarWrongToday';}
else if((workingDate.getDay==0)||(workingDate.getDay()==6))
{styleClass='calendarWrongMonthWeekend';}
else
{styleClass='calendarWrongMonthWeekday';}
table+='<td id="'+id+'" '+events+' class='+styleClass+' align=center>';Classes[id]=styleClass;table+=workingDate.getDate();table+='</td>\n';}}
else
{var i=1;}
for(;;i++)
{workingDate=new Date(blah);workingDate.setDate(i);if((month=(workingDate.getMonth()+1))<10)month='0'+month;if((day=(workingDate.getDate()))<10)day='0'+day;id=workingDate.getFullYear()+'-'+month+'-'+day;if(workingDate.getMonth()!=blah.getMonth())
{break;}
if(workingDate.getDay()==1){table+='</tr>\n<tr>';}
if(today.getDate()==workingDate.getDate()&&today.getMonth()==workingDate.getMonth()&&today.getFullYear()==workingDate.getFullYear())
{styleClass='calendarToday';}
else if((workingDate.getDay()==0)||(workingDate.getDay()==6))
{styleClass='calendarWeekend';}
else
{styleClass='calendarWeekday';}
table+='<td id="'+id+'" '+events+' class='+styleClass+' align=center>';Classes[id]=styleClass;table+=workingDate.getDate();table+='</td>\n';}
if(workingDate.getDay()!=1)
{for(;;i++){workingDate=new Date(blah);workingDate.setDate(i);if((month=(workingDate.getMonth()+1))<10)month='0'+month;if((day=(workingDate.getDate()))<10)day='0'+day;id=workingDate.getFullYear()+'-'+month+'-'+day;if(today.getDate()==workingDate.getDate()&&today.getMonth()==workingDate.getMonth()&&today.getFullYear()==workingDate.getFullYear())
{styleClass='calendarWrongToday';}
else if((workingDate.getDay()==0)||(workingDate.getDay()==6))
{styleClass='calendarWrongMonthWeekend';}
else
{styleClass='calendarWrongMonthWeekday';}
table+='<td id="'+id+'" '+events+' class='+styleClass+' align=center>';Classes[id]=styleClass;table+=workingDate.getDate();table+='</td>\n';if(workingDate.getDay()==0)break;}}
table+='</tr>\n'
table+='<tr><td colspan=7 align=center><a href="javascript:calendarClose(0)">Close</a></td></tr>';table+='</table>';var div=document.getElementById('calendarPopup');div.innerHTML=table;div.style.display='block';}
function calcDay(frm,nm,nm2,nm3,day){curr_year=document.forms[frm].elements[nm3].options[document.forms[frm].elements[nm3].selectedIndex].value;var cl,cForm,cMonthYearField,cDayField,cDateField;var mDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31)
var days=["Sun","Mon","Tue","Wed","Thu","Fri","Sat",];var days2=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var d=new Date();dateVal=document.forms[frm].elements[nm].options[document.forms[frm].elements[nm].selectedIndex].value;monthVal=curr_year+document.forms[frm].elements[nm2].options[document.forms[frm].elements[nm2].selectedIndex].value;var isLeapYear=(((monthVal.substr(0,4)%4==0)&&(monthVal.substr(0,4)%100!=0))||(monthVal.substr(0,4)%400==0));mDays[1]=(isLeapYear)?29:28;if(dateVal>mDays[monthVal.substr(4,2)-1]){setDDValue(document.forms[frm].elements[nm],mDays[monthVal.substr(4,2)-1]);dateVal=document.forms[frm].elements[nm].options[document.forms[frm].elements[nm].selectedIndex].value;}
newDate=new Date(monthVal.substr(0,4)+"/"+monthVal.substr(4,2)+"/"+dateVal);}
function setDDValue(elem,val){num=elem.options.length;for(i=0;i<num;i++){if(elem.options[i].value==val){elem.options.selectedIndex=i;}}}
function clickedOutsideElement(elemId,evt){var theElem='';if(window.event){theElem=getEventTarget(window.event);}else{theElem=getEventTarget(evt);}
while(theElem!=null){if(theElem.id==elemId){return false;}
theElem=theElem.offsetParent;}
return true;}
function getEventTarget(evt){var targ=(evt.target)?evt.target:evt.srcElement;if(targ!=null){if(targ.nodeType==3){targ=targ.parentNode;}}
return targ;}


var Cities = new Array();
if (!Cities["Bosnia And Herzegovina"]) Cities["Bosnia And Herzegovina"] = new Array();
Cities["Bosnia And Herzegovina"][0] = "Sarajevo";



function populateCitySelect( country ) {
  newcountry = country.replace(/ /g,'');
  if ( newcountry.length == 0 ) {
    document.theForm.Choice.length = 1;
    document.theForm.Choice.options[0] = new Option('Choose a country:');
    document.theForm.Choice.options[0].value = '';
    return;
  }
  if ( country == 'Holland' ) {
    newcountry = 'Netherlands';
  }
  if ( country == 'Britain' ) {
    newcountry = 'England';
  }
  newOptions = eval(newcountry+'Array');
  document.theForm.Choice.length = 1;
  document.theForm.Choice.options[0] = new Option('Sarajevo');
  document.theForm.Choice.options[0].value = 'CSarajevo;Bosnia And Herzegovina';
  document.theForm.Choice.options[0].selected = true;
  var citylength = newOptions.length + 1;
  for ( i=0; i<newOptions.length; i++ ) {
    document.theForm.Choice.length++;
    thisEntry = newOptions[i];
    newOption = new Option( thisEntry );
    newOption.value = 'C' + thisEntry + ';' + country;
    document.theForm.Choice.options[i+1] = newOption;
  }
  document.theForm.Choice.length = citylength;
  if(newOptions.length == 1) document.theForm.Choice.options[1].selected = true;
}

function makeValidDate() {
  year = document.theForm.selYear.options[ document.theForm.selYear.selectedIndex ].value;
  month = document.theForm.selMonth.options[ document.theForm.selMonth.selectedIndex ].value;
  day = document.theForm.selDay.options[ document.theForm.selDay.selectedIndex ].value;
  maxDay = 31;
  if ( month == 4 || month == 6 || month == 9 || month == 11 ) {
    maxDay = 30;
  } else if ( month == 2 ) {
    if ( year%100 != 0 && year%4 == 0 ) {
      maxDay = 28;
    } else {
      maxDay = 29;
    }
  }
  document.theForm.selDay.selectedIndex = Math.min(day, maxDay)-1;
}
function SwitchTypes(element) {
  if (element.checked == true) {
    if(document.theForm.SelPropTypes_HOSTEL) document.theForm.SelPropTypes_HOSTEL.checked = true;
    if(document.theForm.SelPropTypes_HOTEL) document.theForm.SelPropTypes_HOTEL.checked = true;
    if(document.theForm.SelPropTypes_GUESTHOUSE) document.theForm.SelPropTypes_GUESTHOUSE.checked = true;
    if(document.theForm.SelPropTypes_APARTMENT) document.theForm.SelPropTypes_APARTMENT.checked = true;
    if(document.theForm.SelPropTypes_CAMPSITE) document.theForm.SelPropTypes_CAMPSITE.checked = true;
  } else {
    if(document.theForm.SelPropTypes_HOSTEL) document.theForm.SelPropTypes_HOSTEL.checked = false;
    if(document.theForm.SelPropTypes_HOTEL) document.theForm.SelPropTypes_HOTEL.checked = false;
    if(document.theForm.SelPropTypes_GUESTHOUSE) document.theForm.SelPropTypes_GUESTHOUSE.checked = false;
    if(document.theForm.SelPropTypes_APARTMENT) document.theForm.SelPropTypes_APARTMENT.checked = false;
    if(document.theForm.SelPropTypes_CAMPSITE) document.theForm.SelPropTypes_CAMPSITE.checked = false;
  }
}
function SwitchAllTypes(element) {
  if (element.checked == false) {
    document.theForm.ShowAll.checked = false;
  } else {
    var selectAll = true;
    if(document.theForm.SelPropTypes_HOSTEL && !document.theForm.SelPropTypes_HOSTEL.checked) selectAll = false;
    if(document.theForm.SelPropTypes_HOTEL && !document.theForm.SelPropTypes_HOTEL.checked) selectAll = false;
    if(document.theForm.SelPropTypes_GUESTHOUSE && !document.theForm.SelPropTypes_GUESTHOUSE.checked) selectAll = false;
    if(document.theForm.SelPropTypes_APARTMENT && !document.theForm.SelPropTypes_APARTMENT.checked) selectAll = false;
    if(document.theForm.SelPropTypes_CAMPSITE && !document.theForm.SelPropTypes_CAMPSITE.checked) selectAll = false;
    document.theForm.ShowAll.checked = selectAll;
  }
}

