﻿// JavaScript Document

function GetObj(objName){
 if(document.getElementById){
  return eval('document.getElementById("' + objName + '")');
 }else if(document.layers){
  return eval("document.layers['" + objName +"']");
 }else{
  return eval('document.all.' + objName);
 }
}

// 图片上传专用
function getImageUpCookie(Name) {
	var search = Name + "=";
	if(document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if(offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if(end == -1) end = document.cookie.length;
			return document.cookie.substring(offset, end);
		} else return "";
	}
}
//返回指定iframe的document
function getIFrameDocument(aID) {
    var rv = null;
    if (document.getElementById(aID).contentWindow.document){
        // if contentDocument exists, W3C compliant (Mozilla)
        rv = document.getElementById(aID).contentWindow.document;
    } else {
        // IE
        rv = document.frames[aID].document;
    }
    return rv;
}
 
function GetElementFromIFrame(frameId,elementId) {
    var iDocument = getIFrameDocument(frameId);
    //接下来就可以进行类似的DOM操作了
    var elementObj = iDocument.getElementById(elementId);
    return elementObj;
}
function setCookie(cookieName,cookieValue){        //设置cookie值
    var expires = new Date((new Date()).getTime()+24*60*60*1000);
    //var cookies=cookieName+"="+escape(cookieValue)+";path=/;expires="+(expires).toGMTString();
    var cookies=cookieName+"="+cookieValue+";path=/;expires="+(expires).toGMTString();
    cookies+=";domain=foloda.com";            
    document.cookie=cookies;
}


// 房源发布专用验证
function BrokerPubValidator(ddlids, ddlerror, radlids, radlerror, txtids, txterror, txtnumid, txtnumerror, cn, clubid, clubname, agreeId){
	try{
		var isOk = true;
		var focusobj = null;
		var msg = "";
		var errorCount = 1;
		// 验证社区
		var cid = document.getElementById(clubid);
		if(cid==null || cid==undefined || cid.value < 1) {
			msg += (errorCount + "、小区名称为必填项\r\n");
			if(focusobj == null) focusobj = GetObj(clubname);
			isOk = false;
			errorCount++;
//			alert('请选择小区');
//			try{
//				GetObj(clubname).focus();
//			}catch(e){}
//			return false;
		}
		
		// 验证下拉列表
		if(ddlids){
			for(var i = 0; i < ddlids.split(',').length; i++){
				var ops = [];
				var opsObj = GetObj(ddlids.split(',')[i]);
				ops = GetObj(ddlids.split(',')[i]).options;
				if(ops.item(0).selected){
					msg += (errorCount + "、" + ddlerror.split('^')[i] + "\r\n");
					if(focusobj == null) focusobj = opsObj;
					isOk = false;
					errorCount++;
//					alert(ddlerror.split('^')[i]);
//					try{
//						opsObj.focus();
//					}catch(e){}
//					return false;
				}
			}
		}
		
		// 验证单选列表
		if(radlids){
			for(var i = 0; i < radlids.split(',').length; i++){
				var radls = [];
				var radlObj = GetObj(radlids.split(',')[i]);
				
				var isAllNoCheck = true;
				for(var j = 0; j < radlObj.getElementsByTagName("input").length; j++){
					if(radlObj.getElementsByTagName("input")[j].checked){
						isAllNoCheck = false;
					}
				}
				if(isAllNoCheck){
					msg += (errorCount + "、" + radlerror.split('^')[i] + "\r\n");
					if(focusobj == null) focusobj = radlObj.getElementsByTagName("input")[0];
					isOk = false;
					errorCount++;
//					alert(radlerror.split('^')[i]);
//					radlObj.getElementsByTagName("input")[0].focus();
//					return false;
				}
			}
		}
		
		// 文本框必填
		if(txtids){
			for(var i = 0; i < txtids.split(',').length; i++){
				var txtObj = GetObj(txtids.split(',')[i]);
				if(Trim(txtObj.value) == ""){
					msg += (errorCount + "、" + txterror.split('^')[i] + "\r\n");
					if(focusobj == null) focusobj = txtObj;
					isOk = false;
					errorCount++;
//					alert(txterror.split('^')[i]);
//					txtObj.focus();
//					return false;
				}
			}
		}
		
		//验证是否为数字
		if(txtnumid){
//		    var valid = new Valid();
			for(var i = 0; i < txtnumid.split(',').length; i++){
				var txtObj = GetObj(txtnumid.split(',')[i]);
				if(!Valid.validNum(Trim(txtObj.value))){
					msg += (errorCount + "、" + txtnumerror.split('^')[i] + "\r\n");
					if(focusobj == null) focusobj = txtObj;
					isOk = false;
					errorCount++;
				}
			}
		}

		// 验证室内图标题
		//var str = getImageUpCookie(cn);
		var str = GetElementFromIFrame('ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ContentPlaceHolder1_uploadImageHouse_frame','hidImageData').value;
		if(str != null && str != ''){
			if(str.split('&').length == 3){
				var ids = str.split('&')[0].replace('ids=', '');
				var titles = decodeURI(str.split('&')[1].replace('titles=', ''));
				var arrTitle=titles.split('|');var isSuccess=true;
				for(var i = 0; i < arrTitle.length; i++){
					if(arrTitle[i] == '' || arrTitle[i] == '无标题' || arrTitle[i].replace(/[+]/g,"")==''){	
						msg += (errorCount + "、室内照片描述为必填项\r\n");
						if(focusobj == null) focusobj = GetObj('imageupt');
						isOk = false;isSuccess=false;
						errorCount++;
//						alert('室内照片描述必填');
//						GetObj('imageupt').focus();
//						return false;
					}
				}
			}else{
				alert('室内照片数据异常，请重新发布/编辑房源');
				return false;
			}
		}
		if(isSuccess) { setCookie(cn,(str));}

//        ///修改人： 笪元峰
//		///时间： 20090521
//		///内容：新的图片标题验证		
//		var str=document.getElementById("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_ContentPlaceHolder1_hid").value;
//		//var str1=getImageUpCookie(cn);
//		//var ids = str1.split('&')[0].replace('ids=', '');
//		if(str != null && str != ''){
//			    isOk=GetImgTitle();
//				var titles = decodeURI(str);
//				for(var i = 0; i < titles.split('|').length; i++){
//					if(titles.split('|')[i] == '' || titles.split('|')[i] == '无标题' || titles.split('|')[i] == '照片描述最多16个中文字'){
//						msg += (errorCount + "、室内照片描述为必填项\r\n");
//						if(focusobj == null) focusobj = GetObj('imageupt');
//						isOk = false;
//						errorCount++;
//					}
//				}
//			
//		}else{
//				msg += (errorCount + "、室内照片描述为必填项\r\n");
//				if(focusobj == null) focusobj = GetObj('imageupt');
//				isOk = false;
//				errorCount++;
//		}
//	    //修改结束	
	    		
		// 是否接受协议
		if(!GetObj(agreeId).checked){
			msg += (errorCount + "、只有接受条款才能发布\r\n");
			if(focusobj == null) focusobj = GetObj(agreeId);
			isOk = false;
			errorCount++;
//			alert('只有接受条款才能发布。');
//			GetObj(agreeId).focus();
//			return false;
		}//else{
//			return true;
//		}
		if(isOk){
			return true;
		}else{
			alert(msg);
			focusobj.focus();
			return false;
		}
	}catch(e){
		alert('验证异常，请重新发布/编辑房源');
		return false;
	}
}
function PublishValidator(ddlids, ddlerror, radId, radId1, radId2, agreeId){
	for(var i = 0; i < ddlids.split(',').length; i++){
		var ops = [];
		ops = GetObj(ddlids.split(',')[i]).options;
		if(ops.item(0).selected){
			alert(ddlerror.split('^')[i]);
			try{
			ops.focus();
			}catch(e){}
			return false;
		}
	}
	
	if(radId != ''){
		var isAllNoCheck = true;
		for(var i = 0; i< GetObj(radId).getElementsByTagName("input").length; i++){
			if(GetObj(radId).getElementsByTagName("input")[i].checked){
				isAllNoCheck = false;
			}
		}
		if(isAllNoCheck){
			alert('租赁方式必须选择。');
			GetObj(radId).getElementsByTagName("input")[0].focus();
			return false;
		}
	}
	
	if(radId1 != ''){
		var isAllNoCheck = true;
		for(var i = 0; i< GetObj(radId1).getElementsByTagName("input").length; i++){
			if(GetObj(radId1).getElementsByTagName("input")[i].checked){
				isAllNoCheck = false;
			}
		}
		if(isAllNoCheck){
			alert('装修程度必须选择。');
			GetObj(radId1).getElementsByTagName("input")[0].focus();
			return false;
		}
	}
	
	if(radId2 != ''){
		var isAllNoCheck = true;
		for(var i = 0; i< GetObj(radId2).getElementsByTagName("input").length; i++){
			if(GetObj(radId2).getElementsByTagName("input")[i].checked){
				isAllNoCheck = false;
			}
		}
		if(isAllNoCheck){
			alert('房屋类型必须选择。');
			GetObj(radId2).getElementsByTagName("input")[0].focus();
			return false;
		}
	}
	
//	if(GetObj('codeid').innerHTML != "true")
//	{
//	    alert('验证码不正确');
//	    return false;
//	}
	if(!GetObj(agreeId).checked){
		alert('只有接受条款才能发布。');
		GetObj(agreeId).focus();
		return false;
	}else{
		return true;
	}
}

function ItemOver(id)
{
	if(GetObj(id).className == "cur")
		{return}
	
	GetObj(id).className = "on";

}
function ItemOut(id)
{
	if(GetObj(id).className == "cur")
		{return}
		
	GetObj(id).className = "";

}
function ItemSelect(obj, id)
{
	if(GetObj("houselist").childNodes.length>0)
	{
		for(var i=0;i<GetObj("houselist").childNodes.length;i++)
		{
			if(GetObj("houselist").childNodes[i].className == "cur" && GetObj("houselist").childNodes[i].id!=id)
			{
				GetObj("houselist").childNodes[i].className = "";
				var liId = GetObj("houselist").childNodes[i].id;
				var dObj = GetObj("dck"+liId);
				dObj.innerHTML = "展开";
				dObj.parentNode.className = "br optcss btn1";
			}
		}
	}

	if(GetObj(id).className == "cur")
	{
		GetObj(id).className = "on";
		GetObj("d"+obj.id).innerHTML = "展开";
		GetObj("d"+obj.id).parentNode.className = "br optcss btn1";
	}
	else
	{
		GetObj(id).className = "cur";
		GetObj("d"+obj.id).innerHTML = "收回";
		GetObj("d"+obj.id).parentNode.className = "br optcss btn2";
	}

}
var lastOpenPanel = "";
function ItemSelect0(obj, id)
{
	if(lastOpenPanel != '' && lastOpenPanel != id){
		var lopObj = GetObj(lastOpenPanel);
		if(lopObj != null && lopObj.className == "cur"){
			lopObj.className = "on";
		}
	}
	if(GetObj(id).className == "cur")
	{
		GetObj(id).className = "on";
	}
	else
	{
		GetObj(id).className = "cur";
		lastOpenPanel = id;
	}

}

function DisplayCollapse(titleobj, contentid)
{
	var obj = GetObj(contentid);
	if(obj!=null)
	{
		if(obj.style.display=="none") {
			titleobj.className = "collapsetitle boldbluelabel";
//			alert(obj.style.height);
//			obj.style.display = "block";
		}
		else {
			titleobj.className = "collapsetitleon boldbluelabel";
//			obj.style.display = "none";
		}
	}
}

function ShowDiv(contentid){
	var obj = GetObj(contentid);
	obj.style.display = "block";
}

function HiddenDiv(contentid){
	var obj = GetObj(contentid);
	obj.style.display = "none";
}

function ShowObj(obj){
	obj.style.display = "none";
}

function HiddDiv(obj){
	obj.style.display = "none";
}

function ClearText(obj){
	obj.value = "";
	obj.style.color = "#000";
}

// JScript File


SCROLL_ACCEL = 10; //滑动的加速度 1-100有效
SCROLL_TIME = 300; //滑动时间(毫秒)

//判断浏览器
o_navigator = navigator.userAgent;
var isIE = (o_navigator.indexOf("MSIE") > -1) ? 1 : 0;
var isIE5 = (o_navigator.indexOf("MSIE 5") > -1) ? 1 : 0;
var isMac = (o_navigator.indexOf("Mac") > -1) ? 1 : 0;
var isOpera = (o_navigator.indexOf("Opera") > -1) ? 1 : 0;
var isIE50 = (o_navigator.indexOf("MSIE 5.0") > -1) ? 1 : 0;
var isIE55 = (o_navigator.indexOf("MSIE 5.5") > -1) ? 1 : 0;
var isIE6 = (o_navigator.indexOf("MSIE 6.0") > -1) ? 1 : 0;
var isNN6 = (o_navigator.indexOf("Netscape6") > -1) ? 1 : 0;
var isFirefox = (o_navigator.indexOf("Firefox") > -1) ? 1 : 0;
var isDOM = (document.getElementById) ? 1 : 0;
//isIE = (isIE && !isOpera);

var objDiv;
var Scroller = function(){
/*	var startTime,startHeight,endHeight,dist,accel;
	var aniTimer;*/
	aDiv	:	null;
}

Scroller.show = function(){
	with(this.aDiv){
		
		this.startTime = (new Date()).getTime();
		this.startHeight = 0;
		this.endHeight = scrollHeight;
		
		this.dist = this.endHeight;
		this.accel = this.dist / SCROLL_TIME / SCROLL_TIME;
		if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer);
		this.aniTimer = window.setInterval("Scroller.slide()", parseInt(100/SCROLL_ACCEL));
	}
}

Scroller.hide = function(){
	with(this.aDiv){
		this.startTime = (new Date()).getTime();
		this.startHeight = scrollHeight;
		this.endHeight = 0;
		this.dist = -this.startHeight;
		this.accel = this.dist / SCROLL_TIME / SCROLL_TIME;
		if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer);
		this.aniTimer = window.setInterval("Scroller.slide()", parseInt(100/SCROLL_ACCEL));
	}
}

Scroller.slide = function(){
	with(this){
		var now = (new Date()).getTime();
		var elapsed = now - startTime;
		if (elapsed > SCROLL_TIME) endScroll();
		else {
			var t = SCROLL_TIME - elapsed;
			var ny = endHeight - t * t * accel;
			jumpTo(ny);
		}
	}
}

Scroller.jumpTo = function(ny){
	var alpha = Math.abs(parseInt(ny*100/this.dist));
	
	with(this.aDiv){
		style.height = ny+'px';
		scrollTop = ny;
		if(isIE){
		    filters.alpha.opacity = alpha;}
		else{
		    style.opacity = alpha;
		}
	}
}

Scroller.endScroll = function() {
	if (this.aniTimer) this.aniTimer = window.clearTimeout(this.aniTimer);
	with(this.aDiv){
		style.overflowY="";
		style.height = "";
		if(this.endHeight==0){
			style.display = "none";
			//filters.alpha.opacity = 0;
		}
		//else{
		if(isIE){
		    filters.alpha.opacity = 100;}
		else{
		    style.opacity = 100;
		}
		//}
	}
}

function TransNodeImg(imgObj){
    var objIcon;
    objIcon = imgObj;
	switch (objIcon.className)
	{
	    case "collapsetitleon boldbluelabel":
	    objIcon.className = "collapsetitle boldbluelabel";
	    break;
	    case "collapsetitle boldbluelabel":
	    objIcon.className = "collapsetitleon boldbluelabel";
	    break;
	}
	
	var bObj;
	for(var i = 0; i<objIcon.childNodes.length; i++){
		if(objIcon.childNodes[i].nodeName.toLowerCase() == "b"){
			bObj = objIcon.childNodes[i];
			break;
		}
	}
	if(bObj != null){
		switch (bObj.className)
		{
			case "up":
			bObj.className = "down";
			break;case "down":
			bObj.className = "up";
			break;
		}
	}
	//alert(oldSrc);
}

function NodeExpand(obj){
//    if(obj.getElementsByTagName("b")!=null && obj.getElementsByTagName("b").length>0)
//        TransNodeImg(obj.getElementsByTagName("b")[0]);
	TransNodeImg(obj);

	objDiv = getNextSibling(obj);
	if(objDiv){
		if(objDiv.style.display =='block'){
			if(isIE || isFirefox){
				objDiv.style.overflowY="hidden";
				Scroller.aDiv = objDiv;
				Scroller.hide();
			}
			else{
				objDiv.style.display = "none";
			}
		}
		else{
			if(isIE || isFirefox){
				objDiv.style.display = 'block';
				if(isIE){
		            objDiv.filters.alpha.opacity = 100;}
		        else{
		            objDiv.style.opacity = 100;
		        }
				objDiv.style.overflowY="hidden";
				objDiv.style.height=0;
				Scroller.aDiv = objDiv;
				Scroller.show();
			}
			else{
			
				objDiv.style.display = "block";
			}
		}
	}
}

function getNextSibling(startBrother){
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}




function Checkbox1_onclick(sender,textId,title) {
var textBox=GetObj(textId);
var ss,s;
s = textBox.value;
s= s.replace("，",",");
ss = s.split(",");
if(sender.checked){
	var flag=false;
	for(var a = 0; a < ss.length; a++){
		if(title==ss[a]){
			flag=true;
			break;
		}
	}
	if(!flag){
		textBox.value = textBox.value + title + ",";
	}
}else{
	var tempv = "";
	for(var a = 0; a < ss.length-1 ;a++){
		if(title != ss[a]){
			tempv = tempv + ss[a] + ","
		}
	}
	textBox.value = tempv;
}
}

function CheckNeedBid(obj, cid1, cid2){
	if(obj.checked){
		GetObj('bidpannel').style.display = 'block';
//		GetObj(cid1).checked = true;
//		GetObj(cid2).checked = true;
	}else{
		GetObj('bidpannel').style.display = 'none';
//		GetObj(cid1).checked = false;
//		GetObj(cid2).checked = false;
	}
}
var nav4 = window.Event ? true : false;

function modifiers(e) {
  if (nav4) { 
     document.keys.alt.checked = e.modifiers & Event.ALT_MASK;
     document.keys.control.checked = e.modifiers & Event.CONTROL_MASK;
     document.keys.shift.checked = e.modifiers & Event.SHIFT_MASK;
     document.keys.meta.checked = e.modifiers & Event.META_MASK;
  } else {
     document.keys.alt.checked = window.event.altKey;
     document.keys.control.checked = window.event.ctrlKey;
     document.keys.shift.checked = window.event.shiftKey;
     document.keys.meta.checked = false;
  }
  return false;
}
function ChromaticEgg(objid, cobj){
	var src = '/App_Themes/Default/defaultimg/error.gif';
	var obj = GetObj(objid);
	if(window.event.ctrlKey & window.event.altKey){
		cobj.src = '/App_Themes/Default/defaultimg/errorsmile.jpg';
		obj.style.display = 'block';
	}else if(cobj.src.indexOf('errorsmile.jpg') > 0){
		cobj.src = src;
		obj.style.display = 'none';
	}
}

function toggleItem(o) {
	o.style.display  = ((o.style.display == 'none') ? 'block' : 'none');
}

function IsTitleValid(s){
	var isOk = false;
	if(s.length < 4 | s.lenght > 25){
		alert("标题长度应该介于4到25之间。");
		isOk = false;
	}else{
		isOk = true;
	}
	return isOk;
}
function ValidCode(pageKey, valueId)
{   
    var value = GetObj(valueId).value;  
    var strpost = "{'pageKey':'"+pageKey+"','value':'"+value+"'}";
    var ajaxV = new Ajax(null,null,"/WebService/WsValid.asmx/ValidCode",2,strpost,function(rexm){ValidCodeSuccessCallBack(rexm)});
    ajaxV.post();
}

function ValidCodeSuccessCallBack(rexm){
    var data = eval("(" + rexm + ")");
    
    if(data == false)
    {
        GetObj('codeid').innerHTML = false;  
    }
    else
    {
        GetObj('codeid').innerHTML = true;  
    }
}

//20091225 朱轲 添加 验证是否为数字
var Valid={};
Valid.validNum=function(num) {
    var result=true;
    if(num){
        var myReg = new RegExp("^(-?\\d+)(\\.\\d+)?$");//数字验证
        result = myReg.test(num);
    }
    return result;
}