// $Id: core.js 2191 2009-09-22 03:57:53Z taras $

var CM = new Object; 
var CC = new Object;
var CA = new Object;
var SA = new Object; 
var SS = new Object; 
var JJ = new Object; // joining member
var CO = new Object; // property owner


var AJAX_NAV = 0;

var T = new Array (); // Temp array. Keep here all variables needed
//T['system_images_path'] = 'http://www.distinctiveholidayhomes.com/images/';
T['system_images_path'] = '/images/';

var now_at_server = new Date;
var now_generated;

var form_requests = new Array();
var action_requests = new Array();
var current_page_ext_form = new Array();
var try_count = new Array();
var YAHOO = false;

// cached images
var cim = new Array();
var cimd = new Array();

var homepageSlides = new Array();

var currentLanguage;
var map;

function unload(){
	if (map){
		GUnload();
	}
}

function set_now_at_server(a){
	var x = new Date(a.local_c.year,a.local_c.month-1,a.local_c.day,a.local_c.hour,a.local_c.minute,a.local_c.second);
	now_at_server = x;
	now_generated = new Date;
}
function set_now_at_server_broken(){
//	var x = new Date(a.local_c.year,a.local_c.month-1,a.local_c.day,a.local_c.hour,a.local_c.minute,a.local_c.second);
	now_at_server = new Date;
	now_generated = new Date;
}

function set_today (id){
	var n = now_at_server;
	ge(id+'_year').value = n.getUTCFullYear();
	ge(id+'_month').value = n.getUTCMonth()+1;
	ge(id+'_day').value = n.getUTCDate();
}

function set_now (id){
	var n = now_at_server;
	ge(id+'_year').value = n.getUTCFullYear();
	ge(id+'_month').value = n.getUTCMonth()+1;
	ge(id+'_day').value = n.getUTCDate();
	var hours = n.getUTCHours();
	ge(id+'_min').value = n.getUTCMinutes();
	var half = 'am';
	if (n.getUTCHours() > 12){
		hours = hours-12;
		half = 'pm';
	}
	ge(id+'_hour').value = hours;
	ge(id+'_half').value = half;

}

function kill_wait(){
	var d = ge('the_loading');
	if (d){
		d.parentNode.removeChild(d);
	}

}

function ptiming(where){
	var now = new Date;
	var pt = (now-then)/1000;
	if (getCookie('DHHsession')){
		who = 'Non-public';
	} else {
		who = 'Public';
	}
	requester('timing', '&t0='+pt+'&where='+where+'&who='+who);
}

function requester(what_stuff,params){

	var r = new Object;
	
	r.typ = 'requester';
	r.params = 'w=req&req='+what_stuff;
	r.aborted = false;

	if(params){
		r.params += params;
	}        

	var message = new Message();

  	action_requests.push(r);

	return false;
}

function postquester(what_stuff,params){

	var r = new Object;
	
	r.typ = 'post';
	r.params = 'w=req&req='+what_stuff;
	r.aborted = false;

	if(params){
		r.params += params;
	}        

	var message = new Message();

  	action_requests.push(r);

	return false;
}

function requester1(method,clas,params){
	var r = new Object;
	r.typ = 'Rone';
	r.params = 'w=req1&m='+method+'&c='+clas;
	r.aborted = false;
	if(params){
		r.params += params;
	}        
	var message = new Message();
	action_requests.push(r);
	return false;
}


function fillForm (obj, att){
  resetForm(att);
  var f = document.forms[att];
  var id_elem = f.elements[att+'::object_id'];
  if (id_elem){
    f.elements[att+'::object_id'].value = obj.object_id;
  } else {
    var elem = ce("INPUT");
    elem.type = 'hidden';
    elem.name = att+'::object_id';
    elem.value = obj.object_id;
    f.appendChild(elem);
  }
  var pref = att;
  setFormFields (f, pref, obj,att);
  init();
  checkLocation();
  upload_tinyMCE(att);
}

function resetForm(name){
	if(!document.forms[name]){	
		alert('resetForm: Form '+ name +' doesnt exist');
		return false;
	}	
	document.forms[name].reset();
	if (document.forms[name][name+'::object_id']){
		document.forms[name][name+'::object_id'].value='';
	}

  	rows = getElementsByAttribute(ge(name), 'date', 'Y','input');

	for (var r in rows){
		//FIXME this is wrong
		rows[r].value = '0-0-0'; 
	}

//	if(window.set_onfocus_for_members_details) {
//		set_onfocus_for_members_details(name);
//	}
}

function setFormFields (f, pref, obj, att){

  //FIXMe - form id and fld name
	var formid = att + '_';
	for (var p in obj){
		if (obj[p] && obj[p].local_c){
			var fld = ge(formid+pref +'::'+ p);
			if (fld){
      			var fld_target = fld.firstChild;
     			 	if(! fld_target) {
							fld.innerHTML = obj[p].local_c.day + "-" + obj[p].local_c.month + "-" + obj[p].local_c.year;
							if(fld.getAttribute('need_oid')) {
							fld.innerHTML += '<input type="hidden" name="'+ att +'::'+p+'" value="'+ fld.innerHTML +'">';
						}
				} else {	
					if (fld_target.nodeName == '#text'){
						if(ge(formid+pref+"::"+p+'_day') && obj[p]){
							ge(formid+pref+"::"+p+'_day').value = obj[p].local_c.day;
							ge(formid+pref+"::"+p+'_month').value = obj[p].local_c.month;
							ge(formid+pref+"::"+p+'_year').value = obj[p].local_c.year;
							var art = time24to12(obj[p].local_c.hour);
							var half = art.half;
							var hour = art.hour;
							ge(formid+pref+"::"+p+'_hour').value = hour;
							ge(formid+pref+"::"+p+'_min').value = obj[p].local_c.minute;
							ge(formid+pref+"::"+p+'_half').value = half;
							updateDate(formid+pref +'::'+ p);
						} else {
							fld_target.nodeValue = obj[p].local_c.day + "/" + obj[p].local_c.month + "/" + obj[p].local_c.year;
						}  
					} else {
						if(ge(formid+pref+"::"+p+'_day') && obj[p]){
							ge(formid+pref+"::"+p+'_day').value = obj[p].local_c.day;
							ge(formid+pref+"::"+p+'_month').value = obj[p].local_c.month;
							ge(formid+pref+"::"+p+'_year').value = obj[p].local_c.year;
							var art = time24to12(obj[p].local_c.hour);
							var half = art.half;
							var hour = art.hour;
							ge(formid+pref+"::"+p+'_hour').value = hour;
							ge(formid+pref+"::"+p+'_min').value = obj[p].local_c.minute;
							ge(formid+pref+"::"+p+'_half').value = half;
							updateDate(formid+pref +'::'+ p);
						} else {
							fld_target.nodeValue = obj[p].local_c.day + "/" + obj[p].local_c.month + "/" + obj[p].local_c.year;
						}
       				}
    				 }
			}
	} else if (typeof(obj[p]) == 'string' || typeof(obj[p]) == 'number') {
      var fld = ge(formid+pref +'::'+ p);
      if (fld){
    		var fld_target = fld.firstChild;
    		var res = obj[p];
    		if(p == 'object_id'){
   				res = obj.to_string;
    		}

    		if(fld.getAttribute('need_oid')) {
    			var n = fld.getAttribute('need_oid');
    			if(p == 'object_id') {
    				res += '<input type="hidden" name="'+ n +'" value="'+ obj.object_id +'">';
    			} else {
	    			res += '<input type="hidden" name="'+ n +'" value="'+ res +'">';
    			}
				}

    	  if(! fld_target) {
   	  		fld.innerHTML = res;
      	} else {
      	  if (fld_target.nodeName == '#text'){
						if(res){
	      	    fld.removeChild(fld_target);
	      	    fld.innerHTML = res;
	      		}
      	    
					} else if (fld_target.nodeName == 'SPAN'){ // autocomplete, FIXME: better checks here please ;-(
						// FIXMENOW by id please
						fld_target.firstChild.value = obj[p];
						fld_target.firstChild.nextSibling.value = obj.to_string;

          } else if (fld_target.nodeName == 'IMG'){
						
            fld_target.parentNode.removeChild(fld_target);
            fld.innerHTML = ''; 
						fld.className = 'gchd';
						var he = 344; //344
						var wi = 736;
            fld.style.height = he + 'px';
            fld_target = ce("IMG");

//						VERY DIRTY HACK FIXME ASAP
						if (pref+'::'+p != 'Destination::area_info::image'){
	            fld_target.src = T['system_images_path']+obj[p];
						}	

	     			T['faq_first_image'] = fld_target.src;
            
						fld_target.style.display='block';

						fld.appendChild(fld_target);

						fld_target.height = he;
						fld_target.width = wi;
						fld_target.style.height = he + 'px';
						fld_target.style.width = wi + 'px';

						// FIXME ASAP
          } else if ((fld_target.nodeName == 'P') || (fld_target.nodeName == 'UL') || (fld_target.nodeName == 'H3') || (fld_target.nodeName == 'H2') || (fld_target.nodeName == 'TABLE') ||(fld_target.nodeName == 'DIV')){
						fld.removeChild(fld_target);
						fld.innerHTML = obj[p];
      	  } else {
        		fld_target.value = obj[p];
          }
        }
      } else {
      //FIXME do something nasty
      }
    } else if (typeof(obj[p]) == 'object'){
			var fld = ge(formid+pref +'::'+ p);
			if(obj[p] == null && fld){
				var fld_target = fld.firstChild;
				if (!fld_target) {
					fld.innerHTML = '';
				} else {
					if (fld_target.nodeName == '#text'){
						fld_target.nodeValue = '';
					} else {
						fld_target.value = '';
					}				
				}
			}
			else {
				setFormFields (f, pref+'::'+p, obj[p], att);
			}

    } else if (typeof(obj[p]) == 'function'){
			// silently skip it
		} else {    
			alert('dunno how to process the thing: ' + typeof(obj[p]) + ' Value: ' + p + ' Pref: ' + pref);
    }
  }
//	window.setTimeout(MS_idiots, 5000);
}

function MS_idiots(){
	if (ge('container')){
		ge('container').style.width='962px';
	}
	if (ge('container2')){
		ge('container2').style.width='380px';
	}
}

function init(){

  var rows = new Array();
  rows = getElementsByClass(document, 'ztd','td');

	if(rows.length>0) {
		for (var r in rows){
			var id = rows[r].getAttribute('open');
			var ifExists = ge('d'+id+'_child');
	
				rows[r].onclick = function req() {
								var id = this.getAttribute('open');
								var att = this.getAttribute('att');
								var nw = this.getAttribute('new');
								ge('indicator').style.display='';
	
								toggleDrags('d'+id, 0);
								closeParent['d'+id+'_child'] = 'd'+id;


								var ifExists = ge('d'+id+'_child');
								if (ifExists){
									if(nw == 'new'){
										if (document.forms[att][att+'::object_id']){
											document.forms[att][att+'::object_id'].value = '';
										} else {
											alert(att+'::object_id was not in the form. ignoring...' );
										}
										document.forms[att].reset();
										ifExists.style.display = 'block';
										ge('indicator').style.display='none';
										
										init();
										ge('del_button').style.display = 'none';	
									}
									else {
										var url = '/ajax.pl?id='+this.id+'&w=g&class='+att+'&x='+x+'&y='+y + '&multilang=1';
										document.forms[att].reset();
										loadJSON(url, 'fillForm', att);
									}
									ifExists.style.display = 'block';
								}
								else  {
									ge('indicator').style.display='';
									if(nw == 'null'){
										var url = '/ajax.pl?id='+id+'&w=gf'+'&x='+x+'&y='+y;
									}
									else {
										var url = '/ajax.pl?id='+id+'&w=gfd&did='+this.id+'&class='+att+'&x='+x+'&y='+y+'&multilang=1';
									}
									loadJSON(url, 'getForm', att);		
								}
							};
							
		}
	
	}
  rows = getElementsByAttribute(document, 'control', 'arl','td');
	for (var r in rows){
		rows[r].onclick=reqA;
	}
}


function hasClass( object, className ) {
	if(object){
		var SEP = '(^|$| )';
		var regex = new RegExp( SEP + className + SEP );
		return regex.test( object.className );
	}
	else {
		return false;
	}
}


function getElementsByAttribute( object, atr_name, atr_value, tags ) {

        if (!tags){
                tags  = '*';
        }
        var classElements = new Array();

        var allElements = object.getElementsByTagName( tags );

        for (var i=0;i < allElements.length;i++) {
                if ( allElements[i].getAttribute( atr_name ) == atr_value) {
                        classElements.push(allElements[i]);
                }
        }

        return classElements;
}

function getElementsByName(object, elem_name){
	var ret = new Array;
	if (object){
		var ae = object.getElementsByTagName('*');
		for (var i=0; i<ae.length; i++){
			if (ae[i].name == elem_name){
				ret.push(ae[i]);
			}
		}
	}
	return ret;
}

function getElementsByClass( object, cls, tags ) {
        if (!tags){
                tags  = '*';
        }
        var classElements = new Array();

        var allElements = object.getElementsByTagName( tags );

		for (var i=0; allElements.length > i ; i++) {
    
                if ( hasClass( allElements[i], cls ) ) {
                        classElements.push( allElements[i] );
                }
        }

        return classElements;
}

function time24to12 (hour) {
	var half = 'am';
	hour = parseInt(hour, 10);
	if(hour > 12) {
		hour = hour - 12;
		half = 'pm';
	}
	if(hour == 12) {
		half = 'pm';
	}
	if(hour == 0) {
		hour = 12;
		half = 'am';
	}
	var ret = new Object;
	ret.hour = hour;
	ret.half = half;
	return ret;
}

function time12to24 (hour,half) {
	var h = hour;
	h = parseInt(h);
	if(half == 'pm' && h != 12) {
		h += 12;
	}
	if(half == 'am' && h == 12) {
		h = 0;
	}
	var ret = new Object;
	ret.hour = h;
	return ret;
}

function updateDate (id, strict, auto,  date_only) {
	var month;
	var year;
	var mif = ge(id + '_month').value;
	var yif = ge(id + '_year').value;
	var myDate = now_at_server;
	cmonth = myDate.getUTCMonth()+1;
	cyear = myDate.getUTCFullYear();
	cday = myDate.getUTCDate();
	if(auto && mif == 0 && yif == 0) {
		month = cmonth;
		year = cyear;
		ge(id + '_month').value = cmonth;
		ge(id + '_year').value = cyear;
	} else {
		month = mif || 0;
		year = yif || 0;
	}
	var day = ge(id + '_day').value || 0;
	var hour = 0;
	if(ge(id + '_hour')) {
		hour = ge(id + '_hour').value || 0;
	}

	if(!date_only) {
		var min = 0;
		if(ge(id + '_min')) {
			min = ge(id + '_min').value || 0;
		}
		var half = 'am';
		if(ge(id + '_half')) {
			half = ge(id + '_half').value;
		}
	}
	
	if(strict && day!=0 && month!=0 && year!=0) {

		var cDate = now_at_server;
		cDate.setUTCFullYear(year);
		cDate.setUTCMonth(month-1);
		cDate.setUTCDate(day);
		
		if(cDate < myDate) {
			
			ge(id + '_day').value = cday;
			ge(id + '_month').value = cmonth;
			ge(id + '_year').value = cyear;		
			ge(id + '_hidden').value = cday +'-'+ cmonth +'-'+ cyear;
		} else {
			ge(id + '_hidden').value = day +'-'+ month +'-'+ year;
		}
	} else { 
		var rd = days_in_month(year,month-1);
		if(day > rd) {
			day = rd;	
		}
		if(!date_only) {
			ge(id + '_hidden').value = day +'-'+ month +'-'+ year + '-' + hour + '-' + min + '-' + half;
		} else {
			ge(id + '_hidden').value = day +'-'+ month +'-'+ year;
		}
	}
	if (auto && strict) {
		updateDate(id,'strict');
	}	
}


function attachForm (frm_id, where, robj){

	if(!where) {
		where = 'container';	
	
	}

	var cont = ge(where);
	if (!cont){
		alert('system integrity violation.\nThe application is not usable. Missing element id = '+where);
		return;
	}
	if (frm_id == 'MassMail'){
		if (tinyMCE.getInstanceById('massmail_body') != null){
			tinyMCE.execCommand('mceRemoveControl', false, 'massmail_body');
		}
	} else if (frm_id == 'PressRelease'){
		if (tinyMCE.getInstanceById('pr_body') != null){
			tinyMCE.execCommand('mceRemoveControl', false, 'pr_body');
		}
	} else if (frm_id == 'MessageTemplate'){
		if (tinyMCE.getInstanceById('mt_body') != null){
			tinyMCE.execCommand('mceRemoveControl', false, 'mt_body');
		}
	} else if (frm_id == 'ThingToDo'){
		if (tinyMCE.getInstanceById('thingtodo_body') != null){
			tinyMCE.execCommand('mceRemoveControl', false, 'thingtodo_body');
		}
	} else if (frm_id == 'PracticalInfo'){
		if (tinyMCE.getInstanceById('pi_body') != null){
			tinyMCE.execCommand('mceRemoveControl', false, 'pi_body');
		}
	}
	var frm = ge(frm_id);
	if (!frm){
		cont.innerHTML = 'Loading template...';
		var r = new Object;
		r.typ = 'form';
		if (frm_id.indexOf('faq') == -1){
			r.params = 'w=gforms';
		} else {
			r.params = 'w=gtext';
		}
		r.clas = frm_id;

		current_page_ext_form['id'] = frm_id;
		current_page_ext_form['target'] = where;
		
		//FIXME: Proper check if in member's area
		if(where == 'the_details'){
			if (robj) {
				current_page_ext_form['form_data'] = robj; 
			}
			current_page_ext_form['member'] = 1; 
			cont.innerHTML = '<div class="m_details">' +'Loading template...' + '</div>';
		} else {
			cont.innerHTML = 'Loading template...';
		}
		form_requests.push(r);
		try_count[frm_id] = 0;
	} else {
		if (cont.firstChild){
			if (cont.firstChild.id != frm_id){			
				resetForm(frm_id);
				var attic = ge('attic');
				attic.appendChild(cont.firstChild);
				cont.appendChild(frm);
				
			}
		} else {
			cont.appendChild(frm);
		}
	}
	
	hideUnwantedFields(frm_id);
}

function hideUnwantedFields(frm_id){

	if (frm_id == 'JoinApplication') {
	
		//FIXME What to do if form still hasnt arrived yet?
			//How are we gonna hide unwanted fields?
					
		var tmp;
		tmp = ge(frm_id+'_'+frm_id+'::physical_address::owner_guest::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::physical_address::owner_member::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::physical_address::owner_familymember::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}		
	
	
		tmp = ge(frm_id+'_'+frm_id+'::postal_address::owner_guest::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::postal_address::owner_member::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::postal_address::owner_familymember::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}		
	
	
		if(currentLanguage == 'en') {
		
			tmp = ge(frm_id+'_'+frm_id+'::applicant::personal_info_en::first_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';
				tmp.parentNode.previousSibling.className = 'displaynone';	
			}
			tmp = ge(frm_id+'_'+frm_id+'::applicant::personal_info_en::last_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';		
			}
			tmp = ge(frm_id+'_'+frm_id+'::applicant::personal_info_en::middle_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';	
			}
			
			tmp = ge(frm_id+'_'+frm_id+'::applicants_partner::personal_info_en::first_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';
				tmp.parentNode.previousSibling.className = 'displaynone';	
			}
			tmp = ge(frm_id+'_'+frm_id+'::applicants_partner::personal_info_en::last_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';		
			}
			tmp = ge(frm_id+'_'+frm_id+'::applicants_partner::personal_info_en::middle_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';	
			}			
		
		}
	
	} else if (frm_id == 'InfoRequest') {
		
		//FIXME What to do if form still hasnt arrived yet?
			//How are we gonna hide unwanted fields?
			
		var tmp;
		tmp = ge(frm_id+'_'+frm_id+'::address::owner_guest::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::address::owner_member::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::address::owner_familymember::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}		
	
	
		tmp = ge(frm_id+'_'+frm_id+'::phone::owner_guest::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::phone::owner_member::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::phone::owner_familymember::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}		
	
	
		if(currentLanguage == 'en') {
		
			tmp = ge(frm_id+'_'+frm_id+'::applicant::personal_info_en::first_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';
				tmp.parentNode.previousSibling.className = 'displaynone';	
			}
			tmp = ge(frm_id+'_'+frm_id+'::applicant::personal_info_en::last_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';		
			}
			tmp = ge(frm_id+'_'+frm_id+'::applicant::personal_info_en::middle_name');
			if(tmp) {
				tmp.parentNode.className = 'displaynone';	
			}
		
		}
	
	} 


	if(currentLanguage == 'en') {

		var tmp;

		tmp = ge(frm_id+'_'+frm_id+'::personal_info_en::object_id');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';
			tmp.parentNode.previousSibling.className = 'displaynone';	
		}		
		tmp = ge(frm_id+'_'+frm_id+'::personal_info_en::first_name');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';
			tmp.parentNode.previousSibling.className = 'displaynone';	
		}
		tmp = ge(frm_id+'_'+frm_id+'::personal_info_en::last_name');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';		
		}
		tmp = ge(frm_id+'_'+frm_id+'::personal_info_en::middle_name');
		if(tmp) {
			tmp.parentNode.className = 'displaynone';	
		}

	
	}

	
	if(ge(frm_id+'_submit_button') && ge(frm_id+'_submit_button').disabled == true) {
		ge(frm_id+'_submit_button').disabled = false;
	}
}

function SetCookie(cookieName,cookieValue,nDays,path) {
 var today = new Date();
 var expire = new Date();
 var exp = '';
 if (!(nDays==null || nDays==0)) {

	expire.setTime(today.getTime() + 3600000*24*nDays);
	exp = 'expires=' + expire.toGMTString();
	
 }
 var pa = '';
 path = '/';
 if (path){
	pa = ";path="+path;
 }
 document.cookie = cookieName+"="+escape(cookieValue) + ";"+exp+";"+pa;
}


function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

// move to admin
function reqA (){
    var att = this.id;

    var frm = document.forms[this.getAttribute('att')];
    var theid = frm.elements[this.getAttribute('att')+'::object_id'];

	toggleDrags('d'+openedArrayForms[this.getAttribute('att')]+'_child', 0);
	
	if(!openedArrayForms[att]){
		ge('indicator').style.display='';
		var url = '/ajax.pl?id='+theid.value+'&w=ga&class='+this.id+'&caller_id='+this.getAttribute('caller_id')+'&x='+x+'&y='+y+'&multilang=1';
		loadJSON(url,'getArrayForm',att,'d'+openedArrayForms[this.getAttribute('att')]+'_child');
	}
	else {
		toggleDrags('d'+openedArrayForms[att], 0);
		closeParent['d'+openedArrayForms[att]] =  'd'+openedArrayForms[this.getAttribute('att')]+'_child';
		
	}

}
// end of admin

//
function init_propaganda_fixes (){
	var message = new Message();
	if (current_class == 'Destination'){
		make_root_table2(current_class);
	} else {
		make_root_table(current_class);
	}
	killMessage();
}

function init_fixes (){

	var message = new Message();
	restore_propaganda_td();
	make_root_table("RegionDHH");
	make_root_table("CountryDHH");
	make_root_table2("Destination");
	killMessage();

}

function init_class_fixes (c){

//	if (current_class == 'Destination'){
//		make_root_table2(current_class);
//	} else {
//		make_root_table(current_class);
//	}
//return;
	var message = new Message();
	restore_propaganda_td();
	make_root_table("Propaganda");
	make_root_table("RegionDHH");
	make_root_table("CountryDHH");
	make_root_table2("Destination");
	killMessage();

}



function make_root_table (ref_form_id){
	var ref_table = ge(ref_form_id+'_tab');
	if (!ref_table){
		setTimeout("make_root_table('"+ref_form_id+"')", 200);
		return;
	}

	ref_table.width="962px";
	ref_table.align="center";
	ref_table.cellPadding="0";
	ref_table.cellSpacing="0";
	ref_table.border="0";
	var extra = '';
	if (ref_form_id == 'Destination'){
		extra = '::area_info';
	}
	var img_row = ge(ref_form_id+ "_" + ref_form_id + extra+"::image").parentNode;
	var img_td = ge(ref_form_id+ "_" + ref_form_id + extra+"::image");
	img_td.style.fontsize = "1px";
	img_td.vAlign = 'top';
	var img = img_td.firstChild;

	make_midrow(ref_table, 2, 1);
	make_footer(ref_table, 2);


	var ref_row = img_row;
	var ref_td = img_td;
	var td = ce('TD');
	td.innerHTML='<img src="/images/system/1x1.gif" width="194" height="0" style="margin:0;display:block;"><img src="/images/manual/dhh_med.jpg" style="margin-left: 5px;">';
	td.width = "200px";
	td.id = "dhh_logo";
	td.ondblclick = make_menu;
	td.setAttribute('dhh_logo', 1);	
	td.className = 'greycontent';
	td.style.verticalAlign = 'top';
	ref_row.insertBefore(td, ref_td);
	if (ref_form_id == 'Propaganda'){
		ge(ref_form_id+ "_" + ref_form_id + "::heading::curlang").colSpan="2";
		ge(ref_form_id+ "_" + ref_form_id + "::heading::curlang").align="center";
		ge(ref_form_id+ "_" + ref_form_id + "::content::curlang").colSpan="2";
	} else if (ref_form_id == 'RegionDHH' || ref_form_id == 'CountryDHH'){
		ge(ref_form_id+ "_" + ref_form_id + "::name::curlang").colSpan="2";
		ge(ref_form_id+ "_" + ref_form_id + "::name::curlang").align="center";

	}
	ref_table.style.display = '';
}


function make_link (lnk){
	var txt;
	for (var i =0; i<jsmenu.length; i++){
		if (jsmenu[i].uri == lnk){
			txt = jsmenu[i].title;
			break;
		}
	}
	var t = '<a href="javascript:goto(\''+lnk+'\');">'+txt+'</a>';
	return t;
}

function make_footer(ref_table, cs){
	var tr0 = ref_table.insertRow(ref_table.rows.length);
	var t0 = tr0.insertCell(0);
	t0.colSpan = cs;
	var t = ce('TABLE');
	t.width = "100%";
	t.cellPadding = "0";
	t.cellSpacing = "0";
	t.border = "0";
	t.id = "footer_tab";
	var bg = '#40402D';

	t0.appendChild(t);
	var tr = t.insertRow(0);
	var t1 = tr.insertCell(0);
	t1.innerHTML='&nbsp;';
	t1.width="20%";
	t1.style.backgroundColor=bg;

	var t2 = tr.insertCell(1);
	t2.style.whiteSpace='nowrap';
	t2.innerHTML = make_link('contact_us');
	t2.className='subnav_f';

	var t3 = tr.insertCell(2);
	t3.style.whiteSpace='nowrap';
	t3.innerHTML = make_link('tell_a_friend');
	t3.className='subnav_f';

	var t4 = tr.insertCell(3);
	t4.style.whiteSpace='nowrap';
	t4.innerHTML = make_link('request_info');
	t4.className='subnav_f';

	var t5 = tr.insertCell(4);
	t5.innerHTML="&nbsp;";
	t5.width="20%";
	t5.style.backgroundColor=bg;

}

function make_midrow(ref_table, cs, idx){
	var tr0 = ref_table.insertRow(idx);
	var t0 = tr0.insertCell(0);
	t0.colSpan = cs;
	t0.className = 'image_caption';
	t0.id = 'im_caption';
	t0.innerHTML='&nbsp;';
	return tr0;
}

function killMessage(){
	var m = ge('message');
	if (m){
		m.parentNode.removeChild(m);
	}
}


function check_browser(){
	if (	navigator.userAgent.indexOf('MSIE 3.') != -1 ||
		navigator.userAgent.indexOf('MSIE 5.') != -1 ||
		navigator.userAgent.indexOf('Safari/100') != -1 ||
		navigator.userAgent.indexOf('Safari/8') != -1 ||
		navigator.userAgent.indexOf('Netscape6') != -1 ||
		navigator.userAgent.indexOf('Netscape/7') != -1 ||
		navigator.userAgent.indexOf('Mozilla/3') != -1 ||
		navigator.userAgent.indexOf('Mozilla/4.8') != -1

	){
		window.location = '/nosupport.html';
	}
}

var Throbber = document.createElement('IMG');
Throbber.src =  "/skin/std/images/throbber.gif";
Throbber.align = "middle";
Throbber.style.marginLeft = "0px";

function Message( message ) {
	this.element = ce( "div" );
	this.element.id = "message";
		
	if(document.all){
		this.element.style.position='absolute';
	} else {
//		this.element.style.position='fixed';
	}
	
	this.image = Throbber;
	this.element.appendChild( this.image );

	var indicator = ge('m_indicator');
	
	this.body = indicator;	
	this.body.appendChild(this.element);

	if(document.all){
	    this.element.style.top = document.documentElement.scrollTop;
	} else {
		this.element.style.top = 0;
	}

	// Rejig everything for the IE7 suff
	if ( document.recalc ) {
		document.recalc();
	}

	if ( message ) {
		this.updateMessage( message );
	}
}

Message.prototype.updateMessage = function(message) {
	var tmpid = new Date().getTime();
	this.element.innerHTML = '<a href="#" style="margin:0;padding:0;height:0;width:0;" id="' + tmpid + '"></a>' + message;
	ge(tmpid).focus();

}

Message.prototype.addClose = function() {
	this.element.appendChild( ce("br"));
	var okElement = ce("button");	
	okElement.innerHTML = "OK";
	var self = this;
	okElement.onclick = function( ) { self.close( self ) };
	okElement.className = "button";	
	var lastChild = this.element.childNodes[ this.element.childNodes.length - 1 ];
	this.element.appendChild( okElement );
}

Message.prototype.close = function (self) {
	self.body.removeChild( this.element );
	self.body = null;
	self.element = null;
	self.image = null;
}
//end


function pm_link(active, link, text){
	active = 1;
	var t = '';
	var a_class='';
	if (!active){a_class = " subnav3_n";}
	t += '<ul class="subnav3'+a_class+'">';
	t += '<li style="z-index:1;">';
	if (active){
		t += '<a href="javascript:goto(\''+link+'\');">'+text+'</a>';
	} else {
		t += '<a href="javascript:void(0);" onClick="return false;">'+text+'</a>';
	}
	t += '</li></ul>';
	return t;
}

function insert_link(uri){
	var h = '';
	var active;
	for (var i=0; i<jsmenu.length; i++){
		if(CFO.object_id == jsmenu[i].id) {
			active = 0;
		} else { active = 1;}
		if (jsmenu[i].uri == uri){
			h = pm_link(active,jsmenu[i].uri, jsmenu[i].title);
			break;
		}
	}
	return h;
}

function propaganda_minimenu (s){
	if (CM.object_id){
		return false;
	}
	var path;
	if (window.location.pathname.split('/').length > 2){
		path = window.location.pathname.split('/')[3];
	}
	if (path && path.indexOf('hcc')!=-1 || window.location.pathname.indexOf('hcc') != -1){
		SetCookie('hcc',1);
	} else {
  		var mes = getElementsByAttribute(ge('listMenuRoot'), 'oid', '5B9CC8C14195243AE04040454A4051F3','a');
			var me = mes[0];
			if (me){
				zap_if(me.parentNode);
			}
	}
	var check = ge('dhh_logo');
	if(!check) {
		return false;
	}

	zap_if(ge('propaganda_menu'));

	var hcc = getCookie('hcc');	
	var fixed_links;
	if (hcc){
		fixed_links = new Array ('plans', 'hcc_special','availability', 'member_comments', 'request_info', 'try_before_you_buy', 'tell_a_friend', 'contact_us', 'press_articles');
	} else {
		fixed_links = new Array ('plans', 'availability', 'member_comments', 'request_info', 'try_before_you_buy', 'join', 'tell_a_friend', 'contact_us', 'press_articles');
	}
	var html = '';
	var t = ''
	html += list_all_destinations();
	html += '<div id="reg_links">';
	for (var i = 0; i<fixed_links.length; i++){
		html += insert_link(fixed_links[i]);
	}

	html += '</div>';	

	var pl = ge('dhh_logo');
	var d=ce('DIV');
	pl.appendChild(d);
	d.id= "propaganda_menu";
	d.style.marginLeft="12px";
	d.style.marginTop="5px";
	d.innerHTML = html;

}

function minimenu_loop(fixed_links, links_no, main){
	var cnt = 0;
	var show = 0;
	var t = '';
	var active = 0;
OUTER:
	for(var i=0; i < jsmenu.length; i++) {
		if (jsmenu[i].title == 'Login'){continue;}
			if (main){
				if (i != 0 && CFO.object_id == jsmenu[i+1].id){
					show = 1;
				}
				if(CFO.object_id != jsmenu[i].id) {
					active = 1;
				} else  {
					active = 0;
					show = 1;
				}
		} else {
			show = 1;
			active = 1;
		}
		if (!show){continue};
		for (var j=0; j<fixed_links.length; j++){
			if (fixed_links[j] == jsmenu[i].uri){ continue OUTER;}
		}
		cnt++;
		t += pm_link(active, jsmenu[i].uri, jsmenu[i].title);
		if (cnt > links_no){break;}
	}
	var r = new Object;
	r.t = t;
	r.cnt = cnt;
	return r;
}


function getDestLab(){
	var o = new Object;
	o.lab = jssm['misc_menu']['other_destinations'];
	o.map_link = 0;
	if (!CFO.readiness){
		o.lab = jssm['misc_menu']['destinations'];
		o.map_link = 1;
	}
	return o;
}

function list_all_destinations () {

	var type_id;
	var ps = new Array;
	for (var i=0; i<points.length; i++){
		if (CFO.object_id != points[i].object_id){
			ps.push(points[i]);
		}
	}
	ps.sort(compareRegions);

	var o = getDestLab();
	var lab = o.lab;
	var map_link = o.map_link;
	var lft = '170';
	if (CM.object_id) {
		lft = '153';
	}
	var r = '<div id="all_dest_links" style="width:' + lft +'px;padding:0; border-bottom:solid 1px #a0a0a0;">';
	r += '<div id="d_sw" onclick="d_sw1();" style="cursor:hand; cursor:pointer; margin:0px;">';


	var path='info';
	var cla1 = "dlist1x";
	if (window.location.pathname.split('/').length > 2){
		path = window.location.pathname.split('/')[2];
	}



	r += '<ul class="subnav3" style="width:'+ lft +'px;" id="d_ul">';
	r += '<li><a id="ds_a" href="javascript:void(0);">'+lab+expd(0)+'</a></li></ul></div>';
	r += '<div id="dest_cont" style="display:none;">';
	if (o.map_link){
		r += '<ul id="reg_ul" class="subnav3">';
		r += '<li style="width:'+ lft +'px";>';
		r += '<a href="javascript:goto(\'browse_by_map\');" title="'+jssm['misc_menu']['browse_by_map_title']+'">'+jssm['misc_menu']['browse_by_map']+'</a>';
		r += '</li></ul>';
	}
	if (path == 'destination'){
		cla1 = "dlist2x";
	}
	var old_reg = 'NADA';
	r += '<table style="margin-left:-2px;"><tr>';
	for (var i =0; i<ps.length; i++) {
		if (ps[i].readiness == 'future'){continue;}
		if (old_reg != ps[i].regiondhh){
			if (old_reg != 'NADA'){
//	r += '</td>';
				r += '</ul>';
			}
			old_reg = ps[i].regiondhh;
	r += '<td valign="top" bgcolor="#555542">';
			r += '<ul shh="'+old_reg+'" id="reg_ul" class="subnav3"><span class="rul">' + old_reg + ':</span>';
		}
		r += '<li style="width:'+ lft +'px"; sh="'+old_reg+'">';
		if (ps[i].readiness != 'future'){
			if (CM.object_id) {
				r += '<a style="margin:0px;" href="javascript:void(0);" onclick="return yoyo(\''+ps[i].object_id+'\',\'Destination\');" title="'+ps[i].short_desc+'">'+ps[i].name+'</a>';
			} else {
				r += '<a href="javascript:goto(\''+ps[i].uri+'\');" title="'+ps[i].short_desc+'">'+ps[i].name+'</a>';
			}
    		} else {
					r += '<a style="margin:0px;" href="javascript:void(0);" title="'+ps[i].short_desc+'" onclick="return warn_future();">'+ps[i].name+'</a>';
    		}
		r += '</li>';
	}
	r += '</ul>';
	r += '</td></tr></table>';
	r += '</div>';
	r += '</div>';
	r += '</div>';
	return r;

}


function expd(how){
	var path='info';
	var wid = 86;
	if (window.location.pathname.split('/').length > 2){
		path = window.location.pathname.split('/')[2];
	}
	if (path == 'destination'){
		wid = 36;
	}
	var ext = '<span style="position:relative;left:'+wid+'px;">';
	if (how == 1){
		ext += 'v';
	} else {
		ext += '>';
	}
	ext += '</span>';
	return ext;
}

function d_sw1(){
	ge('d_sw').blur();
	var dl = ge('dest_cont');
	var re = ge('reg_links');
	var d_s = ge('d_ul');
	var ext = 0;
	if (dl){
		if (dl.style.display == 'none'){
			if(re) {
				re.style.display='none';
			}
			d_s.className='subnav3_n';
			d_s.style.backgroundColor = '#cccccc';
			ge('ds_a').style.cursor = 'pointer';
			dl.style.position='absolute';
			dl.style.display = '';
			dl.style.zIndex=5000;
			ext = 1;
		} else {
			dl.style.display = 'none';
			d_s.className='subnav3';
			d_s.style.backgroundColor = '#8a7b53';
			if(re) {
				re.style.display = '';
			}
		}
		var lab = getDestLab().lab;
		ge('ds_a').innerHTML = lab+expd(ext);
	}
	return false;
}

function add_image_caption (obj) {
	paint_image_caption(obj.image_caption.curlang);
	return false;
}

function paint_image_caption (what){
	if (!what){
		what = '&nbsp;';
	}
	var cp = ge('im_caption');
	if (cp){
		cp.style.display='';
		cp.innerHTML = what;
	}

}




function ge (id){
	return document.getElementById(id);
}

function ce (tag){
	return document.createElement(tag);
}


function zap (el){
	return el.parentNode.removeChild(el);
}

function zap_if(el) {
	if (el){
		return zap(el);
	}
}
function upload_tinyMCE(form_id){
		if (CA.object_id){
		} else if (CC.object_id){
			if (form_id == 'ThingToDo'){
				if (tinyMCE.getInstanceById('thingtodo_body') != null){
					tinyMCE.updateContent('ThingToDo::description::curlang');
					tinyMCE.updateContent('thingtodo_body');
				}
			} else if (form_id == 'PracticalInfo'){
				if (tinyMCE.getInstanceById('pi_body') != null){
//					tinyMCE.updateContent('ThingToDo::description::curlang');
					tinyMCE.updateContent('pi_body');
				}

			}
		}
}

function goto_old(url){
	for (var i in uris){
		if (i.indexOf('array') != -1){continue;}
		if (i == url){
			yoyo(uris[i].id, uris[i].clas);
			break;
		}
	}
}

function goto(url){
	var lan = getCookie('lang');
	if (!lan || lan==''){
		lan = 'en';
	}
	if (window.location.pathname && window.location.pathname != '/'){
		lan = (window.location.pathname.split('/'))[1];
	} else {
		lan = 'en';
	}
	for (var i in uris){
		if (i.indexOf('array') != -1){continue;}
		if (i == url){
			var c;
			if (uris[i].clas == 'Propaganda'){
				c = 'info';
			} else {
				c = uris[i].clas.toLowerCase();
			}
			clear_timeouts();
			var fu = '';
			if (JJ && JJ.object_id){
				fu = 'http://www.distinctiveholidayhomes.com';
				lan = 'en';
			}
			window.location=fu + '/'+lan+'/'+c+'/'+url+'.html';
			break;
		}
	}
}

function clear_timeouts(){
 	if (mo_to){
		window.clearTimeout(mo_to);
	}
	if (ss_to2){
		window.clearTimeout(ss_to2);
	}
	if (ss_to){
		window.clearTimeout(ss_to);
	}

}


function make_root_table2 (ref_form_id){
	var ref_table = ge(ref_form_id+'_tab');
	if (!ref_table){
		setTimeout("make_root_table2('"+ref_form_id+"')", 200);
		return;
	}


	ge('Destination_Destination::area_info::object_id').colSpan="2";
	ge('Destination_Destination::area_info::info::curlang').colSpan="2";
	ge('Destination_Destination::inventory_info::curlang').colSpan="2";
	ge('Destination_Destination::activities_info::curlang').colSpan="2";
	ge('Destination_Destination::overview::object_id').colSpan="2";
	ge('Destination_Destination::overview::image').colSpan="2";
	ge('Destination_Destination::overview::info::curlang').colSpan="2";
	ge('Destination_Destination::layout_image').colSpan="2";

	ref_table.width="962px";
	ref_table.align="center";
	ref_table.cellPadding="0";
	ref_table.cellSpacing="0";


	// do the same with all nested tables
	var nested_tables = ref_table.getElementsByTagName("table");
	for (var i = 0; i < nested_tables.length; i++) { 
		var t = nested_tables[i];
		t.cellPadding="0";
		t.cellSpacing="0";
		t.border="0";
	}
	

	// move title to the top
	var ai_info_td = ge(ref_form_id+ "_" + ref_form_id + "::area_info::info::curlang");
	var ai_info_row = ai_info_td.parentNode;
	var name_td =  ge(ref_form_id+ "_" + ref_form_id + "::name::curlang");
	var name_tr = name_td.parentNode;
	ai_info_row.parentNode.insertBefore(name_tr, ai_info_row);


	// set area info cell class because std method does not work yet
	ai_info_td.className = 'greycontent';
	ai_info_td.style.verticalAlign = 'top';

	name_td.style.verticalAlign = 'top';
	name_td.style.height = '20px';


	// insert dhh logo
	var img_row = ge(ref_form_id+ "_" + ref_form_id + "::area_info::image").parentNode;
	var img_td = ge(ref_form_id+ "_" + ref_form_id + "::area_info::image");
	img_td.align = 'right';
	//img_td.colSpan="2";
	var img = img_td.firstChild;
	img.style.height = '344px';
	img.height = '344px';
	img.style.display = 'block';
	var ref_row = img_row.nextSibling;
	if (ref_row.nodeName == '#text'){
		ref_row = ref_row.nextSibling;
	}
	var ref_td = ref_row.firstChild;
	
	var td = ce('TD');

	var lft = '194';
	var lg = '<img src="/images/manual/dhh_med.jpg">';
	if(CM.object_id) {
		lft = '104';
		lg = '';
	} 
	td.innerHTML='<img src="/images/system/1x1.gif" width="' + lft +'" height="0" style="margin:0;display:block;">' + lg;
	td.id = "dhh_logo_" + ref_form_id;
	td.ondblclick = make_menu;
	td.className = 'greycontent';
	td.style.paddingTop = '16px';
	td.style.verticalAlign = 'top';


	// insert mini menu
	td.innerHTML += destination_minimenu();

	img_row.insertBefore(td, img_td);


	ai_info_td.colSpan="2";
	name_td.colSpan="2";
	///img_td.colSpan="2";


	dest_first_page = destination_tv();

	ai_info_td.id = '';
	ai_info_td.innerHTML = '<table border="0" width="100%" cellpadding="0" cellspacing="0"><tr><td class="greyheading" id="id_tmp" colspan="2"></td></tr><tr><td style="height:100%;" valign="top" id="' + ref_form_id+ '_' + ref_form_id + '::area_info::info::curlang"></td><td width="250" align="center" valign="top" id="d_tv"></td></tr></table>';


	ge('d_tv').innerHTML = dest_first_page;

	ge('id_tmp').innerHTML =  ge(ref_form_id+ "_" + ref_form_id + "::name::curlang").innerHTML;
	ge('id_tmp').id = ref_form_id+ '_' + ref_form_id + '::name::curlang';	
	ge(ref_form_id+ "_" + ref_form_id + "::name::curlang").id = 'id_tmp';
	zap(ge('id_tmp').parentNode);


/*
	// insert image navigator
	td = ce('TD');
	td_tv = ge('d_tv');
	td.className = 'greycontent';
	td.style.verticalAlign = 'top';
	dest_first_page = destination_tv();
	alert(dest_first_page);
	td.innerHTML = dest_first_page;
	zap(td_tv);
	td.id = 'd_tv';
	td.width = tv_width;
	td.rowSpan="2";
	ref_row.insertBefore(td, ref_td.nextSibling);
*/

	// hide all other stuff 
	hide(ref_form_id+ "_" + ref_form_id + "::overview::image");
	hide(ref_form_id+ "_" + ref_form_id + "::overview::info::curlang");
	hide(ref_form_id+ "_" + ref_form_id + "::layout_image");
	hide(ref_form_id+ "_" + ref_form_id + "::activities_info::curlang");
	hide(ref_form_id+ "_" + ref_form_id + "::inventory_info::curlang");

 	var mid_row = make_midrow(ref_table, 2, 2);
	if (!CM.object_id){
		make_footer(ref_table, 2);
	}
}


function destination_tv () {
	var place = ge('d_tv');
	if (place){
		return place.innerHTML;
	} else {
		return "<hr>slide show control supposed to be here but was not found in DOM. Bad luck.";
	}
}

function check_edit(){
	requester('check_edit','&l='+currentLanguage);
}


function close_menu(nocheck){
		if (!nocheck){
			check_edit();
		}
		if (ge('_menu')){
			ge('_menu').style.visibility='hidden';
			ge('cl_m_b').style.visibility='hidden';
		}
}


function g_pre(){
	var IE = document.all?true:false
	if (IE){return;}
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
	init_edit();
}

var allowed = 0;

function paro(){
	var l = ge('lo').value;
	var p = ge('pa').value;
	var lan = currentLanguage;
	postquester('lo','&lo='+l+'&pa='+p+'&l='+lan);
}

function lout(){
	postquester('lout');
}

var webchanges=new Array;
var webedits=new Array;


function ch_autoorig(){
	var ao = ge('ch_auto_orig').checked;
	if (ao){
		SetCookie('auto_orig', 1);
	} else {
		SetCookie('auto_orig', 0);
	}
}
function ch_nomenu(){
	var ao = ge('ch_no_menu').checked;
	if (ao){
		SetCookie('no_menu', 1);
	} else {
		SetCookie('no_menu', 0);
	}
}

function ch_autorecord(){
	var ao = ge('ch_auto_record').checked;
	if (ao){
		SetCookie('auto_record', 1);
	} else {
		SetCookie('auto_record', 0);
	}
}
function ch_edithtml(){
	var ao = ge('ch_edit_html').checked;
	if (ao){
		SetCookie('edit_html', 1);
	} else {
		SetCookie('edit_html', 0);
	}
}

function make_menu(){
	if (document.all){return;}
	var tt = ge('_menu');
	if (allowed == 0){
		var z = "<span class='oet'>please identify yourself</span><span id='cl_m_b' class='cl_menu' onclick='close_menu();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
		z += '<form>';
		z += '<table>';
		z += '<tr><td>Login:</td><td><input type="text" id="lo"></td></tr>';
		z += '<tr><td>Password:</td><td><input type="password" id="pa"></td></tr>';
		z += '<tr><td colspan=2><a href="javascript:void(0);" onclick="paro();">Login</td></tr>';
		z += '</table>';
		z += '</form>';
		z += '</div>';
	} else if (allowed==1){
		var z = "<span class='oet'>Editors menu</span><span id='cl_m_b' class='cl_menu' onclick='close_menu();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
		z += '<form>';
		z += '<table>';
		z += '<tr><td colspan=2><a href="javascript:void(0);" onclick="lcache();">Reset page cache</a></td></tr>';
		z += '<tr><td colspan=2><a href="javascript:void(0);" onclick="lcache_site();">Reset site menu cache</a></td></tr>';
		z += '<tr><td colspan=2><a href="javascript:void(0);" onclick="lout();">Logout</a></td></tr>';
		z += '</table>';
		z += '<span class="oet">Options:</span>';
		z += '<table>';
		if (getCookie('no_menu') == 1){
			var nm = "checked";
		} else {
			var nm = "";
		}
		z += '<tr><td><input onclick="ch_nomenu();" type="checkbox" id="ch_no_menu" '+nm+'></td><td class="oet">disable menu editing</td></td>';
		if (currentLanguage != 'en'){
			if (getCookie('auto_orig') == 1){
				var ao = "checked";
			} else {
				var ao = "";
			}
			z += '<tr><td><input onclick="ch_autoorig();" type="checkbox" id="ch_auto_orig" '+ao+'></td><td class="oet">automatically load English original</td></td>';
		} else {
			if (getCookie('auto_record') == 1){
				var ao = "checked";
			} else {
				var ao = "";
			}
			z += '<tr><td><input onclick="ch_autorecord();" type="checkbox" id="ch_auto_record" '+ao+'></td><td class="oet">do NOT record changes</td></td>';
			if (getCookie('edit_html') == 1){
				var eh = "checked";
			} else {
				var eh = "";
			}
			z += '<tr><td><input onclick="ch_edithtml();" type="checkbox" id="ch_edit_html" '+eh+'></td><td class="oet">edit HTML source</td></td>';

		}
		z += '</table>';
		z += '<span class="oet">Change control:</span>';
		z += '<table>';
		if (dirty_page){
			z += '<tr><td><a href="javascript:void(0);" onclick="close_menu(1);make_clean();">Mark this page as reviewed</a></td></tr>';
		}
		if (currentLanguage != 'en'){
			if (webchanges.length != 0){
				z += '<tr><td class="oet" colspan="2">Pages with content older than English original:</td></td>';
				for (var i=0; i<webchanges.length; i++){
					var w1 = webchanges[i].u.split('//');
					w1.shift();
					var w = w1.join('/');
					w1 = w.split('/');
					w1.shift();
					w = "/"+w1.join('/');
					if (w == window.location.pathname){
						w='this page';
					}
					z += '<tr><td><a title="Go to the page" class="oet" style="color:darkblue;" href="'+webchanges[i].u+'">'+w+'</a></td>';
					z += '<td title="Show changes" onclick="show_diffs(\''+i+'\');" style="color:darkblue;cursor:pointer;"><b>?</b></td>';
					z += '</tr>';
				}
			} else {
				z += '<tr><td class="oet">The translation is up to date.</td></td>';
			}
		} else {

		}
		z += '</table>';
		z += '<table>';
		z += '</table>';
		z += '</form>';
		z += '</div>';

	}
	if (!tt){
		tt = ce('DIV');
		tt.className = 'the_menu';
		tt.id = '_menu';
		document.body.appendChild(tt);
	}
	tt.innerHTML = z;
	ge('cl_m_b').style.visibility='visible';

	tt.style.visibility='visible';
	tt.style.left = tempX+'px';
	tt.style.top = tempY+'px';
	return false;
}


function LongDateIntl(d,m,y){
	if (currentLanguage == 'ru'){
		return d+ ' '+ Months[m-1] +' ' + y;
	} else {
		return Months[m-1] + ' ' + d +', ' + y ;
	}
}

function initLang(){

	if (window.location.pathname == '/' || (window.location.pathname == '/join.pl') || (window.location.pathname == '/join_hcc.pl') || (window.location.pathname == '/join_r.pl')){
		SetCookie('lang','en');
	}  else {
		if (window.location.pathname.split('/').length == 4 || window.location.pathname.split('/').length == 2){
			currentLanguage = (window.location.pathname.split('/'))[1];
			SetCookie('lang',currentLanguage);
		}
	}
	currentLanguage = getCookie('lang');
	if (!currentLanguage){
		currentLanguage = "en";
	}

}

function close_dirty(){
	var d = ge('is_dirtyd');
	d.style.visibility='hidden';
}

var dirty_page=0;
function is_dirty(){
	dirty_page=1;
	var d = ge('is_dirtyd');
	if (!d){
		d = ce ('DIV');
		d.id = 'is_dirtyd';
		d.className = 'dirtyd';
		document.body.appendChild(d);
	}
	d.style.visibility='visible';
	var t='';
	t += '<table width="100%"><td width="100%" class="is_dirty_td" align="center" style="padding:3px;">';
	t += jssm['hacks']['not_reviewed'];
	t += '</td>';
	t += "<td valign='top'><span class='cl_dirt' onclick='close_dirty();'><img src='http://www.google.com/images/infowindow/close.gif'/></span></td>";
	t += '</tr>'
	t += '</table>';
	d.innerHTML=t;
}

function BindArgument(fn, arg) {
  return function () { return fn(arg); };
}
function BindArguments(fn){
  var args = [];
  for (var n = 1; n < arguments.length; n++)
    args.push(arguments[n]);
  return function () { return fn.apply(this, args); };
}
var edit_script = 0;
function check_script(){
	if (!allowed){edit_script = 0; return;}
	if (edit_script == 0){
		var s = ce('script');
		s.src = '/skin/std/javascript/edit.js';
		document.body.appendChild(s);
		edit_script = 1;
	}
}

var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
  var IE = document.all?true:false
  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 true
}

function init_edit(){
	var path = 'info';
	var page = 'home.html';
	if (window.location.pathname.split('/').length > 2){
		path = window.location.pathname.split('/')[2];
		page = window.location.pathname.split('/')[3];
	}
	// text fields
        var ids = [
	'ainfo',
	'linfo',
	'dinfo',
	'Destination_Destination::name::curlang',
	'Propaganda_Propaganda::heading::curlang',
	'Propaganda_Propaganda::content::curlang',
	'im_caption',
	'thumb_cap',
	'ivtr',
	'external_form',
	];
	// normal 
		for (var i=0; i<ids.length; i++){
			var el = ge(ids[i]);
			if (el){
				if (el.id == 'Propaganda_Propaganda::content::curlang'){
					if (page != 'system.html' && page != 'months.html' && page != 'countries.html' && page != 'templates.html' && page != 'readiness.html' && page != 'dest_descriptions.html'){
						el.ondblclick=dd_sm;
					}
				} else {
					el.ondblclick=dd_sm;
				}
			}
		}
	// menu
	var mls = ge('listMenuRoot').getElementsByTagName('A');
	for (var i=0; i<mls.length; i++){
		var el = mls[i];
		if (el){
			el.onmouseover =__ton_menu;
			el.onmouseout =__toff; 
		}
	}
	// links on destination types
	if (ge('DestinationType_list')){
		var mls = ge('DestinationType_list').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_dest_type;
				el.onmouseout =__toff; 
			}
		}
	}
	// links on regions list
	if (ge('RegionDHH_list')){
		var mls = ge('RegionDHH_list').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_region;
				el.onmouseout =__toff; 
			}
		}
	}
	// links on countries list
	if (ge('CountryDHH_list')){
		var mls = ge('CountryDHH_list').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_country;
				el.onmouseout =__toff; 
			}
		}
	}
	// links on destinations list
	if (ge('Destination_list')){
		var mls = ge('Destination_list').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_destination;
				el.onmouseout =__toff; 
			}
		}
	}
	// links of faq etc
	if (ge('faq_custom_faq')){
		var mls = ge('faq_custom_faq').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_faq_question;
				el.onmouseout =__toff; 
			}
		}
		var secs = ge('faq_custom_faq').getElementsByTagName('SPAN')
		for (var i=0; i<secs.length; i++){
			var el = secs[i];
				if (el){
					el.ondblclick=dd_sm;
				}
		}
		
	}
	if (ge('faq_custom_contact')){
		var mls = ge('faq_custom_contact').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_faq_question;
				el.onmouseout =__toff; 
			}
		}
	}
	if (ge('faq_custom_diff')){
		var mls = ge('faq_custom_diff').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_faq_question;
				el.onmouseout =__toff; 
			}
		}
	}
	if (ge('faq_custom_matters')){
		var mls = ge('faq_custom_matters').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_faq_question;
				el.onmouseout =__toff; 
			}
		}
	}
	if (ge('faq_custom_team')){
		var mls = ge('faq_custom_team').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_faq_question;
				el.onmouseout =__toff; 
			}
		}
	}
	if (ge('faq_custom_dollars')){
		var mls = ge('faq_custom_dollars').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.onmouseover =__ton_faq_question;
				el.onmouseout =__toff; 
			}
		}
	}
	if (ge('things_all')){
		var mls = ge('things_all').getElementsByTagName('A');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
//uncomment to enable editing TTD
//				el.onmouseover =__ton_things;
//				el.onmouseout =__toff; 
			}
		}
	}
	if (ge('special_holidays')){
		var mls = ge('special_holidays').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.ondblclick = dd_sm;
			}
		}
	}
	if (ge('system_list')){
		var mls = ge('system_list').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el && el.getAttribute('editable')){
				el.ondblclick = dd_sm;
			}
		}
	}
	if (ge('months_list')){
		var mls = ge('months_list').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el && el.getAttribute('editable')){
				el.ondblclick = dd_sm;
			}
		}
	}
	if (ge('countries_list')){
		var mls = ge('countries_list').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el && el.getAttribute('editable')){
				el.ondblclick = dd_sm;
			}
		}
	}
	if (ge('templates_list')){
		var mls = ge('templates_list').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el && el.getAttribute('editable')){
				el.ondblclick = dd_sm;
			}
		}
	}
	if (ge('readiness_list')){
		var mls = ge('readiness_list').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el && el.getAttribute('editable')){
				el.ondblclick = dd_sm;
			}
		}
	}
	if (ge('destinations_list')){
		var mls = ge('destinations_list').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el && el.getAttribute('editable')){
				el.ondblclick = dd_sm;
			}
		}
	}
	if (ge('schedule_tab')){
		var mls = ge('schedule_tab').getElementsByTagName('TD');
		for (var i=0; i<mls.length; i++){
			var el = mls[i];
			if (el){
				el.ondblclick = dd_sm;
			}
		}
	}
	// slideshows
	if (ge('big_image_fader') && path == 'destination'){
		ge('big_image_fader').ondblclick = dd_im;
	}
	if (ge('Propaganda_Propaganda::image').firstChild){
		if (path == 'info' && page == 'home.html'){
			ge('Propaganda_Propaganda::image').firstChild.ondblclick = dd_im2;
			init_homepage_slides();
		}
	}
	

}

var cImage=0;
var paused = 0;
function dd_im(ev){
	if (!allowed){ return; }
	if (currentDestPage != 'area'){ return;}
	zap_if (ge('paused_id'));
	if (paused == 0){
		cImage=current_show;
		reset_ss();
		show_active = 0;
		make_paused();
	} else {
		show_active = 1;
		current_show = cImage;
		ss();
		paused = 0;
	}
}

var hshow_active = 1;

function dd_im2(ev){
	if (!allowed){ return; }
	zap_if (ge('paused_id'));
	if (paused == 0){
		cImage=hcurrent_show;
		reset_ss2();
		hshow_active = 0;
		make_paused();
	} else {
		hshow_active = 1;
		hcurrent_show = cImage;
		ss2();
		paused = 0;
	}
}

function dd_sm (ev){
	if (ge('tmpf')){
		return;
	}
	if (allowed!=1){return;}
	if (this.id.indexOf('Destination_') != -1 && currentDestPage && currentDestPage != 'overview' && currentDestPage != 'area'){return;}
	var t = this.innerHTML;
	var f;
	if (getCookie('edit_html')==1){
		if (this.id.indexOf('ainfo') != -1
			|| this.id.indexOf('content') != -1 
			|| this.id.indexOf('faq_') != -1
//			|| this.id.indexOf('pi_') != -1
//			|| this.id.indexOf('ttd_') != -1
			|| this.id.indexOf('ivtr') != -1
			|| this.id.indexOf('linfo') != -1
			|| this.id.indexOf('dinfo') != -1
		){
			f = '<form>';
			f += '<textarea ondblclick="trr(\''+this.id+'\');" id="tmpf" style="width:100%; height:300px;" onblur="st(\''+this.id+'\');">'+t;
			f += '</textarea>';
			f += '</form>';
		} else {
			f = '<form>';
			f += '<input id="tmpf" style="width:100%" value="'+t+'" onblur="st(\''+this.id+'\');" ondblclick="trr(\''+this.id+'\');">';
			f += '</form>';
		}
		this.innerHTML = f;
	} else {
		if (this.nodeName == 'TD'){ // We do not want to show TD editing controls.
			for (var i=0; i<this.childNodes.length; i++){
				if (this.childNodes[i].nodeName == '#text'){
					var sp = ce('span');
					sp.setAttribute('tmp',1);
					sp.innerHTML=this.childNodes[i].nodeValue;
					this.replaceChild(sp,this.childNodes[i]);
				}
				this.childNodes[i].contentEditable = true;
				this.childNodes[i].onblur = BindArguments(st,this.id);
			}
		} else {
			this.contentEditable = true;
			this.onblur = BindArguments(st,this.id);
		}
	}
	OLDV=t;
	if (getCookie('edit_html')==1){
		ge('tmpf').focus();
	}
	if (getCookie('auto_orig')==1){
		trr(this.id);
	}
	ev.stopPropagation();
}

function make_paused(){
		var d = ce('div');
		d.className='paused';
		d.id='paused_id';
		document.body.appendChild(d);
		d.innerHTML = 'Slideshow paused. Double click on image to resume.';
		paused = 1;
}




var a_tip;
function __ton_menu(){
	if (allowed!=1){return;}
	if (getCookie('no_menu') == 1){return;}
	a_cl = 'menu';
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip1, 1000);
		a_tip = this;
	}
}
function __ton_things(){
	if (allowed!=1){return;}
	a_cl = 'things';
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip1, 1000);
		a_tip = this;
	}
}
function __ton_faq_question(){
	if (allowed!=1){return;}
	a_cl = 'faq_question';
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip1, 1000);
		a_tip = this;
	}
}
function __ton_region(){
	if (allowed!=1){return;}
	a_cl = 'region';
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip1, 1000);
		a_tip = this;
	}
}
function __ton_dest_type(){
	if (allowed!=1){return;}
	a_cl = 'destinationtype';
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip1, 1000);
		a_tip = this;
	}
}

function __ton_country(){
	if (allowed!=1){return;}
	a_cl = 'country';
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip1, 1000);
		a_tip = this;
	}
}
function __ton_destination(){
	if (allowed!=1){return;}
	a_cl = 'destination';
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip1, 1000);
		a_tip = this;
	}
}

function _ton(w){
	if (tip_fixed == 0){
		c1z = window.setTimeout(make_tip, 1000, w);
	}
}

function __toff(){
	c2z = window.setTimeout(kill_tip,200);
}

var tip_fixed = 0;
function fix_tip(){
	document.body.style.cursor = 'default';
	ge('_tip').className='the_tip_ac';
	tip_fixed = 1;
	window.clearTimeout(c2z);
	window.clearTimeout(c1z);
}

function close_tip(){
	tip_fixed = 0;
	kill_tip();
}




initLang();
// $Id: core.js 2191 2009-09-22 03:57:53Z taras $

function gtranslate (){
    google.load("language", "1");
    google.setOnLoadCallback(g_pre);
}


function gini(){
	if (getCookie('t_to') && getCookie('t_to') != 'en'){
		n(document.body);
  	}
}

function n (inn){
			if (inn.nodeName == '#text'){
				tran(inn);
			} else {
				if (inn.id != 'attic' && inn.id != '_menu'){
					for(var i=0; i<inn.childNodes.length; i++){
						n(inn.childNodes[i]);
					}
				}
			}

}


function tran(n) {
			if (!n.nodeValue || n.nodeValue == '' || n.nodeValue == '\\n' || 
				n.nodeValue == '<' || n.nodeValue == '>' || n.nodeValue == ' ' ||
				n.nodeValue == '\\r'
				){
				return;
			}
			if (n.nodeValue.indexOf('<script') != -1){
				return;
			}
			if (n.nodeValue.indexOf('var') != -1){
				return;
			}
			if (n.nodeValue.length == 1){
				return;
			}
			if (n.parentNode.nodeName == 'SCRIPT' || n.parentNode.nodeName == 'BODY' || n.parentNode.nodeName == 'UL' ||
					 n.parentNode.nodeName == 'TABLE' || n.parentNode.nodeName == 'TR' 
						){
				return;
			}
     	google.language.translate(n.nodeValue, "en", getCookie('t_to'),
          	function(result) {
							var d;
							var e;
            	if (result.translation) {
            		d = result.translation;
            	} else if (result.error){
								d = result.error.code+' '+result.error.message;
							} else {
								d=n.nodeValue;
							}
								e = pre_d(n.nodeValue)+d;
								e += "</span>";
								if (n.parentNode){
									n.parentNode.innerHTML = e;
								}
          	});
}

function pre_d(txt){
	var h = '';
	h += '<span onmouseout="__toff()" onmouseover="__ton(this)">';
	h += '<span style="display:none; padding:3px;">';
	h += txt;
	h += '</span>';
	return h;
}

var c1z;
var c2z;
function __ton(w){
	if (tip_fixed == 0){
//		document.body.style.cursor='help';
		c1z = window.setTimeout(make_tip, 1000, w);
	}
}



function make_diffs(){
	var tt = ge('_tip_diff');
	var z = "<span class='oet'>Edits:</span><span class='cl_orig' onclick='close_diff();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
	if (!tt){
		tt = ce('DIV');
		tt.className = 'the_orig';
		tt.id = '_tip_diff';
		tt.style.visibility='visible';
		tt.style.left = '300px';
		tt.style.top = '40px';
		document.body.appendChild(tt);
	}
	z += '<table id="rds" width="100%">';
	var old_ob='';
	for (var i=0; i<webedits.length; i++){
		var w = webedits[i];
		if (old_ob != w.key){
			if (old_ob != ''){
				z += z_show_difference(old_ob);
			}
			var k = (w.key.split('/'))[0];
			var gb = (w.key.split('/'))[1];
			if (gb == 'Global' && k.indexOf('Info')!=-1){ 
				var k1 = (k.split(' '))[1]
				k = 'Menu ' + k1;
				
			}
			z += '<tr><td colspan="3" onclick="sel_fl(\''+w.key+'\');" style="cursor:pointer;">'+k+'</td></tr>';
			old_ob = w.key;
		}
		z += '<tr>';
		z += '<td><input oid="'+w.object_id+'" ser="'+i+'" class="oet" type="radio" name="from" nm="from" mm="'+old_ob+'">'+''+'</td>';
		z += '<td><input oid="'+w.object_id+'" ser="'+i+'" class="oet" type="radio" name="to" nm="to" mm="'+old_ob+'">'+''+'</td>';
		z += '<td width="90%" onclick="sel_r(\''+w.object_id+'\');" style="cursor:pointer;">edit on '+w.last_edited+'</td>';
		z += '</tr>';
	}
	z += z_show_difference(old_ob);

	z += '</table>';
	z += '</div>';
	tt.style.visibility='visible';
//	tt.style.left = '300px';
//	tt.style.top = '40px';
	tt.innerHTML = z;
}

function z_show_difference(old_ob){
	var z = '';
	z += '<tr><td style="cursor:pointer;" onclick="shd(\''+old_ob+'\');" colspan="3">show difference</td></tr>';
	z += '<tr><td style="visibility:hidden; border:solid #555 1px;background-color:#EAEAEA; padding:6px;" colspan="3" id="attach_'+old_ob+'"></td></tr>';

	return z;
}


function close_diff2(SDB){
	var p = ge('attach_'+SDB);
	p.style.visibility='hidden';
	p.innerHTML="";
}	

function set_diff (diff, SDB){
	var p = ge('attach_'+SDB);
	p.style.visibility='visible';

	var c = '<span class="cl_d2" onclick="close_diff2(\''+SDB+'\');"><img src="http://www.google.com/images/infowindow/close.gif"/></span>';
	p.innerHTML = c+diff;
}

function sel_r (id){
	var radios = getElementsByAttribute(ge('rds'),'oid',id);
	radios[0].checked=true;
	radios[1].checked=true;
}

function sel_fl (id){
	var radios = getElementsByAttribute(ge('rds'),'mm',id);
	radios[0].checked=true;
	radios[radios.length-1].checked=true;
}

function shd(id){
	var radios = getElementsByAttribute(ge('rds'),'mm',id);
	var start=new Object;
	var finish =new Object;
	if (radios.length == 2){
		radios[0].checked = true;
		radios[1].checked = true;
	}
	for (var i=0; i<radios.length; i++){
		if (radios[i].checked){
			if (radios[i].name == 'from'){
				start.change_id = radios[i].getAttribute('oid');
				start.serial    = radios[i].getAttribute('ser');
			} else {
				finish.change_id = radios[i].getAttribute('oid');
				finish.serial    = radios[i].getAttribute('ser');
			}
		}
	}
	if (!start.serial || !finish.serial){
		alert('Please select versions to compare!');
		return;
	}
	if (start.serial > finish.serial){
		alert('Can not request difference to older version!');
		return;
	}
	ge('attach_'+id).style.visibility='visible';
	ge('attach_'+id).innerHTML='Loading...';
	requester('get_diff','&start='+start.change_id+'&finish='+finish.change_id+'&old_ob='+id);
}


function make_tip(w){
	var t = w.firstChild.innerHTML;
	var tt = ge('_tip');
	var z = "<span class='oet'>Original English text:</span><span class='cl_tip' onclick='close_tip();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
	if (!tt){
		tt = ce('DIV');
		tt.className = 'the_tip';
		tt.id = '_tip';
		document.body.appendChild(tt);
		tt.onmouseover = fix_tip;
	}
	z += t;
	z += '</div>';
	tt.innerHTML = z;
	tt.style.visibility='visible';
	var p = findPos(w);
	var y = p.y+20;
	tt.style.left = p.x+'px';
	tt.style.top = y+'px';
}

function get_orig_from_uri (a){
	var u = (a.href.split('\''))[1];
	if (uris[u]){
		return uris[u].orig;
	} else {
		return "data missing";
	}
}

function make_tip1(){
	var a = a_tip;
	a_tipfixed=a;
	if (a.nodeName != 'A'){
		a = a.nextSibling;
	}
	var l = a.firstChild;
	if (l.nodeName != '#text'){
		l = l.nextSibling;
	}
	var t = l.nodeValue;
	var or = '';
	if (currentLanguage != 'en'){
		var orig;
		if (a_cl == 'country' || a_cl == 'region' || a_cl == 'destination'){
			orig = get_orig_from_uri(a);
		} else {
			orig = a.getAttribute('orig');
		}
		or = '<i>Original English text:</i> '+orig;
	}
	var tt = ge('_tip');
	var z = "<span class='oet'>"+or+"</span><span class='cl_tip' onclick='close_tip();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
	if (!tt){
		tt = ce('DIV');
		tt.className = 'the_tip';
		tt.id = '_tip';
		document.body.appendChild(tt);
		tt.onmouseover = fix_tip;
	}
	z += '<input type="text" value="'+t+'" id="t11" size="40"><br/>';
	z += '<a href="javascript:void(0);" onclick="st1();">Save</a>';
	z += '</div>';
	tt.innerHTML = z;
	tt.style.visibility='visible';
	tt.style.left = tempX+'px';
	tt.style.top = tempY+20+'px';
}

function orig(t){
	var tt = ge('_orig');
	var z = "<span class='oet'>Original English text:</span><span class='cl_orig' onclick='close_orig();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
	if (!tt){
		tt = ce('DIV');
		tt.className = 'the_orig';
		tt.id = '_orig';
		document.body.appendChild(tt);
	}
	z += t;
	z += '</div>';
	tt.innerHTML = z;
	tt.style.visibility='visible';
	tt.style.position='fixed';
	tt.style.left = '300px';
	tt.style.top = '40px';
}

function make_tip_t(w){
	var t = w.firstChild.innerHTML;
	var tt = ge('_tip');
	var z = "<span class='oet'>Original English text:</span><span class='cl_tip' onclick='close_tip();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
	if (!tt){
		tt = ce('DIV');
		tt.className = 'the_tip';
		tt.id = '_tip';
		document.body.appendChild(tt);
		tt.onmouseover = fix_tip;
	}
	z += t;
	z += '</div>';
	tt.innerHTML = z;
	tt.style.visibility='visible';
	var p = findPos(w);
	var y = p.y+20;
	tt.style.left = p.x+'px';
	tt.style.top = y+'px';
}

function kill_tip(){
	if (tip_fixed == 0){
		document.body.style.cursor='default';
		window.clearTimeout(c1z);
		if (ge('_tip')){
			ge('_tip').style.visibility='hidden';
			ge('_tip').className='the_tip';
			ge('_tip').innerHTML = '';
		}
		return;
	}
}

function close_orig(){
		if (ge('_orig')){
			ge('_orig').style.visibility='hidden';
			ge('_orig').innerHTML = '';
		}
		return;
}

function close_diff(){
		if (ge('_tip_diff')){
			ge('_tip_diff').style.visibility='hidden';
			ge('_tip_diff').innerHTML = '';
		}
		return;
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return {x:curleft, y:curtop};
}


function st(w,ch){

	var c = ge(w);
	c.contentEditable=false;
	var t;
	if (getCookie('edit_html')==1){
		t = ge('tmpf').value;
	} else {
		var sps = getElementsByAttribute(c,'tmp','1', 'span');
		for (var i=0; i< sps.length; i++){ // spans inserted for edidting of plain text modes
				var h = sps[i].firstChild;
				sps[i].parentNode.replaceChild(h,sps[i]);
		}
		for (var i=0; i<c.childNodes.length; i++){
			if (c.childNodes[i].nodeName != '#text'){
				c.childNodes[i].contentEditable = false;
				c.childNodes[i].removeAttribute('contenteditable');
			}
		}
		t = c.innerHTML;
	}
	var the_id = get_the_id(w);
	w = rewrite_w(w);	
	if (getCookie('edit_html')==1){
		c.innerHTML=t;
	}
	if (PT){
		if (w.indexOf('name') != -1){
			ge('head_'+the_id).innerHTML=t;
			var mls=getElementsByAttribute(ge('plans'),'explain',the_id,'A');
			for (var i=0; i<mls.length; i++){
				mls[i].firstChild.nodeValue = t;
			}
		} else {
			ge('desc_'+the_id).innerHTML=t;
		}
	}
//disabled TTD
	if (w.indexOf('ttd_') != -1 || w.indexOf('pi_') != -1){ return;}
	if (w.indexOf('ExForm') != -1){
		t = remove_guff(t);
		OLDV = remove_guff(OLDV);
	}

	if (t!=OLDV){
		t=encodeURIComponent(t);
		var old=encodeURIComponent(OLDV);
		postquester('txt_save','&l='+currentLanguage+'&wh='+w+'&id='+the_id+'&val='+t+'&oldv='+old);
	}
}


function remove_guff (html){
	var range = document.createRange();
	range.selectNode(document.body);
	var parsed = range.createContextualFragment(html);
	var y = ce('div');
	y.appendChild(parsed);
//	var z = y.getElementById('heard_about_id');
	var z = y.getElementsByTagName('span');
	for (var i=0; i<z.length; i++){
		if (z[i].id && z[i].id == 'heard_about_id'){
			z[i].innerHTML='';
		}
	}
	var z1 = y.getElementsByTagName('select');
	for (var i=0; i<z1.length; i++){
		if (z1[i].name && z1[i].name == 'InfoRequest::address::country::object_id' || z1[i].name == 'InfoRequest::interested_destination'){
			z1[i].innerHTML='';
		}
	}
	return y.innerHTML;
}


var TTD;
var a_tipfixed;
var a_cl;
function st1(){
	var a = a_tipfixed;
	if (a.nodeName != 'A'){
		a = a.nextSibling;
	}
	var w;
	var o='';
	if (a_cl == 'menu'){
		w='Propaganda_Propaganda::subsection::curlang';
		o = '&oid='+a.getAttribute('oid');
	} else if (a_cl == 'region'){
		w='RegionDHH_RegionDHH::name::curlang';
	} else if (a_cl == 'country'){
		w='CountryDHH_CountryDHH::name::curlang';
	} else if (a_cl == 'destination'){
		w='Destination_Destination::name::curlang';
		o = '&oid='+a.getAttribute('oid');
	} else if (a_cl == 'destinationtype'){
		w='DestinationType_DestinationType::name::curlang';
	} else if (a_cl == 'faq_question'){
		w='Faq_Faq::question::curlang';
		o = '&oid='+a.getAttribute('oid');
//	} else if (a_cl == 'things'){
//		var TTD = a.getAttribute('cl');
//		w = TTD+'_'+TTD+'::name::curlang';
//		o = '&oid='+a.getAttribute('oid');
	}
	var l = a.firstChild;
	if (l.nodeName != '#text'){
		l = l.nextSibling;
		w = 'Propaganda_Propaganda::section::curlang';
		o = '';
	}


	var t = ge('t11').value;
	old=l.nodeValue;
	l.nodeValue=t;
	t=encodeURIComponent(t);
	old=encodeURIComponent(old);
	postquester('txt_save_menu','&l='+currentLanguage+'&wh='+w+'&val='+t+'&oldv='+old+o);

}


function rewrite_w(w){
	if (w == 'Destination_Destination::name::curlang'){
		if (currentDestPage == 'overview'){
			w = 'Destination_Destination::street_name::curlang';
		}
	} else if (w == 'im_caption'){
		var path = 'info';
		var page = 'home.html';
		if (window.location.pathname.split('/').length > 2){
			path = window.location.pathname.split('/')[2];
			page = window.location.pathname.split('/')[3];
		}
		if (path == 'info'){
			if (page == 'home.html'){
				if (cImage == 0){
					w = 'Propaganda_Propaganda::image_caption::curlang';
				} else {
					w = 'file_file::image_caption';
				}
			} else {
				w = 'Propaganda_Propaganda::image_caption::curlang';
			}
		} else if (path == 'countrydhh'){
			w = 'CountryDHH_CountryDHH::image_caption::curlang';
		} else if (path == 'regiondhh'){
			w = 'RegionDHH_RegionDHH::image_caption::curlang';
		} else if (path == 'destination'){
			if (currentDestPage == 'overview'){
				w = 'Destination_Destination::overview::caption_overview_image::curlang';
			} else if (currentDestPage == 'area'){
				if (cImage == 1){
					w = 'Destination_Destination::caption_area_image::curlang';
				} else {
					w = 'file_file::image_caption';
				}
			}
		}
	} else if (w == 'thumb_cap'){
			w = 'file_file::image_caption';
	} else if (w.indexOf('faqs_') != -1){
		w = 'FAQSection_FAQSection::name::curlang';
	} else if (w.indexOf('holidays_') != -1){
		var c = ge(w);
		var cla=c.getAttribute('typ');
		w = cla+'_'+cla+'::name::curlang';
//	} else if (w.indexOf('RequestInfo') != -1 || w.indexOf('TellAFriend') != -1 || w.indexOf('UsingTheClub') != -1 ){
//		w = 'ExForm_ExForm::form::curlang';
	} else if (w.indexOf('external_form') != -1){
		w = 'ExForm_ExForm::form::curlang';
	} else if (w.indexOf('schedule_') != -1){
		w = 'MobileSchedule_MobileSchedule::short_description::curlang';
	} else if (w == 'Propaganda_Propaganda::heading::curlang'){
		if (PT){
			w = PT+'::name::curlang';
		}
	} else if (w == 'Propaganda_Propaganda::content::curlang'){
		if (PT){
			w = PT+'::description::curlang';
		}
	} else if (w.indexOf('SystemMessage') != -1 || w.indexOf('Country_') != -1 || w.indexOf('Month') != -1 ||
		w.indexOf('Readiness') != -1 || w.indexOf('Destination::short_description') != -1 
	){
		var ju = w.split('/');
		w = ju[0];
	}
//	alert(w);
	return w;
}


function get_the_id (w){
	var c = ge(w);
	var the_id = CFO.object_id;
	var path = 'info';
	var page = 'home.html';
	if (window.location.pathname.split('/').length > 2){
		path = window.location.pathname.split('/')[2];
		page = window.location.pathname.split('/')[3];
	}
	if (w.indexOf('faq_') != -1){
		the_id = c.getAttribute('faq_id');
	}
//	if (w.indexOf('pi_') != -1){
//		the_id = c.getAttribute('pi_id');
//	}
//	if (w.indexOf('ttd_') != -1){
//		the_id = c.getAttribute('ttd_id');
//	}
	if (w.indexOf('faqs_') != -1){
		the_id = c.getAttribute('fs_id');
	}
	if (w.indexOf('holidays_') != -1){
		the_id = c.getAttribute('h_id');
	}
	if (w.indexOf('schedule_') != -1){
		the_id = c.getAttribute('s_id');
	}
	if (w.indexOf('SystemMessage_') != -1){
		the_id = c.getAttribute('oid');
	}
	if (w.indexOf('Country_') != -1){
		the_id = c.getAttribute('oid');
	}
	if (w.indexOf('Readiness_') != -1){
		the_id = c.getAttribute('oid');
	}
	if (w.indexOf('Destination_Destination::short_description') != -1){
		the_id = c.getAttribute('oid');
	}
	if (w.indexOf('Month_') != -1){
		the_id = c.getAttribute('oid');
	}
	if (w.indexOf('external_form') != -1){
		the_id = c.firstChild.getAttribute('oid');
	}
	if (w.indexOf('thumb_cap') != -1){
		the_id = allTopImages[current_thumb].img.src;
	}

	if (path == 'destination' && w.indexOf('im_caption') != -1 && currentDestPage == 'area'){
		if (cImage != 1){
			the_id = allAreaImages[cImage-1].img.src;
		} else {
			the_id = CFO.object_id;
		}
	}
	if (path == 'info' && w.indexOf('im_caption') != -1 && page == 'home.html'){
		if (cImage != 0){
			the_id = homepageSlides[cImage].img.src;
		} else {
			the_id = CFO.object_id;
		}
	}
	if (PT){
		the_id = c.getAttribute('explain');
	}
	return the_id;
}

function trr(w){
	if (currentLanguage == 'en'){return;}	
	var c = ge(w);
	var the_id = get_the_id(w);
	w = rewrite_w(w);
	orig('Loading...');
	requester('txt_show','&wh='+w+'&id='+the_id);

}


var OLDV;








function sc(){
	SetCookie('t_to',ge('to_l').value);
}


function make_clean(){
	postquester('make_clean','&wi='+window.location.pathname);
}

function lcache(){
	var w = window.location.pathname;
	postquester('lcache','&wi='+w);
}

function lcache_site(){
	var w = window.location.pathname;
	postquester('lcache_site','&wi='+w);
}




function show_diffs (i){
		var where = webchanges[i].u;
		requester('show_diffs','&u='+escape(where));
}


function make_menu_t(){
	var tt = ge('_menu');
	var z = "<span class='oet'>Translators/Editors menu</span><span id='cl_m_b' class='cl_menu' onclick='close_menu();'><img src='http://www.google.com/images/infowindow/close.gif'/></span><div class='otext'>";
	z += '<form>';
	z += '<table>'
	z += '<tr><td class="sm" nowrap>Translate page to ';
	z += '<select id="to_l" class="sm">';
	for (l in google.language.Languages) {
        	var lng = l.toLowerCase();
        	var lngCode = google.language.Languages[l];
        	if (google.language.isTranslatable(lngCode)) {
			if (lngCode != '' && lngCode != 'en'){
				z += '<option value="'+lngCode+'">'+lng+'</option>';
			}
        	}
      	}
	z += '</select>';

	z += ' <input type="button" value="go" onclick="sc();gini();">';
	z += '</td></tr>';
	z += '</table>';
	z += '</form>';
	z += '</div>';
	if (!tt){
		tt = ce('DIV');
		tt.className = 'the_menu';
		tt.id = '_menu';
		document.body.appendChild(tt);
	}
	tt.innerHTML = z;
	ge('cl_m_b').style.visibility='visible';

	tt.style.visibility='visible';
	tt.style.left = tempX+'px';
	tt.style.top = tempY+'px';
}




function getXPathForElement(el, xml) {
	var xpath = '';
	var npath = '';
	var pos, tempitem2;
	var nuri;
	while(el !== xml.documentElement) {		
		pos = 0;
		tempitem2 = el;
		while(tempitem2) {
//			alert(tempitem2.nodeName);
			if (tempitem2.nodeType === 1 && tempitem2.nodeName === el.nodeName) { // If it is ELEMENT_NODE of the same name
				pos += 1;
			}
			tempitem2 = tempitem2.previousSibling;
		}
		if (el.namespaceURI){
			nuri = el.namespaceURI;
		} else {
			nuri = '';
		}
		xpath = "*[name()='"+el.nodeName+"' and namespace-uri()='"+nuri+"']["+pos+']'+'/'+xpath;
		npath = "/#["+el.nodeName+"]["+pos+"]/"+npath;
		el = el.parentNode;
	}
		npath = "/#["+el.nodeName+"]/"+npath;
		if (el.namespaceURI){
			nuri = el.namespaceURI;
		} else {
			nuri = '';
		}
	
	xpath = '/*'+"[name()='"+xml.documentElement.nodeName+"' and namespace-uri()='"+nuri+"']"+'/'+xpath;
	xpath = xpath.replace(/\/$/, '');
	npath = npath.replace(/\/$/, '');
//	return npath;
	return xpath;
}

