// ﻿base web site url
// var lavaurl="http://202.152.181.134/";

var url = window.location.href;
var lavaurl = url.substring(0, url.indexOf('/', 7)+1);


// ??????
function DoRequestAndUpdate(target, surl, params)
{
    var url = lavaurl + surl;
    var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: params, evalScripts: true});
}

// ??????mμ??
function DoFormSubmitAndUpdate(fname, target, surl)
{
	//var f = $(fname);
	//if(!f) f = document.forms[fname];
    var url = lavaurl + surl;
	var params = Form.serialize(fname);	
    var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: params, evalScripts: true});
}

// call ajax update
function ajax_update(target, surl, params)
{
    var url = lavaurl + surl;
	
    var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: params, evalScripts: true});
}

// call ajax form update
function ajax_form_update(fname, target, surl)
{
	//var f = $(fname);
	//if(!f) f = document.forms[fname];
    var url = lavaurl + surl;
	var params = Form.serialize(fname);	
    var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: params, evalScripts: true});
}

function do_lava_login(){
	if($('curl').value=='')
		$('curl').value = window.location.href;
	if ($('lavaid')) {
		lid = $F('lavaid')
		if( lid.trim() == '' ){
			alert('请输入您的Lava-Lava号码或e-mail地址登录。')
			return false;
		}
		ps = $F('pass');
		if (ps.trim() == '' ){
			alert('请输入密码登录。')
			return false;
		}
		$('md5pass').value = MD5( ps );
	}
	return true;
}

function do_lava_logout(pThis){
	var f = document.forms['idlogin']; 
	if(!f) f = $('idlogin'); 
	$('curl').value = window.location.href;
	f.submit(); 
	return false; 
}

function DrawImage(ImgD,width,height)
{
	var image=new Image();
	var iwidth = width; //定义允许图片宽度
	var iheight = height; //定义允许图片高度
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		if(Image.width/image.height>= iwidth/iheight){
			if(image.width>iwidth){
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}else{
			if(image.height>iheight){
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}
		ImgD.alt=image.width+"×"+image.height;
	}
} 

function TopicOpenImage(e){
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
}

function TopicDrawImage(ImgD){
	DrawImage(ImgD, 500, 300);
	ImgD.onclick = TopicOpenImage;
	ImgD.style.cursor="Hand";
	s = "<a href='"+ ImgD.src +"' rel='lightbox' >" + ImgD.outerHTML +"</a>";
	ImgD.outerHTML = s;
}
function fanserrimg(e)
{
	if (e.errhandled) return;
	e.errhandled = true;
	e.src="/image/lava/0.jpg";
}
function tribeerrimg(e)
{
	if (e.errhandled) return;
	e.errhandled = true;
	e.src="/image/tribe/0.gif";
}

function tagerrimg(e)
{
	if (e.errhandled) return;
	e.errhandled = true;
	e.src="/images/tribe/pic-8.gif";
}

function setCopy(_sTxt)
{
	try{
		//alert('clipboardData');
		clipboardData.setData('Text',_sTxt);
	}catch(e){
		alert(e.message);
	}
}

function setHome()
{
	try{
		//alert('AddFavorite');
		window.external.AddFavorite(window.document.location,window.document.title || window.document.location);
	}catch(e){
		alert(e.message);
	}
}

function setHomepage(el)
{
	try{
		el.style.behavior='url(#default#homepage)';
		el.sethomepage(window.document.location);
		return false;
		//window.document.links[0].style.behavior= 'url(#default#homepage)'); 
		//window.document.links[0].setHomePage(window.document.location);
	}catch(e){
	}
}

function inputfocus(e,s){
	var str=e.value;
	if (str.trim()==s)
	{
		e.style.color= "#000000";
		e.value="";
	}
	return true;
}

function inputblur(e,s){
	var str=e.value;
	if (str.trim()=="")
	{
		e.style.color= "#c0c0c0";
		e.value=s;
	}
	return true;
}

function imgchange(e,img1){
	if (e)
	{
		e.src=img1;
		return true;
	}
}

/*
	for vote
	@divid : the return html to display. but will auto contact the obj id as the really id
	@otype : the object type, must be : topic || topicview || tribe
			 if vote at topic list page, otype = topic, 
			 if vote at topic view page, otype= topicview ,
			 if vote tribe then otype = tribe
	@oid   : the object id, such as topic id or tribe id
*/
function voteup(divid, otype, oid){ ajax_update(divid+oid,'vote/digup/'+otype+'/'+oid);}
function votedown(divid, otype, oid){ ajax_update(divid+oid,'vote/digdown/'+otype+'/'+oid);}

/*
	for vote check
	only logined user can do vote.
*/
function alertnotlogin(){ alert('您需要登录后参与顶拍。如果还没有注册，您可以免费注册一个Lava-Lava号码。'); }
