function selectChar(choice,type,item) {
if(item.value) {

	var id = item.value;
	var sel = type+id;
	var des = type+'S'+id;

	switch (choice) {
	case 'S':
		var opt = $("#"+sel);
		var newOpt = opt.clone()
		newOpt.attr('id',des);
		$("#D"+type).append(newOpt);
		opt.attr("disabled","disabled");
	break;
	case 'D':
		var opt = $("#"+sel);
		var opts = $("#"+des);
		opt.attr("disabled","");
		opts.detach();
	break;
	}
	
	$.post("mbuysell_updatePropertyChar.html",{ id: profileId, charId: id, value: choice});
	$('#S'+type).attr('selectedIndex', '-1');

}
}



function updatePropertyProfile(fieldName,fieldValue) {
	$.post("mbuysell_updatePropertyProfile.html",{ id: profileId, field: fieldName, value: fieldValue});
}

function propTab(tabId) {
	$(".propTab").css("display","none");
	$("#propTab"+tabId).css("display","");
	$(".propTabImage").css("display","none");
	$("#propTabImage"+tabId).css("display","");
	$(".propTabBox div").addClass("bg_strip2");
	$(".propTabBox div").removeClass("bg_strip1");
	$("#propTabBox"+tabId+" div").removeClass("bg_strip2");
	$("#propTabBox"+tabId+" div").addClass("bg_strip1");
}

function changeIt(imgName) {
	var theImg = document.getElementById(imgName).src;
	var x = theImg.split("/");
	var t = x.length-1;
	var y = x[t];
	if(y=='green_untick.png'){
		document.getElementById(imgName).src='http://cdn.urbytus.net/_icons/ocm/green_tick.png'
	}
	if(y=='green_tick.png'){
		document.getElementById(imgName).src='http://cdn.urbytus.net/_icons/ocm/green_untick.png'
	}
}



function removeYoutube() {
	var isConf = confirm('<?= langItem(462); ?>');
	if (isConf) {
	updatePropertyProfile("yt_id",'');
	updatePropertyProfile("yt_title",'');
	updatePropertyProfile("yt_desc",'');
	updatePropertyProfile("yt_swf",'');
	updatePropertyProfile("yt_thumb",'');
	$("#youtube").val('');
	$("#ytvideo").detach();
	$("#yt_save").detach();
	}
}


function attach_youtube() {
	$("#youtubeBox").html( '<br /><br /><center><img src="http://cdn.urbytus.net/images/jsonLoader.gif" /></center>' );
	var url = $("#youtube").val();
	$.post("mbuysell_youtube.html",{ url: url}, function(res) {
		$("#youtubeBox").html( res );
	});
}






function buysell_upload(iType) {
	$("#form_"+iType).submit();
	$(".uploadInput").val('');
}
function changeMainImage(imageId,md5) {
	$("#mainImage").css("background-image","url(pi_"+md5+"_S.jpg)");
	$("#mainImage").attr("rel",imageId);
	$("#form_M").css("display","none");
	$("#deleteMain").css("display","block");
	
}
function removeMainImage() {
	var imageId = $("#mainImage").attr("rel");
	var profileId = $("#profileId").val();
	$("#mainImage").css("background-image","");
	$.post("mbuysell_removeImage.html",{ id: imageId, pid: profileId });
	$("#form_M").css("display","");
	$("#deleteMain").css("display","none");
}
function addExtraImage(imageId,md5) {
	var newImage = '<div class="is pip" id="extra'+imageId+'" onclick="removeExtraImage(\''+imageId+'\');" style="background-repeat: none;background-image: url(\'pi_'+md5+'_T.jpg\');"></div>';
	$("#extraImages").append(newImage);
	evalExtras();
}

function removeExtraImage(imageId) {
	var profileId = $("#profileId").val();
	$("#extra"+imageId).detach();
	$.post("mbuysell_removeImage.html",{ id: imageId, pid: profileId });
	evalExtras();
}

function evalExtras() {
	var c = $(".is").length;
	if (c == 10) {
		$("#form_A").css("display","none");
	} else {
		$("#form_A").css("display","");
	}
}

function activateListing() {
	var profileId = $("#profileId").val();
	updatePropertyProfile('isActive','Y');
//	example_ajax_request('buysell/my_property.php');
}
function removeListing(pid) {
	$.post("mbuysell_updatePropertyProfile.html",{ id: pid, field: 'isActive', value: 'N'});
	example_ajax_request('buysell/my_property.php');
}

function loadPreview() {	
	var profileId = $("#profileId").val();
	$("#previewWindow").load("mbuysell_preview.html?pid="+profileId);	
}


function addPeriod() {
	var profileId = $("#profileId").val();
	var fromDate = $("#periodFrom").val();
	var toDate = $("#periodTo").val();
	var price = $("#periodPrice").val();
	var type = $("#periodType").val();
	if (profileId && fromDate && toDate && price) {
		$.post("mbuysell_periodAdd.html",{pid: profileId, from: fromDate, to: toDate, price: price, type: type},function() {
			loadPeriodList();
		var fromDate = $("#periodFrom").val('');
		var toDate = $("#periodTo").val('');
		var price = $("#periodPrice").val('');
		});
	}
}

function removePeriod(id) {
	var profileId = $("#profileId").val();
	$.post("mbuysell_periodDelete.html",{pid: profileId, id: id},function() {
		loadPeriodList();
	});
}


function loadPeriodList() {
	$("#periodListBox").html('<center><img src="http://cdn.urbytus.net/images/jsonLoader.gif" /></center>');
	var profileId = $("#profileId").val();
	$("#periodListBox").load("mbuysell_period_list.html?pid="+profileId);
}


function changeSaleTick() {
	var isTicked = $("#saleTick").attr("rel");
	switch(isTicked) {
		case 'Y':
			updatePropertyProfile('isSale','N');
			$("#saleTick").attr("rel",'N');
			$("#saleTick").attr("src",'http://cdn.urbytus.net/_icons/ocm/green_untick.png');
			$("#saleBox").css("display","none");
		break;
		case 'N':
			updatePropertyProfile('isSale','Y');
			$("#saleTick").attr("rel",'Y');
			$("#saleTick").attr("src",'http://cdn.urbytus.net/_icons/ocm/green_tick.png');
			$("#saleBox").css("display","");
		break;
	}
}


function changeRentTick() {
	var isTicked = $("#rentTick").attr("rel");
	switch(isTicked) {
		case 'Y':
			updatePropertyProfile('isRent','N');
			$("#rentTick").attr("rel",'N');
			$("#rentTick").attr("src",'http://cdn.urbytus.net/_icons/ocm/green_untick.png');
			evalRentBox();
		break;
		case 'N':
			updatePropertyProfile('isRent','Y');
			$("#rentTick").attr("rel",'Y');
			$("#rentTick").attr("src",'http://cdn.urbytus.net/_icons/ocm/green_tick.png');
			evalRentBox();
		break;
	}
}


function changeRoomTick() {
	var isTicked = $("#roomTick").attr("rel");
	switch(isTicked) {
		case 'Y':
			updatePropertyProfile('isRentRoom','N');
			$("#roomTick").attr("rel",'N');
			$("#roomTick").attr("src",'http://cdn.urbytus.net/_icons/ocm/green_untick.png');
			evalRentBox();
		break;
		case 'N':
			updatePropertyProfile('isRentRoom','Y');
			$("#roomTick").attr("rel",'Y');
			$("#roomTick").attr("src",'http://cdn.urbytus.net/_icons/ocm/green_tick.png');
			evalRentBox();
		break;
	}
}

function evalRentBox() {
	var isRentTick = $("#rentTick").attr("rel");
	var isRentRoomTick = $("#roomTick").attr("rel");
	if (isRentTick == 'Y' || isRentRoomTick == 'Y') {
		$("#rentBox").css("display","");
	} else {
		$("#rentBox").css("display","none");
	}
}

function showHideAgent() {
	var isCheck = $("#showAgentInfo").val();
	switch (isCheck) {
	
	case 'Y':
		$("#showAgentInfo").val("N");
		$("#showAgentInfo").attr('checked','');
		$("#showHideAgent").css("display","none");
		updatePropertyProfile('showAgentInfo','N');
	break;
	
	case 'N':
		$("#showAgentInfo").val("Y");
		$("#showAgentInfo").attr('checked','checked');
		$("#showHideAgent").css("display","");
		updatePropertyProfile('showAgentInfo','Y');
	break;
	
	} 
}

function buySellContact(thisItem) {
	var isValid = validateThis(thisItem);
	if (isValid) {
	var profileId = $("#profileId").val();
	var name = $("#buysellName").val();
	var email = $("#buysellEmail").val();
	var tel = $("#buysellTel").val();
	var message = $("#buysellMessage").val();
	$("#buySellContact").html('<center><br /><br /><img src="http://cdn.urbytus.net/images/jsonLoader.gif" /></center>');
		$.post("mbuysell_contact.html",{pid: profileId, name: name, tel: tel, email: email, message: message},function(res) {
			$("#buySellContact").html(res);
		});
		}
}


function buysellSmsNotif() {
	var isCheck = $("#smsNotif").val();
	switch (isCheck) {
		case 'Y':
			$("#smsNotif").val("N");
			$("#smsNotif").attr('checked','');
			updatePropertyProfile('smsNotif','N');
		break;
		case 'N':
			$("#smsNotif").val("Y");
			$("#smsNotif").attr('checked','checked');
			updatePropertyProfile('smsNotif','Y');
		break;	
	}
}
