function copytextfromobj(objstr){

	var value = $("#"+objstr).focus().val();

	copyText(value);

}

function copyText(txt){

	  if(window.clipboardData) {

             window.clipboardData.clearData();

             window.clipboardData.setData("Text", txt);

     } else if(navigator.userAgent.indexOf("Opera") != -1) {

          window.location = txt;

     } else if (window.netscape) {

          try {

               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

          } catch (e) {

               alert("被瀏覽器拒絕！\n請在瀏覽器地址欄輸入'about:config'並回車\n然後將'signed.applets.codebase_principal_support'設置為'true'");

          }

          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);

          if (!clip)

               return;

          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);

          if (!trans)

               return;

          trans.addDataFlavor('text/unicode');

          var str = new Object();

          var len = new Object();

          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

          var copytext = txt;

          str.data = copytext;

          trans.setTransferData("text/unicode",str,copytext.length*2);

          var clipid = Components.interfaces.nsIClipboard;

          if (!clip)

               return false;

          clip.setData(trans,null,clipid.kGlobalClipboard);

     }

     alert('已經複製');

}

function showTagsBoxHotel(containerId, targetId){
	if ($("#search-type1-hotel").is(":checked")) showTagsBox('HOTEL', containerId, targetId,1);
	else if ($("#search-type1-attraction").is(":checked")) showTagsBox('ATTRACTION', containerId, targetId,1);
	else showTagsBox('FOOD', containerId, targetId,1);
}

function showTagsBoxTravel(containerId, targetId){
	if ($("#search-type2-travelinfo").is(":checked")) showTagsBox('TRAVELINFO', containerId, targetId,1);
	else showTagsBox('TRAVELNEWS', containerId, targetId,1);
}

function showTagsBox(type, containerId, targetId, page){
	//closeRegionTagBox();
	$("#"+containerId).html("<div style='padding: 10px; background: #FFF;'><img src='/images/common/common/loading-big.gif'/></div>").show();
	var param = "type="+type+"&targetId="+targetId+"&lang="+lang+"&page="+page+"&containerId="+containerId;
	$.ajax({
		type: "POST",
		url: "/bin/data/regiontags.php",
		data: param,
		success: function(msg){
			if (msg != ""){
				$("#"+containerId).html(msg);
			}
		}
	});
	return false;
}

function assignTagsValue(value , tagertId, tagid){

	//$("#"+tagertId).val(value);

	//closeRegionTagBox();

	

	var newvalue1 = $("#"+ tagertId).val();

	var findtagert1 = ","+value+",";

	var findtagert2 = "^"+value+",";

	var findtagert3 = ","+value+"$";

	var findtagert4 = "^"+value+"$";

	

	var hasSelected = false;

	if (newvalue1.search(findtagert1) != -1 || newvalue1.search(findtagert2) != -1 || newvalue1.search(findtagert3) != -1 || newvalue1.search(findtagert4) != -1){

		hasSelected = true;

	}

	if (hasSelected) {

		if (newvalue1.search(findtagert1) != -1) newvalue1 = newvalue1.replace(","+value+",", ",");

		else if (newvalue1.search(findtagert2) != -1) newvalue1 = newvalue1.replace(value+",", "");

		else if (newvalue1.search(findtagert3) != -1) newvalue1 = newvalue1.replace(","+value, "");

		else if (newvalue1.search(findtagert4) != -1) newvalue1 = newvalue1.replace(value, "");

		$("#"+ tagertId).val(newvalue1);

	}else{

		if (newvalue1 != "") newvalue1 += ",";

		newvalue1 += value;

		$("#"+ tagertId).val(newvalue1);

	}

}

function closeRegionTagBox(){

	$("#regionTagSelectBox").fadeOut('fast', function(){

		$("#regionTagSelectBox").remove();

	});

}

function openPlayer(targetLink){

	window.open (targetLink,'RADIOPLAYER','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=200, height=100');

}

function popupImgObj(obj){
	var newLink = $(obj).attr('src');
	newLink = newLink .replace("/tn2/", "/");
	newLink = newLink.replace("/tn1/", "/");
	newLink = newLink.replace("/tn/", "/");

	var img = new Image();
	img.src = newLink;

	img.onload = function(){
		var width = img.width;
		var height = img.height;
		var w_w = $(window).width();
		var w_h = $(window).height();
	
		var w = 0;
		var h = 0;
		if (height > w_h && width > w_w){
			if ((height / w_h) > (width / w_w)){
				h = w_h;
				w = w_w / ( height / w_h );
			}else{
				w = w_w;
				h = w_h / ( width / w_w ); 
			}
		}else if (height > w_h && width <= w_w){
			h = w_h;
			w = Math.ceil(width / height * h);
		}else if (width > w_w && height <= w_h){
			w = w_w;	
			h = Math.ceil(height / width * w);
		}else{
			w = width;
			h = height;
		}
	
		var pp = new popup('sat3dfsaf3');
		pp.setContent('<div style="background: #FFF; padding: 20px;"><img src="'+newLink+'" id="popupimg" width="'+w+'" height="'+h+'"/></div>');
		pp.popup();	
	}
}

function popupImg(imgpath){
	var img = new Image();
	img.src = imgpath;
	img.onload = function(){
		var width = img.width;
		var height = img.height;
		var w_w = $(window).width() - 150;
		var w_h = $(window).height() - 150;
	
		var w = 0;
		var h = 0;
		if (height > w_h && width > w_w){
			if ((height / w_h) > (width / w_w)){
				h = w_h;
				w = width / ( height / w_h );
			}else{
				w = w_w;
				h = height / ( width / w_w ); 
			}
		}else if (height > w_h && width <= w_w){
			h = w_h;
			w = Math.ceil(width / height * h);
		}else if (width > w_w && height <= w_h){
			w = w_w;	
			h = Math.ceil(height / width * w);
		}else{
			w = width;
			h = height;
		}
		var pp = new popup('sat3dfsaf3');
		pp.setContent('<div style="background: #FFF; padding: 20px;"><img src="'+imgpath+'" id="popupimg" width="'+w+'" height="'+h+'"/></div>');
		pp.popup();
	}
}

function getComment(type, id, page){

	var param = "type="+type+"&id="+id+"&page="+page+"&lang="+lang;

	$.ajax({

		type: "POST",

		url: "/bin/data/getcommentfromlist.php",

		data: param,

		success: function(msg){

			$("#commentlistidi").html(msg);

		}

	});

}

function removeBlogType(id){

	var param = "id="+id;

	$.ajax({

		type: "POST",

		url: "/bin/data/removeblogtype.php",

		data: param,

		success: function(msg){

			if (msg == 1) location.reload();

		}

	});

}

function setAlbumCover(id, imgpath){

	var param = 'id='+id;

	$.ajax({

		type: "POST",

		url: "/bin/import/album/setCover.php",

		data: param,

		success: function(msg){

		}

	});

}

var geocoder;

var map;

function codeAddress(address, region) {

	if (geocoder) {

		geocoder.geocode( { 'address': address}, function(results, status) {

			if (status == google.maps.GeocoderStatus.OK) {

					map.setCenter(results[0].geometry.location);

					var marker = new google.maps.Marker({

							map: map, 

							position: results[0].geometry.location

					});

					$('#h-panoramio-container').append('<iframe src="http://www.panoramio.com/plugin/?lt=' + results[0].geometry.location.lat() + '&ln=' + results[0].geometry.location.lng() + '&z=2&k=1" width="100%" height="100%" border="0"></iframe>');

			}

			else{

				if (region != ""){

					codeAddress(region, "");}

				else{

					$('#h-map-panoramio').css('display', 'none');}

			}

		});

	}

}



function removeGroupPhoto(id){

	var param = "lang="+lang+"&id="+id;

	$.ajax({

		type: "POST",

		url: "/bin/member/removegroupphoto.php",

		data: param,

		success: function(msg){

			if (msg = 1){

				window.location.reload();

			}

		}

	});

}

function loadFaceBookRightNav(){

	var param = '';

	$.ajax({

		type: "POST",

		url: "/bin/data/rightnavfb.php",

		data: param,

		success: function(msg){

			if (msg != ""){

				$("#rightnav-facebook").html(msg);

			}

			resizeFunc();

		}

	});

}

function showAlbumPhotos(page, id){

	var param = "lang="+lang+"&id="+id+"&page="+page;

	$.ajax({

		type: "POST",

		url: "/bin/data/getphotoforalbum.php",

		data: param,

		success: function(msg){

			if (msg != ""){

				$("#album-photos-con").html(msg);

				

				var pp = parseInt(page);

				

				$("#photo-list-next").unbind("click").click(function(){

					showAlbumPhotos(pp+1,id);

				});

				$("#photo-list-prev").unbind("click").click(function(){

					showAlbumPhotos(pp-1,id);

				});

				$("#photo-list-select").val(pp);



				if (pp == totalPage) $("#photo-list-next").hide();

				else $("#photo-list-next").show();

				if (pp == 1) $("#photo-list-prev").hide();

				else $("#photo-list-prev").show();

			}

		}

	});

}

function showTravelNews(id, target){

	var hh = $("#"+target).html();

	if (hh == ""){

		var param = "lang="+lang+"&id="+id;

		$.ajax({

			type: "POST",

			url: "/bin/data/gettravelnews.php",

			data: param,

			success: function(msg){

				if (msg != ""){

					$("#"+target).html(msg).hide().toggle('fast');

				}

			}

		});

	}else{

		$("#"+target).toggle('fast').html('');

	}

}

function removeBgBlogSetting(){

	var param = "lang="+lang;

	$.ajax({

		type: "POST",

		url: "/bin/data/removeBlogSettingBg.php",

		data: param,

		success: function(msg){

			if (msg == 1){

				$("#blog-setting-bgimgdiv").html("");

			}

		}

	});

}

function removeTitleBgBlogSetting(){

	var param = "lang="+lang;

	$.ajax({

		type: "POST",

		url: "/bin/data/removeBlogSettingTitleBg.php",

		data: param,

		success: function(msg){

			if (msg == 1){

				$("#blog-setting-titlebgimgdiv").html("");

			}

		}

	});

}

function updateBlogBoxId(target, value){

	var dd = $('div[_itemId="'+target+'"]').html();

	dd = dd.replace(target, value);

	$('div[_itemId="'+target+'"]').attr("_itemId", value).html(dd);

	blogSettingScanColumn("BLOGSETTING3orderListRight", "column2");

}

function editItemBlogSettingAdmin(itemId, typeId, memberId){

	var param = "/bin/data/blogsettingeditboxADMIN.php?lang="+lang+"&typeId="+typeId+"&itemId="+itemId+"&memberId="+memberId;

	var msg = '<iframe src="'+param+'" style="background: #FFF; width: 680px; height: 500px;"></frame>';

	var p = new popup("dasda8wds");

	p.setContent(msg);

	p.popup();

}

function editItemBlogSetting(itemId, typeId){

	var param = "/bin/data/blogsettingeditbox.php?lang="+lang+"&typeId="+typeId+"&itemId="+itemId;

	var msg = '<iframe src="'+param+'" style="background: #FFF; width: 680px; height: 500px;"></frame>';

	var p = new popup("da8wds");

	p.setContent(msg);

	p.popup();

}

function addItemToBlogSetting(obj, type){

	var param = "lang="+lang+"&type="+type;

	$.ajax({

		type: "POST",

		url: "/bin/data/blogsettingaddbox.php",

		data: param,

		success: function(msg){

			if (msg != ""){

				$('#column2').append(msg);

				if (type != 6) $(obj).attr('class', 'item_o abspos').unbind('click').attr('onclick','');

			}

			blogSettingScanColumn("BLOGSETTING3orderListRight", "column2");

		}

	});

}

function removeItemFromBlogSetting(id){

	typeId = $('div[_itemId="'+id+'"]').attr("_typeId");

	var oss = $("#blogType"+typeId).attr("__onclick");

	$("#blogType"+typeId).attr("class", "item abspos").unbind('click').click(function(){ eval(oss); });

	$('div[_itemId="'+id+'"]').remove();

	blogSettingScanColumn("BLOGSETTING3orderListRight", "column2");

}

function blogSettingScanColumn(hiddenField, targetId){

	var cc = "";

	$("#"+targetId).children("div[class='itemss']").each(function(){

		if (cc != "") cc += "|";

		var itemId = $(this).attr("_itemId");

		var typeId = $(this).attr("_typeId");

		cc += typeId+":"+itemId;

	});

	$("#"+hiddenField).val(cc);

}

function loadAlbumPhotoEntry(folder, id){

	var param = "lang="+lang+"&folder="+folder+"&id="+id;

	$.ajax({

		type: "POST",

		url: "/bin/data/albumentry.php",

		data: param,

		success: function(msg){

			if (msg != ""){

				$("#album-entry-photolist").html(msg);

			}

		}

	});		

}

function removeAlbumPhotoEntry(folder, albumid, filepath, id){

	var param = "lang="+lang+"&filepath="+filepath+"&id="+id;

	$.ajax({

		type: "POST",

		url: "/bin/data/albumentryremove.php",

		data: param,

		success: function(msg){

			if (msg != ""){

				loadAlbumPhotoEntry(folder, albumid)

			}

		}

	});

}

function showBox(objstr){

	if ($("#"+objstr).is(":hidden")){

		$("#"+objstr).fadeIn('fast');

	}

}

function hideBox(objstr){

	if (! $("#"+objstr).is(":hidden")){

		$("#"+objstr).fadeOut('fast');

	}

}

var moveTimer = null;

function movePhoto(objstr, direction, maxp){

	var move = 0;

	if (direction == "l") move = -500;

	else move = 500;

	

	var currentLeft = $("#"+objstr).css('marginLeft');

	var width = $("#"+objstr+"-c").width();

	currentLeft = parseInt(currentLeft.replace(/px/,""));

	

	move += currentLeft;

	if (direction == "l"){

		if (maxp - currentLeft < width){

			if (maxp - move > width ) move = 0 - width + maxp;

			$('#'+objstr).animate({ marginLeft: move }, 500, function() { });	

		}

	}else if (direction == "r"){

		if (currentLeft < 0){

			if (move > 0) move = 0 ;

			$('#'+objstr).animate({ marginLeft: move }, 500, function() { });	

		}

	}

}

function selectHeadImg(obj){

	var imgPath = $(obj).attr('src');

	$("#selectHeadimgDiv img").each(function(){

		var src = $(this).attr('src');

		if (src != imgPath) $(this).attr('class','normal');

		else $(this).attr('class','selected');

	});

	$("#REGISTERimgPath").val(imgPath);

}

function selectHeadImgCI(obj){

	var imgPath = $(obj).attr('src');

	$("#selectHeadimgDiv img").each(function(){

		var src = $(this).attr('src');

		if (src != imgPath) $(this).attr('class','normal');

		else $(this).attr('class','selected');

	});

	$("#CHANGEINFOimgPath").val(imgPath);

}

function checkAndShow(obj, targetId){

	if ($(obj).is(':checked') && $("#"+targetId).is(':hidden')){

		$("#"+targetId).toggle('fast');

	}else if (!$(obj).is(':checked') && !$("#"+targetId).is(':hidden')){

		$("#"+targetId).toggle('fast');

	}

}

function checkRegUserName(obj){

	var name = $(obj).val();

	if (name != "" && name != undefined) {

		$("#checkNameMessage").html("<img src='/images/common/common/loading.gif'/>");

		var param = "lang="+lang+"&name="+name;

		$.ajax({

			type: "POST",

			url: "/bin/data/checkname.php",

			data: param,

			success: function(msg){

				if (msg != ""){

					$("#checkNameMessage").html(msg);

				}

			}

		});

	}

}

function checkRegEmail(obj){

	var email = $(obj).val();

	if (email != "" && email != undefined) {

		$("#checkEmailMessage").html("<img src='/images/common/common/loading.gif'/>");

		var param = "lang="+lang+"&email="+email;

		$.ajax({

			type: "POST",

			url: "/bin/data/checkemail.php",

			data: param,

			success: function(msg){

				if (msg != ""){

					$("#checkEmailMessage").html(msg);

				}

			}

		});		

	}

}

function changelang(){

	$('#toplanglist').toggle('fast', function() { });

}

function resizeFunc(){

	var ch = $("#contentnav").height();

	var rh = $("#rightnav").height();

	if (rh > ch) ch = rh;

	$("#content-framework").css({ height: ch });

}

function showsearchmenu(obj){

	var id = $(obj).attr("id");

	if ( !$("#search-comment-c").is(":hidden") && id != "search-comment"){

		$("#search-comment-c").toggle('fast' , function(){ })

	}

	if ( !$("#search-travelevent-c").is(":hidden") && id != "search-travelevent"){

		$("#search-travelevent-c").toggle('fast' , function(){ })

	}

	if ( !$("#search-blog-c").is(":hidden") && id != "search-blog"){

		$("#search-blog-c").toggle('fast' , function(){ })

	}

	if ( !$("#search-album-c").is(":hidden") && id != "search-album"){

		$("#search-album-c").toggle('fast' , function(){ })

	}

	if ( !$("#search-member-c").is(":hidden") && id != "search-member"){

		$("#search-member-c").toggle('fast' , function(){; })

	}

	if ( !$("#search-radio-c").is(":hidden") && id != "search-radio"){

		$("#search-radio-c").toggle('fast' , function(){; })

	}

	$("#"+id+"-c").toggle('fast' , function(){ resizeFunc(); })

}

function hometag(input){
	var tags = new Array("tag-homenews", "tag-travelnews", "tag-travelactivities");
	for(var i = 0; i < tags.length; i++){
		if (input == tags[i]){
			var imgsrc = $("#"+tags[i]+"-img").attr('src');
			if (imgsrc){
				imgsrc = imgsrc.replace("_o.png", ".png");
				imgsrc = imgsrc.replace(".png", "_o.png");
				$("#"+tags[i]+"-img").attr('src', imgsrc);
				$("#" + tags[i]).show();
			}
		}else{
			var imgsrc = $("#"+tags[i]+"-img").attr('src');
			if (imgsrc){
				imgsrc = imgsrc.replace("_o.png", ".png");
				$("#"+tags[i]+"-img").attr('src', imgsrc);
				$("#" + tags[i]).hide();
			}
		}
	}
}

function showRegionBoxRadio(containerId, targetId, targetId2){
	closeRegionBox();
	$("#"+containerId).html("<div style='padding: 10px; background: #FFF;'><img src='/images/common/common/loading-big.gif'/></div>").show();
	var param = "targetId="+targetId+"&targetId2="+targetId2+"&lang="+lang+"&type=radio";
	$.ajax({
		type: "POST",
		url: "/bin/data/region.php",
		data: param,
		success: function(msg){
			if (msg != ""){
				$("#"+containerId).html(msg);
				regionContent('radio', targetId, targetId2);
			}
		}
	});
	return false;	
}

function showRegionBox(containerId, targetId, targetId2){
	closeRegionBox();
	$("#"+containerId).html("<div style='padding: 10px; background: #FFF;'><img src='/images/common/common/loading-big.gif'/></div>").show();
	var param = "targetId="+targetId+"&targetId2="+targetId2+"&lang="+lang+"&type=region";
	$.ajax({
		type: "POST",
		url: "/bin/data/region.php",
		data: param,
		success: function(msg){
			if (msg != ""){
				$("#"+containerId).html(msg);
				regionContent('region', targetId, targetId2);
			}
		}
	});
	return false;
}

function clickRegionMenu(type, input, targetId1, targetId2){

	$("#bigregionmenu div").each(function(){

		var _v = $(this).attr("_v");

		if (_v == input) $(this).attr('class', 'bigregionItem_o abspos');

		else $(this).attr('class', 'bigregionItem abspos');

	});

	$("div[id^=region-sub-menu_]").each(function(){

		var _v = $(this).attr("_v");

		if (_v == input) $(this).show();

		else $(this).hide();

	});

	regionContent(type, targetId1, targetId2);

}

function clickRegionSubMenu(type, parent, input, targetId1, targetId2){

	$("#region-sub-menu_"+parent+" div").each(function (){

		var _v = $(this).attr("_v");

		if (_v != "" && _v != undefined && _v != "undefined"){

			if (_v == input){

				$(this).attr('class', "region-submenu-link_o abspos");

				$(this).attr('_s', "select");

			}

			else{

				$(this).attr('class', "region-submenu-link abspos");

				$(this).attr('_s', "");

			}

		}

	});

	regionContent(type, targetId1, targetId2);

}

function searchRegion(type, targetId1, targetId2, obj){

	$("#region-main-content").html("<img src='/images/common/common/loading-big.gif'/>");



	var bbb = $("#"+obj).val();

	

	var _v = "";

	$('div[id^="region-sub-menu_"]').each(function(){

		if (! $(this).is(":hidden")){

			$(this).children('div').each(function(){

				var _s = $(this).attr("_s");

				if (_s == "select") _v = $(this).attr("_v");

			});

		}

	});

	var values = $("#"+targetId2).val();	

	

	var param = "lang="+lang+"&targetId="+targetId1+"&targetId2="+targetId2+"&type="+type+"&search="+bbb+"&val="+values;

	$.ajax({

		type: "POST",

		url: "/bin/data/region-search.php",

		data: param,

		success: function(msg){

			$("#region-main-content").html(msg);

		}

	});

}

function regionContent(type, targetId1, targetId2, input){

	$("#region-main-content").html("<img src='/images/common/common/loading-big.gif'/>");

	var _v = "";

	$('div[id^="region-sub-menu_"]').each(function(){

		if (! $(this).is(":hidden")){

			$(this).children('div').each(function(){

				var _s = $(this).attr("_s");

				if (_s == "select") _v = $(this).attr("_v");

			});

		}

	});

	

	var values = $("#"+targetId2).val();

	var param = "region="+_v+"&lang="+lang+"&targetId="+targetId1+"&targetId2="+targetId2+"&type="+type+"&val="+values;

	$.ajax({

		type: "POST",

		url: "/bin/data/region-content.php",

		data: param,

		success: function(msg){

			$("#region-main-content").html(msg);

		}

	});

}

function clickRegionLevel4(input){

	$('div[id^="region-level5-item_"]').each(function(){

		var _v = $(this).attr("_v");

		var isHidden = $(this).is(":hidden");



		if (_v == input){

			if(isHidden) $(this).show();

			$("#level4-btn"+_v).attr('src', '/images/common/regionbox/icon-show.png');

		}else if (_v != input) {

			$(this).hide()

			$("#level4-btn"+_v).attr('src', '/images/common/regionbox/icon-hide.png');

		}

	});

}

function regionLevel3Click(input){

	$('div[id^="level3-item_"]').each(function(){

		var _v = $(this).attr("_v");

		var isHidden = $(this).is(":hidden");

		if (_v != input){

			if(!isHidden) $(this).toggle('fast', function(){});

			$("#r-level3-item_"+_v).show();

		}

		else{

			$("#r-level3-item_"+_v).hide();

			$(this).toggle('fast', function(){});

		}

	});

}

function assignValue(targetId, targetId2, value1, value2){

	var newvalue1 = $("#"+ targetId).val();

	var newvalue2 = $("#"+ targetId2).val();

	var findtagert1 = ","+value2+",";

	var findtagert2 = "^"+value2+",";

	

	var hasSelected = false;

	if (newvalue2.search(findtagert1) != -1 || newvalue2.search(findtagert2) != -1){

		hasSelected = true;

		newvalue2 = newvalue2.replace(value2+",", "");

	}

	if (hasSelected) {

		newvalue1 = newvalue1.replace(","+value1, "");

		newvalue1 = newvalue1.replace(value1, "");

		$("#regionSelect"+value2).attr('checked', false);

	}else{

		if (newvalue1 != "") newvalue1 += ",";

		newvalue1 += value1;

		newvalue2 += value2 + ",";

		$("#regionSelect"+value2).attr('checked', true);

	}

	$("#"+ targetId).val(newvalue1);

	$("#"+ targetId2).val(newvalue2);



	//closeRegionBox();

}

function closeRegionBox(){

	$("#regionSelectBox").fadeOut('fast', function(){

		$("#regionSelectBox").remove();

	});

}

var Browser = {

  Version: function() {

    var version = 999; // we assume a sane browser

    if (navigator.appVersion.indexOf("MSIE") != -1)

      // bah, IE again, lets downgrade version number

      version = parseFloat(navigator.appVersion.split("MSIE")[1]);

    return version;

  }

}
