//修改标题
function updateTit(photoID,photoSort, titvalue) 
{
	/*
	var req=new XMLHttpRequest();
	if (req) 
	{
    		req.onreadystatechange=function()
    		{
    			if (req.readyState==4 && req.status==200) 
			{
			}
		}
	}
	var act= document.getElementById("path").value+"/AjaxCtrl";
	req.open('POST', act);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send("page=UpdatePhotoTitlePage&photoID="+photoID+"&title="+titvalue);
	*/
	var pars = 'do=photo_modify_title&id=' + photoID + '&sort=' + photoSort + '&title=' + encodeURI(titvalue);
	//alert(pars);
	var myajax=new Ajax.Request("http://www.tuniu.com/main.php",{method:'get',parameters:pars,onComplete:showresult});
}

function showresult(ajax)
{
	var result=ajax.responseText;
	//alert(result);

	$("hidTit").value=result;
	//alert(result);
	$("tit").innerHTML="<div id='tit' onclick='initTit("+$('hidId').value+");' style='width: 500px' onmouseover='ch(this);' onmouseout='res(this);'><h1>"+result.replace(/</g,"&lt;").replace(/>/g,"&gt;")+"</h1></div>";

}


function initTit(photoID)
{
	var tit=$("tit");
	tit.onclick="";
	tit.onmouseover="";
	tit.innerHTML="<input type='text' id='titTxt' class='highlight' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 500px' value='"+$('hidTit').value+"'><br><input type='button' class='button' value='保存' onclick='getTit("+photoID+");' class='butt'>&nbsp;&nbsp;<input type='button' class='button' value='取消' onclick='resetTitHTML("+photoID+");' class='cancelbutt'>";
}

function getTit(photoID)
{
	var tit=$('titTxt');
	var titvalue=tit.value;
	var photoSort = $("photoSort").value;
	if(titvalue.length>120)
		{
				alert("标题字数太多！ 请重新输入。");
				return ;
		}
	if(titvalue.length==0)
		{
				alert("标题字数太少！ 请重新输入。");
				return ;
		}
	var str=titvalue.replace(/(^\s*)|(\s*$)/g, '').replace(/</g,"&lt;").replace(/>/g,"&gt;");
	if(str.length==0)
		{
				alert("标题字数太少！ 请重新输入。");
				return ;
		}
	$('tit').innerHTML="正在保存........";

	updateTit(photoID,photoSort, titvalue);
	//$("hidTit"+idx).value=titvalue;
	//tit.innerHTML="<div id='sp"+idx+"' onclick='initTit("+idx+","+photoID+");' style='width: 500px' onmouseover='ch(this);' onmouseout='res(this);'><h1>"+titvalue.replace(/</g,"&lt;").replace(/>/g,"&gt;")+"</h1></div>";

}

function resetTitHTML(photoID)
{
	var tit=$("tit");
	tit.innerHTML="<div id='tit' onclick='initTit("+photoID+");' onmouseover='ch(this);' onmouseout='res(this);'><h1>"+$('hidTit').value.replace(/</g,"&lt;").replace(/>/g,"&gt;")+"</h1></div>";
}

function ch(activeX)
{
	activeX.style.background="#ffc";
}

function res(activeX)
{
	activeX.style.background="#fff";
}
