var IE = document.all?true:false;
var profileWasChanged = false;
var destinationsArray = [];
var destinationsIdsArray = [];
var wishlistsArray = [];
var wishlistsIdsArray = [];
var aPhotoIds = "";
var addressChanged = false;
var isSuggestDivShow = false;
var isSearchBtnClick = false;
var country_lt = [];
var country_lg = [];

function chSearchBtnSub()
{
	valIsSearch = 0;
	if(!isSearchBtnClick)
	{
		try
		{
			divSearchForm = document.getElementById('add-search-param');
			objOff(divSearchForm);
		}
		catch(Exception){}
		try
		{
			divSearchForm2 = document.getElementById('search-add-tags');
			objOff(divSearchForm2);
		}
		catch(Exception){}
	}
	else
	{
		try
		{
			divSearchForm = document.getElementById('add-search-param');
			objOn(divSearchForm);
		}
		catch(Exception){}
		try
		{
			divSearchForm2 = document.getElementById('search-add-tags');
			objOn(divSearchForm2);
		}
		catch(Exception){}
		valIsSearch = 1;
	}
	try
	{
		divSearchForm3 = document.getElementById('is_adv_search');
		divSearchForm3.value = valIsSearch;
	}
	catch(Exception){}
	
}


function chSearchBtn(el)
{
	if(isSearchBtnClick)
	{
		imgObj = new Image();
		imgObj.src = '/img/site/btn_search.gif';
		imgTopSearch = document.getElementById('top_search_btn');
		imgTopSearch.src = imgObj.src;
		el.className = "icon topsearch";
		isSearchBtnClick = false;
		
	}
	else
	{
		imgObj = new Image();
		imgObj.src = '/img/site/btn_search_black.gif';
		imgTopSearch = document.getElementById('top_search_btn');
		imgTopSearch.src = imgObj.src;
		el.className = "icon topsearch dark";
		isSearchBtnClick = true;
	}
	chSearchBtnSub();
	//imgTopSearch
}

function reloadSearchForm(r)
{
	adivName = document.getElementById('searchCont');
	adivName.innerHTML = r.responseText;
	chSearchBtnSub();
}

function _handleChangeSearchType(o,link)
{
	goLinkEmp(link+o.value);
}

function deleteComment(el_id, fname)
{
	var LocFormName = fname;

	eval("cform = document."+LocFormName);
	cform.comm_id.value = el_id;
	cform.comm_action.value = 2;
	cform.submit();
}


function goChSerch(qt,basepath)
{
	var a = new ajax();
	adivName = document.getElementById('searchCont');
	//objOn(adivName);
	a.callback = reloadSearchForm;
	var post = 'qt='+qt+'&load=1';
	a.postData(GlobalDocumentAbsPath+'/search/', post, adivName);	
}


var calendar = null;
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
	cal.hide();
}


function urldecode( str ) {
    var ret = str;
       
    ret = ret.replace(/\+/g, '%20');
    ret = decodeURIComponent(ret);
    ret = ret.toString();
 
    return ret;
}

function chSearchTag(val)
{
	
	//val = urldecode(val);
	if(document.getElementById('q').value!='') document.getElementById('q').value = document.getElementById('q').value+' '+val;
	else document.getElementById('q').value = val;
	//alert(val);
}

function closeHandler(cal) {
	cal.hide();			// hide the calendar
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
					// FIXME: allow end-user to click some link without closing the
					// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

function showCalendar(id) 
{
					var el = document.getElementById(id);
					if (calendar != null) {
						// we already have one created, so just update it.
						calendar.hide();		// hide the existing calendar
						calendar.parseDate(el.value); // set it to a new date
					} else {
						// first-time call, create the calendar
						var cal = new Calendar(true, null, selected, closeHandler);
						calendar = cal;		// remember the calendar in the global
						cal.setRange(1900, 2070);	// min/max year allowed
						
						calendar.create();		// create a popup calendar
						calendar.parseDate(el.value);
					}
					calendar.sel = el;		// inform it about the input field in use
					//alert(el.id);
					calendar.showAtElement(el);	// show the calendar next to the input field

					// catch mousedown on the document
					Calendar.addEvent(document, "mousedown", checkCalendar);
					return false;
}


function savePageURL()
{
     d = document;
     iTime = new Date();
     var a = '<img src="/index/?savepageurl=1&f=';
     a += escape(d.location.href);
     a += "&time=";
     a += iTime.getMilliseconds();
     a += '" width="1" height="1" border="0" />';
     document.write(a);
}

function goTextLink(str)
{
	if(IE)
	{
		location.href = '/search/?formname=search&search_1=' + escape(str);
	}
	else location.href = '/search/?formname=search&search_1=' + encodeURI(str);
}


function objOn(obj)
{
     obj.style.display = "block";
     obj.style.visibility = "visible";
}     

function objOff(obj)
{
     obj.style.visibility = "hidden";
     obj.style.display = "none";
}

function go(path)
{
     document.location.href = path;
}
function shw_blck(obj1,obj2) {
	var b1 = document.getElementById(obj1);
	var b2 = document.getElementById(obj2);
	if (b1.style.display == 'none') {
		b1.style.display = 'block';
		b2.style.display = 'block';
		document.getElementById('header').style.backgroundRepeat = 'no-repeat;'
	} else {
		b1.style.display = 'none';
		b2.style.display = 'none';
		document.getElementById('header').style.backgroundRepeat = 'repeat;'
	}
}

function shw_auth() {
	if (document.getElementById('auth').style.display == 'none') {
	document.getElementById('auth').style.display = 'block';
	arr_sel = document.getElementsByTagName('select');
	for (i=0;i<arr_sel.length;i++) {
		arr_sel[i].style.visibility = 'hidden';
	}
	} else {
	document.getElementById('auth').style.display = 'none';
	arr_sel = document.getElementsByTagName('select');
	for (i=0;i<arr_sel.length;i++) {
		arr_sel[i].style.visibility = 'visible';
	}
	}
}


function auth_focus(obj) {
	if (obj.value == 'Your username' || obj.value == 'Login (Email)' || obj.value == '*' || obj.value == 'Log in Email') {
		obj.value = '';
	}
}

function field_focus(obj,t) {
	if (obj.value == t) {
		obj.value = '';
	}
}


function auth_blur(obj,t) {
	if (obj.value == '' ) {
		obj.value = t;
	}
}

function setPhotos(value)
{
	aPhotoIds = value;
}


function form_submit(formName,val_hid) {
	if (val_hid) {
		if(IE) {
			document.getElementsByName(formName)[0].firstChild.value = '1';
		}
		else {
			document.getElementsByName(formName)[0].childNodes[1].value = '1';
		}
	}
	if(formName=='farticle' || formName=='trip-note')
	{
		
		selectObj = document.getElementById('controlDisplay');
		str = selectObj.innerHTML.toLowerCase();
		pos1 = str.indexOf("<script>parent.setphotos('");
		pos2 = str.indexOf("');</script>");
		str_val = str.substr(pos1+26,pos2-pos1-26);
		inpVal = document.getElementById('var_fld_overview_photogal');
		inpVal.value = str_val;
	}
	
	if(formName=='registration_basic')
	{
		city_fullname = document.getElementById('f936/f805').value;
		splits = city_fullname.split(",", 3);
		city_name = splits[0];
		country_name = splits[1];
		address = document.getElementById('f935').value;
	}
	
	if(formName=='flocation_contact')
	{
		//document.getElementsByName(formName)[0].submit();
		iCountryName = document.getElementById('location_country_name').value;
		iCityName = document.getElementById('location_city_name').value;
		iAddrName = document.getElementById('f977').value;
		locName = document.getElementById('location_el_name').value;
		//alert(iCountryName);
		document.getElementsByName(formName)[0].submit();
		return true;
	}
	
	document.getElementsByName(formName)[0].submit();
}

function sell_dest_submit(formName,val_hid)
{
	selectObj = document.getElementById('fld_source');
	selectSourceObj = document.getElementById(selectObj.value);
	if(selectSourceObj.value=='')
	{
		alert('Please, Enter Destination Name');
		return false;
	}
	
	
	form_submit(formName,val_hid);
}

function form_reset(formName) {
	document.getElementsByName(formName)[0].reset();
}





function shw_field(obj) {
	if (document.getElementById(obj).style.visibility == 'hidden') {
		document.getElementById(obj).style.visibility = 'visible';
	} else {
		document.getElementById(obj).style.visibility = 'hidden';
	}
}


function tab_sel(a,c) {
	if(profileWasChanged) {
		if(confirm('The information on this screen will not be saved if you switch. Do you want to continue?')) changeTab(a,c);
	}else changeTab(a,c);
}

var dispCounter = 0;
function changeTab(a,c){
	var cnt = c+1;
	for (var i=1; i<cnt; i++) {
		document.getElementById('tab_'+i).className = 'ss';
		document.getElementById('edit_'+i).style.display = 'none';
	}
	document.getElementById('tab_'+a).className = 'selected';
	document.getElementById('edit_'+a).style.display = 'block';
	profileWasChanged = false;
	
	try
	{
		obj = document.getElementById('sys_msg_place');
		dispCounter++;
		if(dispCounter>1) objOff(obj);
	}
	catch(Exception){}
	
	
}

function shw_smn(obj) {
	if (document.getElementById(obj)) document.getElementById(obj).style.display = 'block';
}

function hd_smn(obj) {
	if (document.getElementById(obj)) document.getElementById(obj).style.display = 'none';
}

function hd_suggDiv(obj) {
	try
	{
		if ( document.getElementById(obj) ) {
			if (document.getElementById(obj).style.display != 'none') {
				if (isSuggestDivShow == false) {
					isSuggestDivShow = true;
				} else {
					document.getElementById(obj).style.display = 'none';
					isSuggestDivShow = false;
				}
	
			}
		}
	}
	catch(Exception){}
	
	
}
function shw_hd_smn(obj) {
	try
	{
		if (document.getElementById(obj).style.display == 'none') {
			document.getElementById(obj).style.display = 'block';
		}
		else {
			document.getElementById(obj).style.display = 'none';
		}
	}
	catch(Exception){}
}

function shw_tip(obj,txt) {
	document.getElementById(obj).innerHTML=txt;
	document.getElementById(obj).style.color='#999'
}
function hd_tip(obj,txt) {
	document.getElementById(obj).innerHTML=txt;
	document.getElementById(obj).style.color='#ccc'
}

function sbmt_next(obj) {
	document.getElementById('reg'+obj).submit();
	document.getElementById('nextstep'+obj).value = '1';
}

function set_data_value() {
}

function formChangesSetup() {
	forms = document.forms;
	for(var i = 0;i < forms.length;i++){
		if (forms[i].name == 'registration_basic' || forms[i].name == 'registration_contact' || forms[i].name == 'registration_personal' || forms[i].name == 'registration_favorites' || forms[i].name == 'registration_background'){
			for(var j = 0;j < forms[i].childNodes.length;j++) {
				if(IE) forms[i].elements[j].onchange = function(){profileWasChanged = true;}
				else forms[i].childNodes[j].onchange = function(){profileWasChanged = true;}
			}
		}
	}
}

function check_terms(t) {
	if (document.getElementById('terms').checked) {
		return true;
	}
	else {
		alert(t);
		return false;
	}
}


function redraw_dest(div,sel) {
	 	div.innerHTML = '';
	 	for(var i=0; i<destinationsArray.length; i++) div.innerHTML += '<div id="destinationDiv' + destinationsIdsArray[i] + '"><div onClick="removeDestination(' + destinationsIdsArray[i] + ');" class="destinationDeleteButton">&nbsp;</div><select id="destination' + destinationsIdsArray[i] + '" class="'+ sel.className +'" disabled="true"><option selected="selected">' + destinationsArray[i] + '</option></select></div>';
	 	div.style.display = 'block';
}

function destinationAdd(selId, divId) {
 	var sel = document.getElementById(selId);
 	var div = document.getElementById(divId);
 	var countryID = 0;
 	
 	var itsRepeat = false;
 	if (sel.value == 0) {
 		alert('Select a country!');
 		return false;
 	}
 	for(var i=0; i<destinationsIdsArray.length; i++) if(destinationsIdsArray[i] == sel.value) itsRepeat = true;
	if(!itsRepeat){
		destinationsIdsArray.push(sel.value);
	 	destinationsArray.push(sel.options[sel.selectedIndex].text);
	 	countryID = sel.options[sel.selectedIndex].value;
		redraw_dest(div,sel);
	 	sel.value = 0;
	}else alert(sel.options[sel.selectedIndex].text + ' is already selected!');
	
	/*city_lt = '';
	city_lg = '';
	if(countryID>0)
	{
		try
		{
			city_lt = country_lt[countryID];
			city_lg = country_lg[countryID];
		}
		catch(Exception){}
	}
	
	document.getElementById('var_fld_city_lt').value = city_lt;
	document.getElementById('var_fld_city_lg').value = city_lg;*/
	
}
function removeDestination(destinationId, divId){
	var div = document.getElementById('destinationDiv' + destinationId);
	if(destinationsIdsArray.length == 1) div.parentNode.style.display = 'none';
	div.parentNode.removeChild(div);
	for(var i=0; i<destinationsIdsArray.length; i++) {
		if (destinationsIdsArray[i] == destinationId) {
			destinationsIdsArray.splice(i, 1);
			destinationsArray.splice(i, 1);
		}
	}
}
function destinationSubmit(resultName, formName, selectId){
	nameField = document.getElementById('190_el_name');
	if(nameField.value == '') {
		alert('Enter name of destination please!');
		nameField.focus();
		return false;
	}
	var result = ':';
	for(var i=0; i<destinationsIdsArray.length; i++) result += destinationsIdsArray[i] + ':';
	if(document.getElementById(selectId).value != 0) countryIdForCenter = document.getElementById(selectId).value;
	else countryIdForCenter = destinationsIdsArray[destinationsIdsArray.length - 1];
	result += document.getElementById(selectId).value + ':';
	document.getElementsByName(resultName)[0].value = result;
	
	if(countryIdForCenter > 0){
		document.getElementById('var_fld_city_lt').value = parseFloat(country_lt[countryIdForCenter]);
		document.getElementById('var_fld_city_lg').value = parseFloat(country_lg[countryIdForCenter]);
		lookUpAddress('var_fld_destination_lt', 'var_fld_destination_lg', '', '', '', formName, 7, nameField.value);
	}else alert("Country is required!!!");
}

function redraw_wl(div,select) {
	 	div.innerHTML = '';
	 	for(var i=0; i<wishlistsArray.length; i++) div.innerHTML += '<div id="wishlistDiv' + wishlistsIdsArray[i] + '"><div onClick="removewishlist(' + wishlistsIdsArray[i] + ');" class="wishlistDeleteButton">&nbsp;</div><select id="wishlist' + wishlistsIdsArray[i] + '" class="'+ select.className +'" disabled="true"><option selected="selected">' + wishlistsArray[i] + '</option></select></div>';
	 	div.style.display = 'block';
}

function wishlistAdd(selectId, divId) {
 	var select = document.getElementById(selectId);
 	var div = document.getElementById(divId);
 	var itsRepeat = false;
 	if (select.value == 0) {
 		alert('Select a country!');
 		return false;
 	}
 	for(var i=0; i<wishlistsIdsArray.length; i++) if(wishlistsIdsArray[i] == select.value) itsRepeat = true;
	if(!itsRepeat){
		wishlistsIdsArray.push(select.value);
	 	wishlistsArray.push(select.options[select.selectedIndex].text);
	 	div.innerHTML = '';
	 	for(var i=0; i<wishlistsArray.length; i++) div.innerHTML += '<div id="wishlistDiv' + wishlistsIdsArray[i] + '"><div onClick="removewishlist(' + wishlistsIdsArray[i] + ');" class="wishlistDeleteButton">&nbsp;</div><select id="wishlist' + wishlistsIdsArray[i] + '" class="'+ select.className +'" disabled="true"><option selected="selected">' + wishlistsArray[i] + '</option></select></div>';
	 	select.value = 0;
	 	div.style.display = 'block';
	}else alert(select.options[select.selectedIndex].text + ' is already selected!');
}
function removewishlist(wishlistId, divId){
	var div = document.getElementById('wishlistDiv' + wishlistId);
	if(wishlistsIdsArray.length == 1) div.parentNode.style.display = 'none';
	div.parentNode.removeChild(div);
	for(var i=0; i<wishlistsIdsArray.length; i++) {
		if (wishlistsIdsArray[i] == wishlistId) {
			wishlistsIdsArray.splice(i, 1);
			wishlistsArray.splice(i, 1);
		}
	}
}

function favoritesSubmit(destinationName, wishlistName, formName,val_hid){
	var result = ':';
	if(val_hid==0) val_hid = '';
	for(var i=0; i<destinationsIdsArray.length; i++) result += destinationsIdsArray[i] + ':';
	document.getElementsByName(destinationName)[0].value = result;
	var result = ':';
	for(var i=0; i<wishlistsIdsArray.length; i++) result += wishlistsIdsArray[i] + ':';
	document.getElementsByName(wishlistName)[0].value = result;
	if(IE) {
		document.getElementsByName(formName)[0].firstChild.value = val_hid;
	}
	else {
		document.getElementsByName(formName)[0].childNodes[1].value = val_hid;
	}
	document.getElementsByName(formName)[0].submit();
}


function shw_sel2(obj,tt)
{
	 shw_sel(obj,tt);
	 document.getElementById('sel_value').value = obj.value;
}


function shw_sel(obj,tt) {
	if (document.getElementById('shw_sel_var').value != '') {
		document.getElementById('sel_'+document.getElementById('shw_sel_var').value).style.display = 'none';
	}
	
	if ((obj.value != '0') && (obj.value != tt)) {
		document.getElementById('shw_sel_var').value = obj.value;
		document.getElementById('sel_'+obj.value).style.display = 'inline';
	}
	
	if(obj.value == '0'){ document.getElementById('sel_value').value = 0;}
	else if (obj.value != tt)
	{
		document.getElementById('sel_value').value = document.getElementById('sel_'+obj.value).value;
	} else {
		document.getElementById('sel_value').value = tt;
	}
}

function set_val(obj) {
	document.getElementById('sel_value').value = obj.value;
	try {
		if(document.getElementById('shw_sel_var').value == 1 && document.getElementById('sel_value').value == 3) {
			document.getElementById('statusChekboxes').style.display = '';
			document.getElementById('cusineChekboxes').style.display = 'none';
		}else if(document.getElementById('shw_sel_var').value == 2 && document.getElementById('sel_value').value == 6){
			 document.getElementById('cusineChekboxes').style.display = '';
			 document.getElementById('statusChekboxes').style.display = 'none';
		}else{
			document.getElementById('cusineChekboxes').style.display = 'none';
			document.getElementById('statusChekboxes').style.display = 'none';
		} 
	} catch (e) {}
}


function create_location_sel(obj)
{
	city_id = 0 + 1*(document.getElementById('f976/f805_aselect').value);
	categ_id = 0 + 1*(document.getElementById('sel_value').value);
	if(document.getElementById('f982').value=='' || city_id==0 || categ_id==0)
	{
		alert("Please enter 'What is it about?' and 'Where on earth is it?' and 'What's it called?'");
		return false;
	}
	
	document.getElementById('192_el_name').value = document.getElementById('f982').value;
	city_fullname = document.getElementById('f976/f805').value;
	
	eval("fform = document."+obj);
	fform.submit();
}

function create_location(obj)
{
	city_id = 0 + 1*(document.getElementById('f976/f805_aselect').value);
	categ_id = 0 + 1*(document.getElementById('sel_value').value);
	if(document.getElementById('f982').value=='' || city_id==0 || categ_id==0)
	{
		alert("Please enter 'What is it about?' and 'Where on earth is it?' and 'What's it called?'");
		return false;
	}
	
	document.getElementById('192_el_name').value = document.getElementById('f982').value;
	city_fullname = document.getElementById('f976/f805').value;
	splits = city_fullname.split(",", 3);
	city_name = splits[0];
	country_name = splits[1];
	address = document.getElementById('f977').value;
	
	/*
	alert(address); return false;
	eval("fform = document."+obj);
	fform.submit();
	*/
	locname = document.getElementById('f982').value;
	lookUpAddress('var_fld_location_lt', 'var_fld_location_lg', country_name, city_name, address, obj, false, locname);
	//alert(country_name+city_name+address);

	return true;

}

var priorities = [1, 2, 3, 4];
var prioritiesNames = ['Quality', 'Style', 'Value', 'Service'];

function change_priorities() {
	document.getElementById('lifestyles').innerHTML = reDrawPriorities();
	for (i=1; i<5; i++) {
		upArrow = document.getElementById('arr' + i + '_up');
		downArrow = document.getElementById('arr' + i + '_dn');
		if(upArrow.parentNode.parentNode.id != 'ls_div1') upArrow.style.visibility = 'visible';
		else upArrow.style.visibility = 'hidden';
		if(downArrow.parentNode.parentNode.id != 'ls_div4') downArrow.style.visibility = 'visible';
		else downArrow.style.visibility = 'hidden';
	}
	document.getElementById('prior_save').style.display = 'inline';
	document.getElementById('prior_change').style.display = 'none';
}

function reDrawPriorities(){
	var HTML = '';
	for (i=1; i<5; i++) {
		HTML += '<div id="ls_div' + i + '" style="overflow: hidden;">' +
				'<div style="float: left;">' +
				'<input id="priority' + priorities[i - 1] + '" type="text" value="' + i + '" name="priority' + priorities[i - 1] + '" maxlength="1"/>' +
				'. ' + prioritiesNames[priorities[i - 1] - 1] +
				'</div>' +
				'<div style="float: left; padding-left: 5px; padding-top: 3px;">' +
				'<div id="arr' + priorities[i - 1] + '_up" class="arrs ar_up" style="visibility: hidden;" onclick="prioritiesUpOnClick(' + priorities[i - 1] + ')"></div>' +
				'<div id="arr' + priorities[i - 1] + '_dn" class="arrs" style="visibility: hidden;" onclick="prioritiesDownOnClick(' + priorities[i - 1] + ')"></div>' +
				'</div>' +
				'</div>';
	}
	HTML += '<input type="button" value="Change" onclick="change_priorities();" id="prior_change" class="btn"/><input type="button" value="Update" style="display: none;" onclick="save_priorities()" id="prior_save" class="btn"/>' +
			'</div>';
	return HTML;
}

function prioritiesUpOnClick(index){
	for (i=0; i<4; i++) {
		if(priorities[i] == index){
			tmp = priorities[i];
			priorities[i] = priorities[i - 1];
			priorities[i - 1] = tmp;
		}
	}
	change_priorities();
}

function prioritiesDownOnClick(index){
	for (i=3; i>-1; i--) {
		if(priorities[i] == index){
			tmp = priorities[i];
			priorities[i] = priorities[i + 1];
			priorities[i + 1] = tmp;
		}
	}
	change_priorities();
}

function save_priorities() {
	for (i=1; i<5; i++) {
		upArrow = document.getElementById('arr' + i + '_up').style.visibility = 'hidden';
		downArrow = document.getElementById('arr' + i + '_dn').style.visibility = 'hidden';
	}
	document.getElementById('prior_save').style.display = 'none';
	document.getElementById('prior_change').style.display = 'inline';
}

var zooma = '13';

function zoomer(var1,var2) {
	zooma++;
	
	//setCenterByAddress(var1, var2, var3, zooma);
	map.setCenter(new GLatLng(var1, var2), zooma);
}

function show_addform(obj) {
	document.getElementById('shadow').style.display='block';
	document.getElementById('form').style.display='block';
	document.getElementById('form_'+obj).style.display='block';
	return false;
}
function hide_addforms() {
	if (document.getElementById('shadow') && document.getElementById('shadow').style.display != 'none') document.getElementById('shadow').style.display='none';
	if (document.getElementById('form') && document.getElementById('form').style.display != 'none') document.getElementById('form').style.display='none';
	if (document.getElementById('form_fitin') && document.getElementById('form_fitin').style.display != 'none') document.getElementById('form_fitin').style.display='none';
	if (document.getElementById('form_sellocation') && document.getElementById('form_sellocation').style.display != 'none') document.getElementById('form_sellocation').style.display='none';
	return false;
}

function shw_regblock(obj,val) {
	if (obj.checked) {
		document.getElementById(val).style.display = 'block';
	} else {
		document.getElementById(val).style.display = 'none';
	}
}

function sel_input_type(obj,displ_type)
{
	
	document.getElementById('inp_f803').style.display = 'none';
	document.getElementById('inp_f804').style.display = 'none';
	document.getElementById('inp_f805').style.display = 'none';
	document.getElementById('inp_f1004').style.display = 'none';
	document.getElementById('inp_'+obj.value).style.display = displ_type;
}

function sel_input_type2(obj,ttt,displ_type)
{
	document.getElementById('inp_'+ttt+'f803').style.display = 'none';
	document.getElementById('inp_'+ttt+'f804').style.display = 'none';
	document.getElementById('inp_'+ttt+'f805').style.display = 'none';
	document.getElementById('inp_'+ttt+'f1004').style.display = 'none';
	document.getElementById('inp_'+ttt+obj.value).style.display = displ_type;
}

/*
 * Class for lookuping address from Google GeoIP Service
 * 
 * idAddressLt						-	id for hidden field for lookuped Latitude of entered address
 * idAddressLg						-	id for hidden field for lookuped Longtitude of entered address
 * country							-	country name, where address is located
 * city								-	city name, where address is located
 * address	 						-	address for lookuping
 * formName							-	form name for submit
 * zoomLevel						-	zoom level for map
 * elementName						-	name of location/destination/user, whish will be shown in tooltip baloon
 * 
 * function setCoordinatesOnMap()	-	function for drawing maps div and listening doubleclick
 */

function lookUpAddress(idAddressLt, idAddressLg, country, city, address, formName, zoomLevel, elementName) {
  zoomLevel = zoomLevel || 11;
  elementName = elementName || 'Unknown Name';
  var geocoder = new GClientGeocoder();
  if (country != '' || city != '' || address != ''){
	if(address != ''){
	  geocoder.getLatLng(
	    country + ", " + city + ", " + address,
	    function(point) {
	      if (point) submitingFormWithCoordinates(idAddressLt, idAddressLg, formName, point);
	      else setCoordinatesOnMap();
	    }
	  );
	}else setCoordinatesOnMap();//submitingFormWithCoordinates(idAddressLt, idAddressLg, formName, false);
  }else setCoordinatesOnMap();

  function createMarker(point, elementName) {
	    var marker = new GMarker(point);
		windowHTML = 
	    '<div id="item_info" xmlns="">' +
			'<div id="cont">' +
				'<div class="tabs">' +
					'<div style="float: right;">'+
						'<a href="#" onclick="subMap.removeOverlay(subMap.infoBox);" title="Close window" class="close"><img alt="Close window" src="/img/site/0.gif"/></a>'+
					'</div>' +
				'</div>' +
				'<div class="user">' +
					'<div class="imag">' +
						'<img src="/img/site/smile.gif" />' +
					'</div>' +
					'<div class="txt">' +
						'<span class="username">' + elementName + '</span><br/><span class="details small">Add this point as coordinates?<br /><br /></span><a class="buttonGreen" onclick="submitingFormWithCoordinates(\'' + idAddressLt + '\',\'' + idAddressLg + '\',\'' + formName + '\',new GLatLng(' + point.lat() + ',' + point.lng() + '));">Accept</a><a class="buttonGray" onclick="subMap.removeOverlay(subMap.infoBox);">Cancel</a>' +
					'</div>' +
				'</div>' +
				'<div style="margin-top: -10px;" class="tabs"><div style="float: right;">' +
				'</div>' +
			'</div>' +
			'<div class="moreinfo">' +
				'<span class="color georg big">' + '</span></div>' +
			'</div>' +
			'<img width="300" height="28" alt="" class="iePNG" src="/img/site/bg_infownd_btn.png"/>' +
		'</div>';
		var infoBoxOptions = {
			"content": windowHTML,
			"offsetVertical": -130
		};
		var infoBox = new InfoBox(point, infoBoxOptions);
		marker.infoBox = infoBox;
		return marker;
	}
  
  function setCoordinatesOnMap(){
	subDiv = document.createElement("div");
  	body = document.getElementsByTagName("body")[0];
  	body.appendChild(subDiv);
  	shadowDiv = document.createElement("div");
  	shadowDiv.style.position = "absolute";
  	shadowDiv.style.left = "0";
  	shadowDiv.style.top = "0";
  	shadowDiv.style.width = "100%";
  	shadowDiv.style.height = "100%";
  	shadowDiv.style.zIndex = "320";
  	if(location.pathname != '/members/location/'){
  		if(IE) {
	  		shadowDiv.style.backgroundImage = "url(/img/site/0.gif)";
	  		shadowDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/site/gmap/bg_header.png', sizingMethod='scale')";
	  	}else shadowDiv.style.backgroundImage = "url(/img/site/gmap/bg_header.png)";
  	}
  	body.appendChild(shadowDiv);
  	subDiv.style.position = "absolute";
  	subDiv.style.top = "10%";
  	subDiv.style.left = "10%";
  	subDiv.style.width = "80%";
  	subDiv.style.height = "80%";
  	subDiv.style.zIndex = "495";
  	subDiv.innerHTML = "<center><span class='popUpMapMessage'>We didn't find that spot on the database, please find it on the map and doubleclick your mouse on that locaiton point.</span></center>";
  	mapDiv = document.createElement("div");
  	subDiv.appendChild(mapDiv);
  	mapDiv.style.height = "90%";
  	mapDiv.style.border = "3px solid #000";
  	mapDiv.style.marginTop = "10px";
  	subMap = new GMap2(mapDiv);
  	ltCenter = document.getElementById('var_fld_city_lt');
  	lgCenter = document.getElementById('var_fld_city_lg');
  	if (ltCenter && lgCenter) subMap.setCenter(new GLatLng(ltCenter.value, lgCenter.value), zoomLevel);
  	else subMap.setCenter(new GLatLng(34, 0), 2);
  	subMap.enableScrollWheelZoom();
    subMap.disableDoubleClickZoom();
    subMap.addControl(new GSmallMapControl());
    subMap.addControl(new GMapTypeControl());
    GEvent.addListener(subMap, "dblclick", function(overlay, latlng) {
  	  subMap.clearOverlays();
  	  marker = createMarker(latlng, elementName);
  	  if (subMap.infoBox) subMap.removeOverlay(subMap.infoBox);
	  subMap.infoBox = marker.infoBox;
	  subMap.addOverlay(subMap.infoBox);
    });
  }
}

/*
 * Function for submiting form with coordinates in
 * 		'Class for lookuping address from Google GeoIP Service [lookUpAddress]'
 * 
 */

function submitingFormWithCoordinates(idAddressLt, idAddressLg, formName, latlng){
  	try{
	  	document.getElementById(idAddressLt).value = latlng.lat();
	  	document.getElementById(idAddressLg).value = latlng.lng();
	  	document.getElementsByName(formName)[0].submit();
		subDiv.style.display = 'none';
  	}catch(e){}
}