﻿//獲取下類列表
function getAreaResult(keyid,parentid)
{
	AjaxPro.AjaxMethod.getTypeList(keyid,
	function(response)
	{
		if (response.value != null)
		{
　　　　	var ds = response.value;
			if(ds != null && typeof(ds) == "object" && ds.Tables != null)
			{     
				$("dropArea").length=0; 
				$("dropArea").options.add(new Option("無資料",-1));
				if($F("dropCity")==-1) return;        
				for(var i=0; i<ds.Tables[0].Rows.length; i++)
　　　　		{
　　　　			$("dropArea").options.add(new Option(ds.Tables[0].Rows[i].TypeName,ds.Tables[0].Rows[i].KeyId));
　　　　　		}
　　　　　		//selected
　　　　　		for(var i=0;i<$("dropArea").length;i++)
　　　　　		{
　　　　　			if($("dropArea").options[i].value==parentid)
　　　　　			{
　　　　　				$("dropArea").options[i].selected = true;
　　　　　			}
　　　　　		}
			}
		}                
		return
	});
}
//上傳圖片
function uploadpic(cid)
{
    var url = '../../UploadPicture.aspx?controlname=' + cid + '&path=' + document.getElementById(cid).value; //转向网页的地址;
	var name='upload';//网页名称，可为空;
	var iWidth=380;//弹出窗口的宽度;
	var iHeight=130;//弹出窗口的高度;
	var iTop = (window.screen.availHeight-30-iHeight)/2;//获得窗口的垂直位置;
	var iLeft = (window.screen.availWidth-10-iWidth)/2;//获得窗口的水平位置;
	
	var winobj = window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no, status=yes');
	winobj.focus();
	return false;
}
//上傳視頻
function uploadmedia(cid)
{
    var url = '../../UploadMedia.aspx?controlname=' + cid + '&path=' + document.getElementById(cid).value; //转向网页的地址;
	var name='upload';//网页名称，可为空;
	var iWidth=380;//弹出窗口的宽度;
	var iHeight=130;//弹出窗口的高度;
	var iTop = (window.screen.availHeight-30-iHeight)/2;//获得窗口的垂直位置;
	var iLeft = (window.screen.availWidth-10-iWidth)/2;//获得窗口的水平位置;
	
	var winobj = window.open(url,name,'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no, status=yes');
	winobj.focus();
}
var g_i=0;
var maxcount=6;//最大插入數目
//插入一行
function addPic()
{
	if(maxcount==0) return;
	var tbl = $("tblPictureList");
	if(tbl != null)
	{	
		var newRow = tbl.insertRow();
		var rowId = "row" + g_i;
		newRow.id = rowId;
		
		var newCell1 = newRow.insertCell();
		newCell1.innerHTML = "<input id=\"piclist"+g_i+"\" name=\"piclist\" type=\"text\" size=\"50\" class=\"box1\" onmouseover=\"this.className='box2'\"  onmouseout=\"this.className='box1'\">";
		newCell1.innerHTML += "&nbsp;<input type=\"button\" value=\"上傳圖片\" class=\"btnNormal\" onclick=\"javascript:uploadpic('piclist"+g_i+"')\">&nbsp;<input type=\"button\" value=\"刪除\" class=\"btnNormal\" onclick=\"javascript:delPic('tblPictureList',this)\">";
		
		g_i++;
		maxcount--;
	}
}

//刪除一行
function delPic(Pobj,Psrc)
{
	if(!confirm("真的刪除嗎？")) return false;
	var tbl = $(Pobj);
	if(tbl != null)
	{
		tbl.deleteRow(Psrc.parentElement.parentElement.rowIndex);
		maxcount++;		
	}
	return false;
}

//插入列表
function loadPiclist(piclist)
{
	if(piclist=="") return;
	if(maxcount==0) return;
	var tbl = $("tblPictureList");
	if(tbl != null)
	{	
		var list = piclist.split(",");
		for(var i=0;i<list.length;i++)
		{
			var newRow = tbl.insertRow();
			var rowId = "row" + g_i;
			newRow.id = rowId;
			
			var newCell1 = newRow.insertCell();
			newCell1.innerHTML = "<input id=\"piclist"+g_i+"\" name=\"piclist\" type=\"text\" value=\""+list[i]+"\" size=\"50\" class=\"box1\" onmouseover=\"this.className='box2'\"  onmouseout=\"this.className='box1'\">";
			newCell1.innerHTML += "&nbsp;<input type=\"button\" value=\"上傳圖片\" class=\"btnNormal\" onclick=\"javascript:uploadpic('piclist"+g_i+"')\">&nbsp;<input type=\"button\" value=\"刪除\" class=\"btnNormal\" onclick=\"javascript:delPic('tblPictureList',this)\">";
			
			g_i++;
			maxcount--;
		}
	}
}

//數據驗證
function onSubmitCheck()
{								
	//樓盤名稱
	if($F("txtTitle")=="")
	{
		alert("請輸入標題！");
		$("txtTitle").focus();
		return false;
	}
	//車位面積
	if($F("txtBuildingArea")!="")
	{
		if(!checknumfloat($F("txtBuildingArea"),2))
		{
			alert("車位面積輸入錯誤！")
			$("txtBuildingArea").focus();
			return false;
		}
	}
	//使用期限
	if($F("txtUseTerm")!="")
	{
		if(!checknumfloat($F("txtUseTerm"),2))
		{
			alert("使用期限輸入錯誤！")
			$("txtUseTerm").focus();
			return false;
		}
	}
	//要求售價
	if($F("txtSalePrice")!="")
	{
		if(!checknumfloat($F("txtSalePrice"),3))
		{
			alert("售價輸入錯誤！")
			$("txtSalePrice").focus();
			return false;
		}
	}				
	//要求租金
	if($F("txtRentPrice")!="")
	{
		if(!checknumfloat($F("txtRentPrice"),3))
		{
			alert("租金輸入錯誤！")
			$("txtRentPrice").focus();
			return false;
		}
    }
    //聯絡人
    if ($F("txtLinkName") == "") {
        alert("聯絡人不能為空.！")
        $("txtLinkName").focus();
        return false;
    }
    //聯絡電話/手機號碼
    if ($F("txtLinkPhone") == "" && $F("txtLinkMobile") == "") {
        alert("聯絡電話/手機號碼不能都為空，必須選擇其中一個填寫.")
        $("txtLinkPhone").focus();
        return false;
    }
	//保存圖片
	for(var i=0;i<document.getElementsByName("piclist").length;i++)
	{
		if($F("hidPicture")!="") $("hidPicture").value += ",";
		$("hidPicture").value += document.getElementsByName("piclist")[i].value;
	}
	return true;
}