
var domainName = "www.120ask.com";
var domainIp="60.28.160.203";
var isLogined = checkusercookies();
function $(id){return document.getElementById(id);}
function iframeAutoFit(iframeObj){
	setTimeout(function(){if(!iframeObj) return;iframeObj.height=(iframeObj.Document?iframeObj.Document.body.scrollHeight:iframeObj.contentDocument.body.offsetHeight);},200)
}
function changeDisabled(o){o.disabled = !o.disabled;}
function setActionOnTheseName(objN,f){	var i,ins; os=document.getElementsByName(objN); for(i=0;i<os.length;i++) f(os[i]);}
function LEN(str){
    var i,sum=0;
    for(i=0;i<str.length;i++){
        if((str.charCodeAt(i)>=0) && (str.charCodeAt(i)<=255))
            sum=sum+1;
        else
            sum=sum+2;
    }
    return sum;
}
function checkusercookies(){
	var cstr,name,pos,start,end,temp,i;
	cstr = document.cookie.replace(/\s/ig,"");
	temp = (cstr.length - cstr.replace(/ask1user1userid=/ig,"").length)/16;
	name = "ask1user1userid=";
	for(i=0;i<temp;i++){
		var pos = cstr.indexOf(name,cstr.indexOf(name)*i+15*i);
		if(-1!=pos){
			start = pos + name.length;
			end = cstr.indexOf(";",start);
			if(-1==end) end = cstr.length;
			if(""!=cstr.substring(start,end)) return true;
		}
	}
	return false;
}
function TRIM(value){return value.replace(/^\s*/,'').replace(/\s*$/,''); }
function checkC(c){return /^[0-9]+$/.test(c);}
function imgAutoFit(imgObj,maxWidth,maxHeight){
	var heightWidth;
	var widthHeight;
	heightWidth = imgObj.offsetHeight/imgObj.offsetWidth;
	widthHeight = imgObj.offsetWidth/imgObj.offsetHeight;
	if(imgObj.offsetWidth>maxWidth){
		imgObj.width = maxWidth;
		imgObj.height = maxWidth*heightWidth;
	}
	if(imgObj.offsetHeight>maxHeight){
		imgObj.height = maxHeight;
		imgObj.width = maxHeight*widthHeight;
	}
} 
function checkTagIsHave(s,t){
	var re=new RegExp("<\\/?"+t+"(?:(?:\\s|\\/)(?:\\n|.)*?)?>","ig");
	var r=re.test(s);
	re=null;
	return r;
}

function imgUploadFit(){
	var u = document.getElementsByName("imgUploadName");
	if(0==u.length) return;
	for(var i=0;i<u.length;i++){
		//imgAutoFit(u[i],560,560);
		imgAutoFit(u[i],320,320);
		u[i].onclick = function(){window.open(this.src);}
		u[i].style.cursor = "pointer";
		u[i].title = "点击看原图";
	}
}

function inputContent(theQ,oldContent,re,p){
	var o,oA=["msgframeamend","pingJiaFrame","touSuFrame"];
	for(o in oA){
		if($(oA[o])){
			theQ.editIframe(oA[o]);
			if("msgframeamend"==oA[o]) setTimeout(function(){$(oA[o]).contentWindow.document.body.innerHTML = oldContent.replace(re,"")+p[1];},100);
			return;
		}
	}
}

function checkCommon(n,v,t){
	var s = t?"补充提问":"回复内容";
	var o=document.getElementById(n).contentWindow;
	if("msgframereply" == n){
		if(v == ""){
			alert("请填写"+s+" !");
			o.focus();
			return false;
		}
	}
	if(""==v.replace(/<\/*?(?:img|p|pre|br)(?:(?:\s|\/)(?:\n|.)*?)?>|\s|&nbsp;/ig,"")&&checkTagIsHave(v,"img")){
		alert("针对图片，请附上一些说明性的文字！");
		o.focus();
		return false;
	}
	if(10000<LEN(v)){
		alert(s+"超过5000字数限制 !");
		o.focus();
		return false;
	}
	return true;
}

//20091016
function attach_onload(o){
	imgAutoFit(o,320,320);
	o.onclick = function(){window.open(o.src);}
	o.style.cursor = "pointer";
	o.title = "点击看原图";
}