// Show secures emails
function showSecured(name,site,doimain) {
	var vor = name;
	var nach = site;
	var ende = doimain;
	var contact = vor + "@" + nach + "." + ende;
	document.write("<a href=" + "mail" + "to:" + vor + "@" + nach + "." + ende + ">" + contact + "</a>")
}
	
// Rating
function hoverRate(id) {
	for(var x=1; x<=5; x++) {
		document.getElementById('rate_'+x).src = "/img/icon_rating_ia.gif";
	}
	for(var y=1; y<=id; y++) {
		document.getElementById('rate_'+y).src ="/img/icon_rating_a.gif";
	}
}
function resetRate() {
	if(document.getElementById('comment_rating').value != "") {
		currentRate = document.getElementById('comment_rating').value;
		for(var x=1; x<=5; x++) {
			document.getElementById('rate_'+x).src = "/img/icon_rating_ia.gif";
		}
		for(var y=1; y<=currentRate; y++) {
			document.getElementById('rate_'+y).src ="/img/icon_rating_a.gif";
		}
	}
}
function doRate(id) {
	for(var x=1; x<=5; x++) {
		document.getElementById('rate_'+x).src = "/img/icon_rating_ia.gif";
	}
	for(var y=1; y<=id; y++) {
		document.getElementById('rate_'+y).src ="/img/icon_rating_a.gif";
	}
	document.getElementById('comment_rating').value = id;
}

// Love place
function dolove(src) {
	if(document.getElementById('love').src.search(/icon_love_ia/) != -1) {
		document.getElementById('love').src = src + "/img/icon_love_a.gif";
		document.getElementById('comment_love').value = "1";
	} else {
		document.getElementById('love').src = src + "/img/icon_love_ia.gif";
		document.getElementById('comment_love').value = "0";
	}
}

// Use Street for new Location
function useStreet() {
	if(document.getElementById('location_mapstreet').value != "") {
		document.getElementById('location_usrstreet').value = document.getElementById('location_mapstreet').value;
		document.getElementById('map_suggest').style.display = "none";
	}
}

// Load URL
function loadUrl(url) {
	window.location.href = url;
}

// Confirmation Box
function confirmAction(option, url, id, message) {
	confirmed = window.confirm(message);
	if (confirmed) {
		window.location.href = url + '&option=' + option + '&id=' + id;
	}
}

// Effect for comment rating
function commentRating(commentrating,comment_id,src) {
	if(commentrating == 0) {
		for (var i = 1; i <= 5; ++i) {
			document.getElementById('commentrating_'+comment_id+'_'+i).src = src + '/img/icon_comment_rating_ia.gif';
			document.getElementById('commentrating_text_'+comment_id).innerHTML = commentrating_0;
			document.getElementById('rating_count').value = "";
			document.getElementById('comment_id').value = "";
		}
	} else {
		for (var i = 1; i <= commentrating; ++i) {
			document.getElementById('commentrating_'+comment_id+'_'+i).src = src + '/img/icon_comment_rating_a.gif';
			var obj = eval("commentrating_"+i);
			document.getElementById('commentrating_text_'+comment_id).innerHTML = obj;
			document.getElementById('rating_count').value = i;
			document.getElementById('comment_id').value = comment_id;
		}
	}
}

// Closing DIV-Windows e.g. location check
function close_window(id) {
	document.getElementById(id).style.display = "none";	
}

// Check length of textarea
function checkTextLength(id,maxlength,onlyid) {
	var txtmax=maxlength;
	if(onlyid == 1) {
		fieldtocheck = document.getElementById(id);
	} else {
		fieldtocheck = document.getElementById('textarea_gallery_'+id);
	}
	if (fieldtocheck.value.length >= txtmax) {
		fieldtocheck.value = fieldtocheck.value.substring(0,txtmax);
		fieldtocheck.blur();
	}
}

// Add more inputfields for time-entry
function addTime() {
	count_schedule_hours = parseInt(document.getElementById('count_schedule_hours').value);
	//alert(count_schedule_hours);
	if(count_schedule_hours < 6) {
		var alldays = document.getElementById('alldays').value.split(";");
		var counter = document.getElementById('count_schedule_hours').value;
		var next_counter = count_schedule_hours+1;
		for(var a=0; a<alldays.length; a++) {
			var row = a;
			var output = '<span style=\"float: left;\"><input type="text" class="input_2digits" maxlength="2" name="hour_'+alldays[a]+'_'+counter+'" />:<input type="text" class="input_2digits" maxlength="2" name="minute_'+alldays[a]+'_'+counter+'" style=\"margin-right: 15px;\" /></span><span id="next_hour_'+row+'_'+next_counter+'" style="float: left; position: relative;"></span>';
			document.getElementById('next_hour_'+row+'_'+counter).innerHTML = output;	
		}
		document.getElementById('count_schedule_hours').value = count_schedule_hours+1;
	}
}

function addEmails() {
	var count_obj = document.getElementById('schedule_email_count');
	var obj = document.getElementById('schedule_emails_more');
	
	if(count_obj.value < 8) {
		count_obj.value = parseInt(count_obj.value)+1;
		var next_value =  parseInt(count_obj.value)+1;
		document.getElementById('new_inputmail_'+count_obj.value).innerHTML = '<input type="text" name="schedule_email_name[]" maxlength="20" value="" class="input_sendfriends_small" />&nbsp;<input type="text" name="schedule_email[]" maxlength="150" value="" class="input_sendfriends" /><br /><div id="new_inputmail_'+ next_value +'"></div>'
	}
}

function addFriendsEmails() {
	var count_obj = document.getElementById('friends_email_count');
	var obj = document.getElementById('friends_emails_more');
	
	if(count_obj.value < 8) {
		count_obj.value = parseInt(count_obj.value)+1;
		var next_value =  parseInt(count_obj.value)+1;
		document.getElementById('new_inputmail_'+count_obj.value).innerHTML = '<input type="text" name="friends_email[]" maxlength="50" value="" class="input_sendfriends" /><br /><div id="new_inputmail_'+ next_value +'"></div>'
	}
}

// Enable / disable Button based on input
function enableDisableSmartButton(obj,id) {	
	if (obj == 'dohighlight') {
		document.getElementById(id).className = "button_smart";	
	} else if (obj == 'dounhighlight') {
		if(document.getElementById('schedule_typeahead_'+selectedScheduleLocation[0])) {
			document.getElementById('schedule_typeahead_'+selectedScheduleLocation[0]).className = "item";
			selectedScheduleLocation = new Array();
			document.getElementById(id).className = "button_smart_disabled";
		}
	} else {
		if(obj.value.length > 2) {
			document.getElementById(id).className = "button_smart";
		} else {
			document.getElementById(id).className = "button_smart_disabled";
		}	
	}
}

// for hightlighting / selection scheduled location in typeahead
function selectScheduleLocation(id) {
	var obj = document.getElementById('schedule_typeahead_'+id);
	obj.className = "item listselected";
	if(selectedScheduleLocation.length > 0) {
		if(selectedScheduleLocation[0] != id) {
			enableDisableSmartButton('dounhighlight','send_schedule_location');
		}
	}
	selectedScheduleLocation.push(id);
	enableDisableSmartButton('dohighlight','send_schedule_location');
	
	// Load location information into hidden inputfields
	var tmpinput = document.getElementById('schedule_typeahead_input_'+id);
	var arr_tmpinput = tmpinput.value.split(";");

	document.getElementById('db_location_id').value = arr_tmpinput[0];
	document.getElementById('db_location_name').value = arr_tmpinput[1];
	document.getElementById('db_location_street').value = arr_tmpinput[2];
	document.getElementById('db_location_zip').value = arr_tmpinput[3];
	document.getElementById('db_location_city').value = arr_tmpinput[4];
}

function windowWidth () {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.body && document.body.offsetWidth) {
		return document.body.offsetWidth;
	} else {
		return 0;
	}
}

function windowHeight () {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (document.body && document.body.offsetHeight) {
		return document.body.offsetHeight;
	} else {
		return 0;
	}
}

function getScrollX() {
	var scrOfX = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfX = document.documentElement.scrollLeft;
	} else {
		scrOfX = 0;
	}
	return scrOfX;
}

function getScrollY() {
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	} else {
		scrOfY = 0;
	}
	return scrOfY;
}

// Re-position chat window
function positionChatNotify() {
	var chatwindow = document.getElementById('chat_notification');
	if (window.clientHeight < window.scrollHeight) {
		//alert("The element has a vertical scrollbar!"); 
	}
	if(chatwindow) {
		chatwindow.style.bottom = "-"+getScrollY()+"px";
		chatwindow.style.right = "-"+getScrollX()+"px";
	}
}

// Disable button after clicked first time
function deactivateButton(id) {
	parentobject = document.getElementById(id).parentNode;
	object = document.getElementById(id);
	deactivate = window.setTimeout("object.disabled=true; object.className='clearinput button_input disabled'; parentobject.className='button_input disabled';", 100);	
}
function activateButton(id) { // Necessary?
	parentobject = document.getElementById(id).parentNode;
	object = document.getElementById(id);
	deactivate = window.setTimeout("object.disabled=false; object.className='clearinput button_input'; parentobject.className='button_input';", 100);	
}

// Add / Remove element id with checkbox
function selectElementId(id, type) {
	if(id == 'all') {
		ids = new Array();
		var allids = document.getElementById('allids').value;
		arr_allids = allids.split(";");
		
		if(document.getElementById('checkbox_all').className == "designcheckbox selected") {
			document.getElementById('checkbox_all').className = "designcheckbox";
			
			// Uncheck all
			for(i=0;i<arr_allids.length;i++) {
				if(arr_allids[i] != "") {
					document.getElementById('checkbox_'+arr_allids[i]).className = "designcheckbox";
				}
			}
			
		} else {
			document.getElementById('checkbox_all').className = "designcheckbox selected";
			
			// Check all
			for(i=0;i<arr_allids.length;i++) {
				if(arr_allids[i] != "") {
					document.getElementById('checkbox_'+arr_allids[i]).className = "designcheckbox selected";
					ids.push(arr_allids[i]);
				}
			}
		}
	} else if(id == 'reload') {
		var selectedids = document.getElementById('allselectedids').value;
		arr_selectedids = selectedids.split(";");
		// Check selected
		for(i=0;i<arr_selectedids.length;i++) {
			if(arr_selectedids[i] != "") {
				document.getElementById('checkbox_'+arr_selectedids[i]).className = "designcheckbox selected";
				ids.push(arr_selectedids[i]);
			}
		}
	} else {
		var idstmp = new Array();
		var add = "";
		var additem = "yes";
		
		// Search array
		for (var i = 0; i < ids.length; ++i) {
			//something found --> do not add to tmp array
			if(ids[i] == id) {
				document.getElementById('checkbox_'+id).className = "designcheckbox";
				document.getElementById('checkbox_all').className = "designcheckbox";
				additem = "no";
				continue;
			}
			idstmp.push(ids[i]);
		}
		
		if(additem == "yes" || ids.length == 0) { // for adding (first) element
			add = id;
			idstmp.push(add);
			document.getElementById('checkbox_'+id).className = "designcheckbox selected";
		}
		
		ids = idstmp;
	}
	
	document.getElementById('allselectedids').value = ids.join(";");
	
	if(type == 'messages') {
		if(document.getElementById('allselectedids').value != "") {
			// Enable button	
			activateButton('delete_selected_messages');
		} else if(document.getElementById('allselectedids').value == "") {
			// Disable button	
			deactivateButton('delete_selected_messages');
		}
	}
}

// Add / Remove calendar items
function selectDay(id) {
	if(id == 'paging') {
		var selecteddates = top.document.getElementById('allselecteddates').value;
		arr_selecteddates = selecteddates.split(";");
		// Check selected
		for(i=0;i<arr_selecteddates.length;i++) {
			if(arr_selecteddates[i] != "") {
				if(document.getElementById(arr_selecteddates[i])) {
					var obj = document.getElementById(arr_selecteddates[i]);
					if(obj.className.search(/dayweekend/) != -1) {
						obj.className = "dayweekend dayweekend_over";
					} else {
						obj.className = "day day_over";
					}
					if(id == 'reload') {
						//dates.push(arr_selecteddates[i]);
					}
				}
			}
		}
	} else {
		var datestmp = new Array();
		var add = "";
		var additem = "yes";
		
		var obj = document.getElementById(id);
		
		// Search array
		for (var i = 0; i < dates.length; ++i) {
			//something found --> do not add to tmp array
			if(dates[i] == id) {
				if(obj.className.search(/dayweekend/) != -1) {
					obj.className = "dayweekend";
				} else {
					obj.className = "day";
				}
				additem = "no";
				continue;	
			}
			datestmp.push(dates[i]);
		}
		
		if(additem == "yes" || dates.length == 0) { // for adding (first) element
			add = id;
			datestmp.push(add);
			if(obj.className.search(/dayweekend/) != -1) {
				obj.className = "dayweekend dayweekend_over";
			} else {
				obj.className = "day day_over";
			}
		}
		
		dates = datestmp;
	}
	
	document.getElementById('allselecteddates').value = dates.join(";");
}

// Loading sequence when opening new window
function showLoading() {
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
			//$("#TB_overlay").click(tb_remove);
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
			//$("#TB_overlay").click(tb_remove);
		}
	}
	
	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}
	
	$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
	$('#TB_load').show();//show loader
}

// Resizing popup
/*
function resizePopup(width,height) {
	
	top.document.getElementById('TB_window').style.height = height+'px';
	top.document.getElementById('TB_iframeContent').style.height = height+'px';
	
	top.document.getElementById('TB_window').style.width = width+'px';
	top.document.getElementById('TB_iframeContent').style.width = width+'px';

	TB_WIDTH = width;
	TB_HEIGHT = height;
	
	var tbwindow = top.document.getElementById('TB_window');
	$(tbwindow).css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$(tbwindow).css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
	
}
*/

// Enable button if user checked checkbox
function uploadRights(obj) {
	childobject = document.getElementById('upload_image_button').childNodes[0];
	if(obj.checked == true) {
		document.getElementById('upload_image').type = 'file';
		document.getElementById('upload_image_button').className = "button_smart";
		childobject.className = "button_smart";
	} else {
		document.getElementById('upload_image').type = '';
		document.getElementById('upload_image_button').className = "button_smart_disabled";
		childobject.className = "button_smart_disabled";	
	}
}



// show smilies
function showSmiley(string) {
	var smileys = new Object();
		
	smileys[':arrow:'] = 'icon_arrow.gif';
	
	smileys[':\\?'] = 'icon_confused.gif';
	smileys[':-\\? '] = 'icon_confused.gif';
	smileys[':\\?\\?\\?:'] = 'icon_confused.gif';
	
	
	smileys['8-\\)'] = 'icon_cool.gif';
	smileys['8\\)'] = 'icon_cool.gif';
	smileys[':cool:'] = 'icon_cool.gif';
	
	smileys[';\\('] = 'icon_cry.gif';
	smileys[';-\\('] = 'icon_cry.gif';
	smileys[':cry:'] = 'icon_cry.gif';
	
	smileys[':D'] = 'icon_grin.gif';
	smileys[':-D'] = 'icon_grin.gif';
	smileys[':grin:'] = 'icon_grin.gif';

	smileys[':o'] = 'icon_eek.gif';
	smileys[':-o'] = 'icon_eek.gif';
	smileys[':eek:'] = 'icon_eek.gif';
	
	smileys[':evil:'] = 'icon_evil.gif';

	smileys[':!:'] = 'icon_exclaim.gif';

	smileys[':idea:'] = 'icon_idea.gif';

	smileys[':\\)'] = 'icon_smile.gif';
	smileys[':-\\)'] = 'icon_smile.gif';
	smileys[':smile:'] = 'icon_smile.gif';
	
	smileys[':lol:'] = 'icon_lol.gif';
	
	smileys[':x'] = 'icon_mad.gif';
	smileys[':-x'] = 'icon_mad.gif';
	smileys[':mad:'] = 'icon_mad.gif';
	
	smileys[':mrgreen:'] = 'icon_mrgreen.gif';
	
	smileys[':\\|'] = 'icon_neutral.gif';
	smileys[':-\\|'] = 'icon_neutral.gif';
	smileys[':neutral:'] = 'icon_neutral.gif';
	
	smileys[':\\?:'] = 'icon_question.gif';
	
	smileys[':P'] = 'icon_razz.gif';
	smileys[':-P'] = 'icon_razz.gif';
	smileys[':razz:'] = 'icon_razz.gif';
	
	smileys[':oops:'] = 'icon_redface.gif';
	
	smileys[':roll:'] = 'icon_rolleyes.gif';
	
	smileys[':\\('] = 'icon_sad.gif';
	smileys[':-\\('] = 'icon_sad.gif';
	smileys[':sad:'] = 'icon_sad.gif';
	
	smileys['8O'] = 'icon_shock.gif';
	smileys['8-O'] = 'icon_shock.gif';
	smileys[':shock:'] = 'icon_shock.gif';
	
	smileys[':twisted:'] = 'icon_twisted.gif';
	
	smileys[';\\)'] = 'icon_wink.gif';
	smileys[';-\\)'] = 'icon_wink.gif';
	smileys[':wink:'] = 'icon_wink.gif';
	
	
	for (value in smileys) {
		smiley = "<img src='/img/smileys/" + smileys[value] + "'>";
		var search = RegExp("[.*]?("+ value +")[.*]?","i");
		string = string.replace(search, smiley);
	}
	return string;	
}

selectedScheduleLocation = new Array();