/**
** 计算当前行数
**/
//得到第一条记录得开始
var urlList = ['but_0_0','but_1_0','but_2_0','but_3_0','but_4_0','but_5_0','but_6_0'];
var urlListBak = ['?action=picture&attribute=view&id=','?action=picture&attribute=view&id=','?action=manage&attribute=sets_view&sortID=uploadtime&sortID=uploadtime&id=','?action=picture&attribute=view&id=','?action=picture&attribute=view&id=','?action=manage&attribute=sets_view&sortID=uploadtime&id=','?action=picture&attribute=view&id='];

function getStartLine(clipName,numQuotiety)
{

	return Number(document.getElementById(clipName).value)+numQuotiety;
}
//得到结束记录得ID
function getEndLine(clipName,numQuotiety)
{
	return getStartLine(clipName,numQuotiety)+3;
}

var clickOne = true;
var selectOne = true;
/**
** 改变图片
*/
function ph_changePhoto(clipName_bak,url,num)
{
	//分割方式1,5
	//获取服务器信息
	//第一个信息



	var numQuotiety = num;
	//操作CLIP得名称
	var clipName = clipName_bak;



	//起始位置
	var startLine = getStartLine(clipName,numQuotiety);
	//结束位置
	var endLine = getEndLine(clipName,numQuotiety);
	if (clipName=="but_1_0")
	{
		//alert('endLine='+startLine+"\nendLine="+endLine);
	}
	//alert('endLine='+startLine+"\nendLine="+endLine);
	//检测
	if (startLine<-1)
	{
		document.getElementById(clipName).value=-1;
	}

	if (startLine>=0)
	{


		new Ajax.Request(url+"&startline="+startLine+"&endline="+endLine+"&userid="+$('uid').value, {
			onSuccess:function(request)
			{
				document.getElementById(clipName).value=startLine;

				praseXML(request.responseText.split('|'),clipName,numQuotiety);
			}
		});
	}
}

function initLine(clipName)
{

	if (clickOne)
	{
		//拆分clickID
		var urlPara = $('clickID').value;
		var urlParaList = urlPara.split('*');
		if (urlParaList!='')
		{
			document.getElementById(clipName).value = Number(urlParaList[urlParaList.length-1])-Number(urlParaList[1])-1;
		}else
		{
			document.getElementById(clipName).value = -1;
		}
	}
	clickOne= false;
}

/*
*改变当前位置
*/

function praseXML(list,clipName,numQuotiety,startLine,endLine)
{
	if (clipName=='but_1_0')
	{
		//alert(list);
	}
	var tempxx = -1;
	for (var i=0;i<3;i++)
	{
		var photo = list[i].split('*');


		//initSelected(clipName,photo[0],i);
		if (photo[0]=="" || photo[0] =="undefined")
		{

			if(i==0)
			{
				$(clipName+'_'+i).innerHTML = "<img src='"+imageUrl+"images/common/first.gif' >";
			}else
			{
			$(clipName+'_'+i).innerHTML = "<img src='"+imageUrl+"images/common/final.gif' >";
			}
			document.getElementById(clipName+"_"+i).className="PhotoBox";
			$(clipName+'_next').disabled=true;
		}else
		{
			//开启向下按钮
			if (i==2)
			{
				$(clipName+'_next').disabled=false;

			}

			var thisURL = getLink(photo);
			if ($('formMySets').value==1)
			{
				var thisURL = "?action=picture&attribute=view&id=";
			}else
			{
				var thisURL = getLink(clipName);
			}
			//error

			if(thisURL.indexOf('sets_view')<0)
			{
				if (clipName=='but_1_0' && $('formMySets').value==0)
				{
					if (photo[0]==photoURL[2] && photo[0]!="")
					{

						document.getElementById(clipName+'_'+i).className="selectDiv";

					}else
					{
						document.getElementById(clipName+"_"+i).className="PhotoBox";
					}
				}

				if ($('formMySets').value==1)
				{

					var len = photo[photo.length-1];

					if (photo.length>3 || photo[i]=="")
					{
						len=i;
					}
					$(clipName+'_'+i).innerHTML = "<a href=?action=picture&attribute=view&id="+photo[0]+" title='"+photo[photo.length-1]+"' id='img_"+i+"' name='img_"+i+"'><img height=75 width=75 src="+photo[1]+" ></a>";
				}else
				{

					/*tempxx++
					if (clipName=="but_1_0" && photo[photo.length-1]==0 && tempxx==1)
					{
					var len =1;
					}else
					{
					if (clipName=="but_1_0")
					{
					var len = photo[photo.length-1];
					}else
					{
					var len = photo[photo.length-1];
					}
					}*/

					var len =photo[photo.length-1];
					if (clipName=="but_1_0")
					{
						
						if(Number(photo[photo.length-1])==0 && i==0)
						{
						
							$('but_1_0').disabled=true;
						}else if (i==0)
						{
							$('but_1_0').disabled=false;
						}

						var len=photo[photo.length-1];
						$('but_1_0_'+i).divID = len;
						if (photo[0]==$('pid').value)
						{
							$('but_1_0_'+i).className="selectDiv";
						}else
						{
							$('but_1_0_'+i).className="PhotoBox";
						}
						if (i==1)
						{
							
							$(clipName).value = len;
						}
						$(clipName+'_'+i).innerHTML = "<a href="+getLink(clipName)+photo[0]+"&startline="+len+"><img height=75 width=75 src="+photo[1]+" title='"+photo[2]+"' ></a>";
					}else
					{
						$(clipName+'_'+i).innerHTML = "<a href="+getLink(clipName)+photo[0]+" title='"+photo[photo.length-1]+"' id='img_"+i+"' name='img_"+i+"'><img height=75 width=75 src="+photo[1]+" ></a>";
					}
				}
			}else
			{
				//alert("title="+photo[photo.length-2]+"\ni="+i+"\nphoto.length="+photo.length);
				
				$(clipName+'_'+i).innerHTML = "<a href="+getLink(clipName)+photo[0]+"&userid="+photo[2]+" title=\"title: "+photo[photo.length-2]+"\nphotos: "+photo[photo.length-1]+"\" id='img_"+i+"' name='img_"+i+"'><img height=75 width=75 src="+photo[1]+" ></a>";
			}
		}

	}
}





function initSelected(clipName,id,i)
{

	var photo = $('clickID').value.split('*');

	if (photo[2]==id)
	{
		document.getElementById("but_1_0_"+photo[1]).className="selectDiv";
	}else
	{
		document.getElementById("but_1_0_"+i).className="PhotoBox";
	}
}



/**
* 计算在数据库中得位置。。。。
*/

function statsDataBase()
{

}


function autoBuild()
{
}

function getLink(clipName)
{
	for(var i=0;i<urlList.length;i++)
	{
		if (urlList[i]==clipName)
		{
			return urlListBak[i];
		}
	}
}

function getDivValue()
{
	var temp= "";
	return document.getElementById(clipName+"_0").value;
}