window.onload = init;

function init(){
	var email = document.getElementById('maudax');
	if(email){	
		email.href = 'mailto:audax@rtmhotels.com';
		email.innerHTML = 'audax@rtmhotels.com';
	}
	var email = document.getElementById('mcapri');
	if(email){	
		email.href = 'mailto:capri@rtmhotels.com';
		email.innerHTML = 'capri@rtmhotels.com';
	}
	var email = document.getElementById('moffice');
	if(email){
		email.href = 'mailto:artiem@rtmhotels.com';
		email.innerHTML = 'artiem@rtmhotels.com';
	}
	var email = document.getElementById('minfo_audax');
	if(email){
		email.href = 'mailto:audax@rtmhotels.com';
	}else{
		var email = document.getElementById('minfo_capri');
		if(email){
			email.href = 'mailto:capri@rtmhotels.com';
		}else{
			var email = document.getElementById('minfo_office');
			if(email){
				email.href = 'mailto:artiem@rtmhotels.com';
			}
		}	
	}				
}

function sendComment(form){
	if(form.sign.value.length <= 0){
		form.sign.focus();	
		return;		
	}else{
		if(form.text.value.length <= 0){
			form.text.focus();
			return;
		}
	}
	form.submit();
}

function sendContact(form){
	if(form.target.value == ''){
		form.target.focus();	
		return;		
	}
	
	if(form.name.value.length <= 0){
		form.name.focus();
		return;
	}

	if(form.email.value.length <= 0){
		form.email.focus();
		return;
	}

	if(form.query.value.length <= 0){
		form.query.focus();
		return;
	}
		
	form.submit();
}

function swapimage(current, tochange){
	imgc = document.getElementById(current);
	if(current){
		imgt = document.getElementById(tochange);
		if(imgt){
			imgc.src = imgt.src;
		}
	}
}

function popup(atag, width, height){
	width = width ? width : 'auto'; 
	height = height ? height : 'auto';
	var w = window.open('', 'photo', 'toolbar=no, resizable=no, copyhistory=no, status=no, width=' + width + ', height=' + height);
	w.document.open();  
	w.document.write("<html><title>RTM Hotels</title>");  
	w.document.write("<body style=\"backround-color:#ffffff; margin:0; padding:0; width:" + width + "px; height:" + height + "\">");  
	w.document.write("<img src=\"" + atag.href + "\" width=\""+ width +"\" height=\""+ height +"\" alt=\"" + atag.alt + "\">");  
	w.document.write("</body></html>");  	
	w.document.close();
	w.resizeTo(width, height)	
	w.focus();
}

function isInteger(s)
{
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	return true;
}

function trim(str){
	for(i=0; i<str.length; ){
		if(str.charAt(i)==" ")
			str=str.substring(i+1, str.length);
		else
			break;
	}

	for(i=str.length-1; i>=0; i=str.length-1){
		if(str.charAt(i)==" ")
			str=str.substring(0,i);
		else
			break;
	}
	return str;
}


function checkEmail(strng){
    var emailFilter=/^.+@.+\..{2,4}$/;
    if (!(emailFilter.test(strng))){ 
       return false;
    }else{
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
		if (strng.match(illegalChars))
			return false;
    }
	return true;
}

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

if(isExplorer6())
	addEvent(window, 'load', fixIt);

function fixIt(){ 
	if(document.getElementById){ 
		navRoot1 = document.getElementById('resdown');
		if(navRoot1){		
			navRoot1.onmouseover = function(){ document.getElementById('resmenu').style.display = 'block'; }
			navRoot1.onmouseout = function(){ document.getElementById('resmenu').style.display = 'none';  }		
		}
		navRoot2 = document.getElementById('welldown');		
		if(navRoot2){		
			navRoot2.onmouseover = function(){ document.getElementById('wellmenu').style.display = 'block'; }
			navRoot2.onmouseout = function(){ document.getElementById('wellmenu').style.display = 'none'; }		
		}
	}
}

function isExplorer6(){
	var ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	return ie6;
}

function showMoreInfo(id, show){
	var elements = $('shr_' + id, 'full_' + id);
	if(elements[0] && elements[1]){
		if(show){
			new Effect.SlideUp(elements[0]);		
			new Effect.SlideDown(elements[1]);
		}else{
			new Effect.SlideDown(elements[0]);
			new Effect.SlideUp(elements[1]);
		}
	}
}

function bback(step){
	var fm = document.forms[step];
	if(fm.step){
		var cstep = parseInt(fm.step.value);
		if(cstep > 1){
			 fm.step.value = (cstep - 2);
			 fm.submit();
		}
	}
}

function bcancel(strmsg, step){
	var fm = document.forms[step];
	if(confirm(strmsg))
		fm.submit();
}

function gotoMonth(strdate, lang){
	var params = '&lang=' + lang  + '&date=' + strdate;
	new Ajax.Request('/calendar_events.php', { 
			method: 'get',
			parameters: params,			
			onSuccess: function(transport){
				var cal = document.getElementById('calendar'); 
				cal.innerHTML = transport.responseText;
			} 
	});	
}