/*
	var ieVer = parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE ")+5, navigator.appVersion.length));
	//var isIE6 = ieVer >= 6.0;
	if(ieVer < 5.5){
		if(confirm("Dear user, your Internet Explorer must be updated for better browsing of our website.\n\r Do you want to update your IE or to install its latest version?")){
			window.open("http://www.microsoft.com/windows/ie/ie6/worldwide/ie6sp1downloads.mspx");
		}
	}
*/

var saveing = "Being saved!";
var saveSuccess = "Saved!";
var debug = true;

function windowOpen(url){
	window.open(url,"photoDetailWin");
}
function MM_jumpMenu(targ,selObj,url){ //v3.0
	eval(targ+".location='"+url+selObj.options[selObj.selectedIndex].value+"'");
	//if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenu_bak(targ,selObj,url){ //v3.0
	eval(targ+".location='"+url+selObj.options[selObj.selectedIndex].value+"'");
	//if (restore) selObj.selectedIndex=0;
}
var boolen = true;
function diplayDiv(tipName)
{
	boolen = !boolen;
	if (boolen)
	{
		$(tipName).style.display='none';
	}else
	{
		$(tipName).style.display = "";
	}
}


/**
*-----------------------------------
* limit page
* @para url string
*-----------------------------------
*/
function search_List()
{
	window.location = 'index.php?action=member&attribute=getAllMember&like='+$('username').value+$('order').value;
}





function photoView_setClass(id)
{
	for (var i=0;i<3;i++)
	{
		if (id==1)
		{
			$('photos'+i).className="selected";
		}else
		{
			$('photos'+i).className="";
		}
	}
}
/**
Category->
**/
if (navigator.appName == 'Netscape')
{
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = netscapeMouseMove;
}

function netscapeMouseMove(e) {
	if (e.screenX != xx && e.screenY != yy)
	{
		xx = e.screenX;
		yy = e.screenY;
	}
}

function micro() {
	if (window.event.x != xx && window.event.y != yy)
	{
		xx = window.event.x;
		yy = window.event.y;
	}
}
//设置鼠标坐标
var xx = 0;
var yy = 0;

var boolTip = false;
var callID;
function showTipBox(tipName,bool)
{
	boolTip = bool;
	if (!boolTip)
	{
		document.getElementById(tipName).className =  'tipBoxOut';

		//callID = setInterval('setClassName('+tipName+')',1000);
	}else
	{
	//alert(document.getElementById(tipName).clientWidth)
		document.getElementById(tipName).className =  'tipBoxClick';
	//document.getElementById(tipName).style.left = xx-document.getElementById(tipName).style.width;
	//document.getElementById(tipName).style.top = yy-document.getElementById(tipName).style.height;
	}
}
function setClassName_visible(tipName)
{
	document.getElementById(tipName).className =  'tipBoxOut';

}
function setClassName(tipName)
{
	window.setTimeout('setClassName_visible('+tipName+')',1000);
}
//按照名称获取对象,支持IE/FIREFOX/等等
function fetch_object(idname, forcefetch) {
	if (forcefetch || typeof(objects[idname]) == "undefined") {
		switch (domType) {
			case "std": {
				objects[idname] = document.getElementById(idname);
			}
			break;

			case "ie4": {
				objects[idname] = document.all[idname];
			}
			break;

			case "ns4": {
				objects[idname] = document.layers[idname];
			}
			break;
		}
	}
	return objects[idname];
}

function changeSets(albumid,userid,order)
{
	if(albumid==-1)
	{
		window.location ='?action=manage&attribute=sets&userid='+userid+'&sort=creat_time';
	}else
	{
		window.location = '?action=category&attribute=album_photos&albumid='+albumid+'&userid='+userid+'&order='+order;
	}
}
function GoToPage(url){
	//alert(document.getElementById('gopage').value);
	location.href= url+$('gopage').value;
}
function isShow(tipName,boolen)
{
	if (boolen)
	{
		document.getElementById(tipName).className="hide";
	}else
	{
		document.getElementById(tipName).className="show";
	}
}
function test(str,uid)
{
	window.location='?action=picture&attribute=slide&id='+str+"&userid="+uid;
}

function changeNewWin_Slide(str,uid)
{
	window.location='?action=picture&attribute=slide_newWin&id='+str+"&userid="+uid;
}
function displayUser(uid,username,userico)
{

	$('whoUser').innerHTML='<a href="?action=manage&attribute=home&userid='+uid+'">'+username+'\'s photos</a><br />';
	$('userIco').innerHTML= "<img src="+userico+" width='42' height='42' />";
}





function Goto(str)
{
	window.location=str;
}

function topPhoto(address)
{
	window.location = "?action=picture&attribute=topPhotos&albumid="+address;
}


/**
*-----------------------------------
* update sets ($tip=div)
*-----------------------------------
*"ajaxAPI.php?action=manage&attribute=updateSets"
*/
function updata(fromName,tipName,url)
{

	//setVisible(tipName);
	//$(tipName).innerHTML = saveing;
	new Ajax.Request(url, {
		parameters:Form.serialize(fromName),
		onSuccess:function(request)
		{

			var __msg = getTipText(request);
			InlinePopup.popupDialog(__msg,{
				width:400,
				popupClass:'s-tabcolor',
				okButtonClass:'s-button',
				okButton: 'Ok',
				type: 'message'
			});

			//$(tipName).innerHTML = getTipText(request);
		}
	});


}

function updataStats(url,sid)
{
	var arr;
	var temp = ['s1','s2','s3'];
	new Ajax.Request(url, {
		onSuccess:function(request)
		{

			arr = request.responseText.split("|");
			$("total").innerHTML = arr[0];
			$("month").innerHTML = arr[1];
			$("week").innerHTML = arr[2];
			$("today").innerHTML = arr[3];
			for (var i=0;i<temp.length;i++)
			{

				if (sid==temp[i])
				{
					document.getElementById(sid).className="stats_bold";
				}else
				{
					document.getElementById(temp[i]).className='stats';
				}
			}


		}
	});
}

function updateSets(){


	var regex= /^[a-zA-Z0-9]{1,8}/;
	if($('title').value==''){
		alert('Please input the set title!');
		$('title').focus();
		return false;
	}
	//alert(document.getElementById('privilege')[0]);
	//alert($('save').privilege[2].value);
	if($('save').privilege[2].checked){
		if($('password').value==''){
			alert('Please create a password');
			$('password').focus();
			return false;
		}
		if ( !regex.test($('password').value)) {
			alert("Password: 1~8 letters and numbers only");
			$('password').focus();
			return false;
		}
		if($('password').value.length>8){
			alert('Password: 1~8 letters and numbers only');
			return false;
		}

	}
	//$('oldtitle').value = $('title').value;
	updata('save','tip','ajaxAPI.php?action=manage&attribute=updateSets');

	//$('oldtitle').value = $('title').value;


}
/**
*-----------------------------------
* get tip text
*-----------------------------------
*/

function sortJump(str)
{
	window.location="?action=category&attribute=cate_albums&cateid="+$('category').value+str;
}


function getTipText(request)
{
	if (debug)
	{
		return request.responseText;
	}else
	{
		return saveSuccess;
	}
}

function tipText(tipName,tipText)
{
	setVisible(tipName);
	$(tipName).innerHTML = tipText;
}

function changeCoverPhoto(conver)
{
	//	alert(conver);
	updateCover(conver,'cover','ajaxAPI.php?action=manage&attribute=changeCoverPhoto');
}

function updateCover(fromName,tipName,url)
{
	//setVisible(tipName);
	//组装URL
	var photoAdd= $(fromName+"photoAdd").value;
	var photoID= $(fromName+"photoID").value;
	var albumID= $(fromName+"albumID").value;
	var list  = "&photoAdd="+photoAdd+"&photoID="+photoID+"&albumID="+albumID;
	$(tipName).innerHTML = 'Changing now...';
	new Ajax.Request(url+list, {
		parameters:Form.serialize(fromName),
		onSuccess:function(request)
		{
			$(tipName).innerHTML = request.responseText;
		}
	});
}
/**
*-----------------------------------
* call function to flash
*-----------------------------------
*/
/*
function callExternalInterface() {
thisMovie("slide").goHome();
//	alert(thisMovie("slide"));
}

function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
}
else {
return document[movieName];
}
}


*/

function delPhoto(albid)
{
	if(confirm("Delete the photo?"))
	{
		window.location="?action=picture&attribute=deletePhoto&id="+albid;
	}
}
function deletePhoto(albid)
{
	if(confirm("Delete the photo?"))
	{
		window.location="?action=picture&attribute=deletePhoto&id="+albid+"&location=myphotos";
	}
}

function delSets(albid)
{
	if(confirm("Are you sure you want to delete this photo set? \n \r Once deleted, it is irretrievable.")){
		window.location = '?action=manage&attribute=deleteSets&id='+albid;
	}
}

function displayDelete(str)
{
	if(confirm("delete these photos"))
	{
		window.location="?action=picture&attribute=deletePhoto&id="+str;
	}
}


function menuJump(fromName,tipName,url)
{

	$(tipName).innerHTML = '<select disabled><option>Waiting..</option></select>';
	new Ajax.Request(url, {
		parameters:Form.serialize(fromName),
		onSuccess:function(request)
		{
			$(tipName).innerHTML = request.responseText;

		}
	});
}





function updatePhoto()
{
	if($('photoName').value=="")
	{
		alert("please input you title");

		return false;
	}
	if ($('album_id').value=="-1")
	{
		alert("please select this photo's set");

		return false;
	}

	//-updata('picEditForm','tip','ajaxAPI.php?action=picture&attribute=edit_save');

	var fromName="picEditForm";
	var tipName="tip";
	var url="ajaxAPI.php?action=picture&attribute=edit_save";
	new Ajax.Request(url, {
		parameters:Form.serialize(fromName),
		onSuccess:function(request)
		{
			history.back(-1);
		}
	});



	$('div_cate').className = "";

}





function publicMode()
{

	$('onlyMe').disabled="disabled";
	$('havePass').disabled="disabled";
	$('password').disabled="disabled";
	$('password').value="";
}

function privateMode()
{

	$('onlyMe').disabled= !$('onlyMe').disabled;
	$('havePass').disabled=!$('havePass').disabled;

	$('password').value="";
}

function passWordMode()
{
	$('password').disabled=!$('password').disabled;
}

function onlyMe()
{
	$('password').disabled=true;
	$('password').value="";
}
function HiddenPasswordDiv(){
	$("PasswordDiv").style.display = 'none';
}
function DisplayPasswordDiv(){
	$("PasswordDiv").style.display = 'block';
}
function HiddenLogoPositionDiv(){
	$("LogoPositionDiv").style.display = 'none';
}
function DisplayLogoPositionDiv(){
	$("LogoPositionDiv").style.display = 'block';
}
/**
*-----------------------------------
* set visible div
*-----------------------------------
*/
function setVisible(str)
{
	document.getElementById(str).style.visibility="visible";//
}


function set_private_mode()
{

	//$('have_pass').disabled=true;
	//$('password').checked=false;
	//$('have_pass').checked=false;
	$('password').disabled=true;
	//$('password').value="";
}
function set_public_mode()
{
	$('password').value="";
	//$('have_pass').disabled=false;
}
function set_pass()
{
	$('password').disabled = !$('password').disabled;
	$('password').value="";
}


function chooseSets()
{

	if ($('album_id').value=="-1")
	{

		$('dijiao').disabled=true;
	}else
	{
		$('dijiao').disabled=false;
	}
}


function sortSets(str,uid)
{
	window.location = '?action=manage&attribute=sets&page='+$('gopage').value+str+"&userid="+uid;
}

function createSets()
{
	var regex= /^[a-zA-Z0-9]{1,8}/;
	var updataResult='';
	if ($('title').value=="")
	{
		alert('Please input the set title');
		$('title').focus();
		return false;

	}
	if($('category').value=="-1")
	{
		alert('Please select a category');
		$('category').focus();
		return false;
	}

	if($('form1').privilege[2].checked){
		if($('password').value==''){
			alert('Please create a password');
			$('password').focus();
			return false;
		}
		if ( !regex.test($('password').value)) {
			alert("Password: 1~8 letters and numbers only");
			$('password').focus();
			return false;
		}
		if($('password').value.length>8){
			alert('Password: 1~8 letters and numbers only');
			return false;
		}

	}

	new Ajax.Request('ajaxAPI.php?action=manage&attribute=addNewSets', {
		parameters:Form.serialize('form1'),
		onSuccess:function(request)
		{

			var albumid =getTipText(request);
			var __msg='';
			if(albumid=='-1'){
				__msg = "The set name exists!Please input another set name!";
			}else{
				__msg = "The set has been created.<br> go to upload photo(s)."
			}
			InlinePopup.popupDialog(__msg,{
				width:400,
				popupClass:'s-tabcolor',
				okButtonClass:'s-button',
				okButton: 'Ok',
				type: 'message'
			});


			if(albumid >0){
				window.setTimeout("Goto('index.php?action=manage&attribute=upload&albumid="+albumid+"')", 2000);
			}
		}
	});

}

function closewindow(id,op,topid){
	$(id).style.display= "none";
	$(op).innerHTML="<img src='"+imageUrl+"images/open.gif\' onclick=\"openwindow('"+id+"','"+op+"','"+topid+"');\">";
	$(topid).style.height=20;
}
function openwindow(id,op,topid){
	$(id).style.display= "block";
	$(op).innerHTML="<img src='"+imageUrl+"images/close.gif' onclick=\"closewindow('"+id+"','"+op+"','"+topid+"');\">";
	$(topid).style.height=42;
}

function saveChangeMode(){
	var regex= /^[a-zA-Z0-9]{1,8}/;
	if($('changeMode').privilege[2].checked){
		if($('password').value==''){
			alert('Please create a password');
			$('password').focus();
			return false;
		}
		if ( !regex.test($('password').value)) {
			alert("Password: 1~8 letters and numbers only");
			$('password').focus();
			return false;
		}
		if($('password').value.length>8){
			alert('Password: 1~8 letters and numbers only');
			return false;
		}

	}
	updata('changeMode','tip','ajaxAPI.php?action=picture&attribute=changeMode');

}

function goback(){
	history.go(-1);
}

function sub_string(all_str,add_str,str_num)
{
	var endIndex,SubString,temp='';
	endIndex=all_str.indexOf(str_num);// 找到位置
	startIndex=all_str.indexOf("return=");
	
	SubString=all_str.substring(0,endIndex);

	temp+=SubString+add_str;
	temp+=all_str.substring(endIndex,all_str.length);

	return temp;
}

function Remember(){
	var action;
	if($("remember").checked==true){
		action =sub_string($('signInForm').action,"%3Fremember%3D1","&msg");
		//alert(action);
		$("signInForm").action = action;//alert($("signInForm").action);
		$("signInForm").submit();
	}
	//return false;
}
function copyToClipboard(txt) {
	if(window.clipboardData)
	{
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
		alert('copied!');
	}
	else if(navigator.userAgent.indexOf("Opera") != -1)
	{
		window.location = txt;
	}
	else if (window.netscape)
	{
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}
		catch (e)
		{
			alert("!!被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip)
		return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans)
		return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = txt;
		str.data = copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip)
		return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	return true;
}
function ye()
{
	var dd=0;
	dd=getCookie("closeList");

	//alert(dd);
	if(dd!=1){
		$('toppop').style.display='block';
		//Effect.Highlight('toppop',{duration:1.5});
		//new Effect.SlideDown('toppop11',{duration:1.0});
		
		//$("div.toppop").slideDown(2000);
	}

}
function ye2()
{
	setCookie("closeList",1);
	$('toppop').style.display='none';
	//new Effect.SlideUp('toppop',{duration:1.0});

}
function setCookie(Key,value){
	var today = new Date();
	var expireDay = new Date();
	var msPerMonth = 24*60*60*1000*31;
	expireDay.setTime( today.getTime() + msPerMonth );
	document.cookie = Key + "=" + value + ";expires=" + expireDay.toGMTString();
}

function getCookie(Key){
	var search = Key + "=";
	begin = document.cookie.indexOf(search);
	
	if (begin != -1) {
	  begin += search.length;
	  end = document.cookie.indexOf(";",begin);
	  if (end == -1) end = document.cookie.length;
	 return document.cookie.substring(begin,end);
	
	}
} 