var URLPREFIX = 'http://www.skyalbum.com.hk/';
var URLPREFIXIMAGE = 'http://www.skyalbum.com.hk/img/';
var URLPREFIXCART = 'https://www.skyalbum.com.hk/';
var URL= URLPREFIX+'album.sortimageorder';
var originalSequence_1 = "";
var originalSequence_2 = "";

function funAlbumCheck(TheForm,radAction,btnSubmit,username,methodUsed){

	var totalChecked = 0;
	var emptyAlbum = 0;
	var checkedItem  ="";
	var folderId = "";
	var intHasAlbum=0;

		if (!(radAction)){
			emptyAlbum=1;
			totalChecked =1;
		}
		else if (!(radAction.length)){
			emptyAlbum=1;
			totalChecked =1;
		}
		else{
			for (var i=0;i<radAction.length;i++){
				if (radAction[i].checked){
					folderId = radAction[i].value;
					for (key in folder){
						if (folder[key] ==folderId){
							checkedItem = key;
							break;
						}
					}
					totalChecked++;
				}
			}
		}

	if ((totalChecked==0) && (btnSubmit=="Detach")){
		alert(headerDisplay[24]);
	}
	else if ((totalChecked==0) && (btnSubmit=="Delete")){
		alert(headerDisplay[25]);
	}
	else if ((totalChecked==0) && (btnSubmit!="Create") && (btnSubmit!="Order") && (btnSubmit!="Previous") && (btnSubmit!="Next") && (btnSubmit != "SetSorting") && (btnSubmit != "ViewBy") && (btnSubmit!="ViewByReorder") ){
		alert(headerDisplay[8]);
	}
	else if ((emptyAlbum==1) && (btnSubmit!="Create")  && (btnSubmit!="Order") && (btnSubmit!="Previous") && (btnSubmit!="Next" && (btnSubmit!="ViewBy") && (btnSubmit!="ViewByReorder") && (btnSubmit!="button"))){
		alert(headerDisplay[9]);
	}
	else{
		switch (btnSubmit){
			case "Create":
				TheForm.action =URLPREFIX+'album.new';
				TheForm.submit();
				break;
			case "Delete":
			if (folderGroupKey[checkedItem]==1){
				if (confirm(headerDisplay[10])){
					TheForm.action =URLPREFIX+'album.delete';
					TheForm.submit();
				}
			}
			else{
				if(memberNameWithFID[folderId] == undefined){
					if (confirm(headerDisplay[16])){
						TheForm.action = URLPREFIX+"album.group.detach";
						TheForm.submit();
					}
				}
				else{
					if (confirm(headerDisplay[19])){
						TheForm.action = URLPREFIX+"album.group.detach";
						TheForm.submit();
					}
				}
			}
				break;
			case "Edit":
				if (username ==ownerName[checkedItem]){
					TheForm.action =URLPREFIX+'album.edit';
					TheForm.submit();
				}
				else{
					alert(headerDisplay[12]);
				}
				break;
			case "Invite":
				if (username ==ownerName[checkedItem]){
					TheForm.action = URLPREFIX+"album.group";
					TheForm.submit();
				}
				else{
					alert(headerDisplay[15]);
				}
				break;
			case "Detach":

				if (folderGroupKey[checkedItem]==1){
					alert(headerDisplay[17]);
				}else{
					if(isOwner[folderId] == 0){
						if (confirm(headerDisplay[39])){
							TheForm.action = URLPREFIX+"album.group.detach";
							TheForm.submit();
						}
					}else if(!memberName[checkedItem]){
						if (confirm(headerDisplay[16])){
							TheForm.action = URLPREFIX+"album.group.detach";
							TheForm.submit();
						}
					}else{
						if (confirm(headerDisplay[19])){
							TheForm.action = URLPREFIX+"album.group.detach";
							TheForm.submit();
						}
					}
				}
				break;
			case "Upload":
				if (navigator.javaEnabled()){TheForm.action = URLPREFIX+"upload.advance";}
				else {TheForm.action = URLPREFIX+"upload";}
				TheForm.submit();
				break;
			case "Share":

				TheForm.action =URLPREFIX+'album.share';
				TheForm.submit();
				break;
			case "Order":
				TheForm.action = URLPREFIXCART+'cart.order';
				TheForm.submit();
				break;
			case "Same":
				if(methodUsed == "album"){
					document.body.style.overflow = "hidden";
				    document.getElementById('blackLayer').style.top = 0;
			    	document.getElementById('blackLayer').style.left = document.body.scrollLeft;
				    document.getElementById('blackLayer').style.width = document.body.clientWidth;
			    	document.getElementById('blackLayer').style.height = document.body.scrollHeight;
					($('blackLayer')).style.visibility = "visible";
					if(IE){
						($('SCselect')).style.visibility = "hidden";
						($('viewBy')).style.visibility = "hidden";
					}
					($("waitingProcess")).style.left = (document.body.clientWidth-300)/2;
					($("waitingProcess")).style.top = document.body.scrollTop+(document.body.clientHeight/2)-50;
					($('waitingProcess')).style.visibility="visible";
					($('waitingProcess')).style.display="inline";

					setTimeout("addAlbumImage()", 500);
				}
				break;
			case "cancelChange":
				TheForm.method = "POST";
				TheForm.submit();
				break;
			case "ViewBy":
				var sortBox = document.getElementById('sortBox');
				TheForm.sortFolder.value = sortBox.options[sortBox.selectedIndex].value;
				TheForm.method = "POST";
				TheForm.submit();
				break;
			case "ViewByReorder":
				var sortBox = document.getElementById('sortBox2');

				TheForm.sortFolder.value = sortBox.options[sortBox.selectedIndex].value;
				TheForm.method = "POST";
				TheForm.submit();
				break;
		}
	}
}

function changeDisplaySetting(intDisplaySetting){
	if (document.getElementById('detachAlbum') && document.getElementById('deleteAlbum')){
		if (intDisplaySetting == 1){
			document.getElementById('detachAlbum').className='noneDisplay';
			document.getElementById('detachAlbum1').className='noneDisplay';
			document.getElementById('deleteAlbum').className='inlineDisplay';
			document.getElementById('deleteAlbum1').className='inlineDisplay';
			document.getElementById('deleteAlbumHeight').style.height='22';
			document.getElementById('detachAlbumHeight').style.height='0';
		}
		else{
			document.getElementById('detachAlbum').className='inlineDisplay';
			document.getElementById('detachAlbum1').className='inlineDisplay';
			document.getElementById('deleteAlbum').className='noneDisplay';
			document.getElementById('deleteAlbum1').className='noneDisplay';
			document.getElementById('deleteAlbumHeight').style.height='0';
			document.getElementById('detachAlbumHeight').style.height='21';
		}
	}
}

var currentX,currentY;
var IE = document.all?true:false;
if (!IE) {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousedown = getMouseXY;

function getMouseXY(e){
	if (IE) {
		currentX = event.clientX + document.body.scrollLeft;
		currentY = event.clientY + document.body.scrollTop;
	}
	else
	{
		currentX = e.pageX;
		currentY = e.pageY;
	}
	(currentX<0)?0:currentX;
	(currentY<0)?0:currentY;
}

function showDetail(detailNum,colorPattern){
	var strMemberList="";
	var strMemberHTML="";
	var strAlbumImage="";
	var folderDESCDetail="";
	var printRight = "";

	detailNum = (detailNum>0)?detailNum:0;
	var i;

	if (!memberName[detailNum]){
		strMemberHTML="";
	}
	else{
		strMemberListName=memberName[detailNum];
		strMemberHTML ="<tr><td valign=\"top\" ><div align=\"left\">"+headerDisplay[6]+"</div></td>"+
        "<td valign=\"top\" ><div align=\"left\">"+strMemberListName+"</div></td></tr>";
	}
	if (detailNum > 0){

    	currentX = (currentX>410)?currentX-280-185:currentX;
	}
if (IE) {
  document.getElementById('showAlbumDetail').style.left = currentX+90;
  document.getElementById('showAlbumDetail').style.top = currentY-215;
}
else{
  document.getElementById('showAlbumDetail').style.left = currentX+90;
  document.getElementById('showAlbumDetail').style.top = currentY-215;
}
  if (folderTotalImage[detailNum]==0){
	  strAlbumImage = headerDisplay[20];
  }
  else{
	strAlbumImage = folderTotalImage[detailNum]+headerDisplay[1];
  }

  if (folderDesc[detailNum]!=""){
  		folderDESCDetail = "<tr>"+
			"<td valign=\"top\" ><div align=\"right\">"+headerDisplay[22]+":</div></td>"+
			"<td colspan=\"2\" valign=\"top\" ><div align=\"left\">"+folderDesc[detailNum]+"</div></td>"+
	        "</tr>";
    }

	document.getElementById('showAlbumDetail').innerHTML=
"<table width=\"100%\"   border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\" width:280px; height:115px; z-index:1; left: 38px; top: 326px; visibility: visible;border:0px solid #000000;\" class=\"imgDetail\">"+
"<tr><td><table width=\"100%\" border=\"0\"  cellpadding=\"0\" cellspacing=\"0\"  class=\"ToolPanel2\"><tr>"+
"<td width=\"100%\" height=\"25\" class=\"title\"><table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
" <tr>"+
"<td width=\"91%\" height=\"24\" valign=\"bottom\"><strong>&nbsp;&nbsp;"+headerDisplay[23]+"</strong></td>"+
"<td width=\"9%\" valign=\"bottom\"><div align=\"right\"><div id=\"close\" ><div class=\"light\"><strong><img src=\""+URLPREFIXIMAGE+"Icon/cancel.gif\" width=\"16\" height=\"16\" onClick=\"javascript:reStoreDetail();\" class=\"btncursor\"></strong>&nbsp;</div></div></div></td>"+
"</tr>"+
"</table></td>"+
"</tr>"+
"<tr>"+
"<td height=\"*%\"  class=\"IFOcell\"><img src=\""+URLPREFIXIMAGE+"default/spacer/tspacer.gif\" ><br>"+
"<table width=\"95%\" border=\"0\"  align=\"center\" cellpadding=\"2\">"+
"<tr>"+
"<td  width=\"30%\"><div align=\"right\">"+headerDisplay[21]+": </div></td>"+
"<td colspan=\"2\"  ><div align=\"left\">"+folderName[detailNum]+"</div></td>"+
"</tr>"+folderDESCDetail+
"<tr><td  width=\"40%\"><div align=\"right\"><nobr>"+headerDisplay[0]+": </div></td>"+
"<td width=\"60%\"  ><div align=\"left\">"+strAlbumImage+"</div></td>"+
"</tr>"+
"<tr><td ><div align=\"right\">"+headerDisplay[2]+": </div></td>"+
"<td  ><div align=\"left\">"+calculateFileSize(folderSize[detailNum])+" </div></td>"+
"</tr>"+
"<tr><td  ><div align=\"right\">"+headerDisplay[3]+": </div></td>"+
"<td  ><div align=\"left\">"+folderLastUpdate[detailNum]+"</div></td>"+
"</tr>"+
"<tr><td  ><div align=\"right\">"+headerDisplay[4]+": </div></td>"+
"<td  ><div align=\"left\">"+folderGroup[detailNum]+"</div></td>"+
"</tr>"+
"<tr><td  ><div align=\"right\">"+headerDisplay[5]+": </div></td>"+
"<td  ><div align=\"left\">"+folderRights[detailNum]+"</div></td></tr>"+
"<tr><td  ><div align=\"right\">"+headerDisplay[26]+": </div></td>"+
"<td  ><div align=\"left\">"+printRights[detailNum]+"</div></td>"+
"</tr>"+
"<tr><td  ><div align=\"right\">"+headerDisplay[11]+": </div></td>"+
"<td ><div align=\"left\">"+ownerName[detailNum]+"</div></td></tr>"+
"</table>"+
"</td>"+
"</tr>"+
"<tr>"+
"<td height=\"*%\"  class=\"IFO\"><img src=\""+URLPREFIXIMAGE+"default/spacer/tspacer.gif\" ><br>"+
"</tr>"+
"</table></td></tr></table>";
}


function reStoreDetail(){
	document.getElementById('showAlbumDetail').innerHTML="";
}

function calculateFileSize(PictureFileSize){
	if (Math.round(PictureFileSize/1024/1024/1024)>0){
		return roundNumberToDecimal(PictureFileSize/1024/1024/1024,2) +" GB";
	}
	else if (Math.round(PictureFileSize/1024/1024)>0){
		return roundNumberToDecimal(PictureFileSize/1024/1024,2) +" MB";
	}
	else if (Math.round(PictureFileSize/1024)>0){
		return roundNumberToDecimal(PictureFileSize/1024,1) +" KB";
	}
	else if (PictureFileSize){
		return PictureFileSize + " B";
	}

}

function roundNumberToDecimal(number, decimal) {
	return  Math.round(number*Math.pow(10,decimal))/Math.pow(10,decimal);

}

function checkItem(itemCheck,groupSetting){
	if (document.getElementById(itemCheck).checked==false){
		document.getElementById(itemCheck).checked=true;
	}
	changeDisplaySetting(groupSetting);
}



function checkPrintRights(printRights,loginUname, albumUname, shareable){
	var ele = printRights+"HiddenPrint";
	var rights = document.getElementById(ele).value;

	switch(rights){
		case "1":
			if(loginUname == albumUname){
				showAddCart();
				return true;
			}else{
				hideAddCart();
				return false;
			}
			break;
		case "2":
			if(shareable == "1" || loginUname == albumUname){
				showAddCart();
				return true;
			}else{
				hideAddCart();
				return false;
			}
			break;
		case "3":
			showAddCart();
			return true;
			break;
	}
}

function showAddCart(){
	($('add')).style.visibility = "visible";
	($('printDeny')).style.visibility = "hidden";
	($('printDeny')).style.display = "none";
	($('SCselect')).style.visibility = "visible";
	($('SCselect')).style.display = "block";
	($('SelectTitle')).style.visibility = "visible";
	($('SelectTitle')).style.display = "block";
}

function hideAddCart(){
	($('add')).style.visibility = "hidden";
	($('printDeny')).style.visibility = "visible";
	($('printDeny')).style.display = "block";
	($('SCselect')).style.visibility = "hidden";
	($('SCselect')).style.display = "none";
	($('SelectTitle')).style.visibility = "hidden";
	($('SelectTitle')).style.display = "none";
}


function showSaveButton(){
	($('saveButton')).style.visibility = "visible";
	($('saveButton')).style.display = "inline";
	($('cancelButton')).style.visibility = "visible";
	($('cancelButton')).style.display = "inline";
}

function sortingSubmit(TheForm, methodUsed){
	TheForm.saveSortHidden.value = methodUsed;
	TheForm.method = "POST";
	TheForm.submit();
}

var currentX,currentY;
var IE = document.all?true:false;
if (!IE) {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getMouseXY;

function getMouseXY(e){

	if (IE) {
		currentX = event.clientX + document.body.scrollLeft;
		currentY = event.clientY + document.body.scrollTop;
	}
	else{
		currentX = e.pageX;
		currentY = e.pageY;
	}
	(currentX<0)?0:currentX;
	(currentY<0)?0:currentY;

}

function cartNotEmpty(){
	if ($('showCart')){
		($('showCart')).style.visibility = "visible";
		($('showCart')).style.display = "inline";
	}
	if ($('emptyCart')){
		($('emptyCart')).style.visibility = "hidden";
		($('emptyCart')).style.display = "none";
	}
}

var div = "";
var types = "";
var imgCount = 0;
var colorPattern = "";


var origColor = "";
var origOpacity = "";
var origFilter = "";


function addConfirmation(imageCount, type, pattern){

	types = type;
	imgCount = imageCount;
	colorPattern = pattern;
	div = "AlbumDetail_";
	var tempDiv = "";
	var ele = "";
	var box = "";
	var topInt = 0;

	if(types == "folder"){
		box = "Check";
	}else{
		box="";
	}

	for(var i=0; i<imgCount; i++){
		tempDiv = div+""+i;
		ele = ($(tempDiv)).style;
		origColor = ele.color;
		origOpacity = ele.opacity;
		origFilter = ele.filter;
		ele.color =  "black";
      	ele.opacity = .20;
	    ele.filter = "Alpha(Opacity=50)";
		ele.cursor = "default";
		($(i+"Field")).disabled = true;
	}


	($("continueToCart")).style.top = document.body.scrollTop+(document.body.clientHeight/4);
	($('waitingProcess')).style.visibility="hidden";
	($('waitingProcess')).style.display="none";
	($("continueToCart")).style.left = (document.body.clientWidth-400)/2;
	($("continueToCart")).style.visibility = "visible";
	($("continueToCart")).style.display = "inline";

	InitializeTimer();
	($("autoClose")).innerHTML = cartConfirmDisplay[1]+" "+secs+" "+cartConfirmDisplay[2];
}

var secs=0;
var timerID = null;
var timerRunning = true;
var delay = 1000;

function InitializeTimer(){
  secs = 7;
  timerRunning = true;
  StartTheTimer();
}

function StopTheClock(){
  if (timerRunning){
    clearTimeout(timerID);
    timerRunning = false;
  }
}

function StartTheTimer(){
	if (secs==0){
	    secs = 7;
	    hideConfirm();
	}
  	secs = secs - 1;
  	($("autoClose")).innerHTML = cartConfirmDisplay[1]+" "+secs+" "+cartConfirmDisplay[2];

  	if (timerRunning){
    	timerID = self.setTimeout("StartTheTimer()", delay);
  	}
}

function hideConfirm(){
	var tempDiv="";
	var ele= "";
	var box= "";
	StopTheClock();

	if(types == "folder"){
		box = "Check";
	}else{
		box="";
	}

	div = "AlbumDetail_";

	for(var i=0; i<imgCount; i++){
		tempDiv = div+""+i;
		ele = ($(tempDiv)).style;
		ele.color =  origColor;
      	ele.opacity = origOpacity;
	    ele.filter = origFilter;
      	($(i)).disabled = false;
      	($(i+"Field")).disabled = false;
	}

	if(IE){
		($('SCselect')).style.visibility = "visible";
		($('viewBy')).style.visibility = "visible";
	}
	($('blackLayer')).style.visibility = "hidden";
	document.body.style.overflow = "auto";
	($("continueToCart")).style.visibility = "hidden";
	($("continueToCart")).style.display = "none";
	($("autoClose")).value = "";
}

function imgClickable(TheForm, actionStr, methodStr){
	if (!$('blackLayer') || ($('blackLayer')).style.visibility == "hidden"){
		TheForm.action = actionStr;
		TheForm.method = methodStr;
		TheForm.submit();
	}
}


function addAlbumImage(){
	optSize = document.getElementById('optItem');
	optItem = optSize.options[optSize.selectedIndex].value;
	for(var i=0;i<folderName.length; i++){
		if(document.getElementById(i).checked == true){
			addToCart(document.getElementById(i).value, optItem);
		}
	}
}

function reorder(totalImage){
	if(totalImage > 0){
		if(($('StereoMsg'))){
			($('StereoMsg')).style.visibility = "hidden";
			($('StereoMsg')).style.display = "none";
		}
		($('reorderTable')).style.visibility = "visible";
		($('reorderTable')).style.display = "inline";
		($('viewBy')).style.visibility = "hidden";
		($('viewBy')).style.display = "none";

		($('reorderBoolean')).value = "1";
		imgCount = totalImage;

		for(var i=0; i<imgCount; i++){
			($('img_'+i)).style.cursor = "move";
		}

		for(var i=0; i<imgCount; i++){
			($(i+"rad")).style.visibility = "hidden";
			($(i+"rad")).style.display = "none";
		}

		emptyMarker = true;
		if($('albumSortable_1')){
		  Sortable.create("albumSortable_1",
		   {dropOnEmpty:false,tag:'div',overlap:'horizontal', containment:["albumSortable_1"],constraint:false, ghosting:false});
		   originalSequence_1 = Sortable.sequence('albumSortable_1');
		}

		if($('albumSortable_2')){
		   Sortable.create("albumSortable_2",
		   {dropOnEmpty:false,tag:'div',overlap:'horizontal', containment:["albumSortable_2"],constraint:false, ghosting:false});
				originalSequence_2 = Sortable.sequence('albumSortable_2');
		}
	}
}

function endReorder(imgCount){
	($('reorderTable')).style.visibility = "hidden";
	($('reorderTable')).style.display = "none";
	($('viewBy')).style.visibility = "visible";
	($('viewBy')).style.display = "inline";
	($('reorderBoolean')).value = "0";
	($('StereoMsg')).style.visibility = "visible";
	($('StereoMsg')).style.display = "inline";

	for(var i=0; i<imgCount; i++){
		($('img_'+i)).style.cursor = "pointer";
	}

	for(var i=0; i<imgCount; i++){
		($(i+"rad")).style.visibility = "visible";
		($(i+"rad")).style.display = "block";
	}

	emptyMarker = false;
	orderUpdate();
}

function cancelReorder(){
	($('reorderTable')).style.visibility = "hidden";
	($('reorderTable')).style.display = "none";
	($('viewBy')).style.visibility = "visible";
	($('viewBy')).style.display = "inline";
	($('reorderBoolean')).value = "0";
	($('StereoMsg')).style.visibility = "visible";
	($('StereoMsg')).style.display = "inline";

	if($('messageInner')){
		($('messageInner')).innerHTML = "<img src='"+headerDisplay[30]+"' align='absmiddle'> "+headerDisplay[33];
		($('messageInner')).style.visibility = "visible";
		($('messageInner')).style.display = "inline";
	}else{
		($('errorMsgDiv')).innerHTML = "<img src='"+headerDisplay[30]+"' align='absmiddle'> "+headerDisplay[33];
	}

	if($('RightPanel_ManTool') && $('RightPanel_SCTool')){
		($('RightPanel_ManTool')).style.visibility = "visible";
		($('RightPanel_ManTool')).style.display = "inline";
		($('RightPanel_SCTool')).style.visibility = "visible";
		($('RightPanel_SCTool')).style.display = "inline";
	}

	for(var i=0; i<imgCount; i++){
		($('img_'+i)).style.cursor = "pointer";
	}

	for(var i=0; i<imgCount; i++){
		($(i+"rad")).style.visibility = "visible";
		($(i+"rad")).style.display = "block";
	}

	if(($('albumSortable_1'))){
	   	seq = Sortable.sequence('albumSortable_1');
	   	Sortable.destroy('albumSortable_1');
    }
	if($('albumSortable_2')){
		seq2 = Sortable.sequence('albumSortable_2');
		Sortable.destroy('albumSortable_2');
	}
}


var dragArray = new Array();
var dragArrayId = new Array();

function createDraggable(dragDiv){
	var d = new Draggable(dragDiv, {ghosting:true, revert:true});
	dragArray.push(d);
	dragArrayId.push(dragDiv);
}

function createAllDraggable(){
	for(var i=0; i<dragArrayId.length; i++)
		new Draggable(dragArrayId[i], {ghosting:true, revert:true});

}

function resetSequence(){
	if(($('albumSortable_1'))) Sortable.setSequence('albumSortable_1', originalSequence_1);
	if(($('albumSortable_2'))) Sortable.setSequence('albumSortable_2', originalSequence_2);
}

function getUpdateOption(groupFlag, TheForm){

	var URL = URLPREFIX+'album.sortorder';
	var options = "";
	var response = false;
	var displayMSG = "";

	var isNull = ($('reorderNull')).value;
	var sysIMG = headerDisplay[30];
	var failMSG = headerDisplay[31];
	var succMSG = headerDisplay[32];
	var clearMSG = headerDisplay[37];

	if(groupFlag >1){
	 	options = {  method : 		'post',
                     parameters : 	{List1:Sortable.serialize('albumSortable_1'), List2:Sortable.serialize('albumSortable_2'), List3:fidString, reorderNull:isNull},
                     onSuccess: 	function(transport){
        	               				response = transport.responseText;
                         				if(response == "1"){
        									if(($('reorderNull')).value == "1"){
	        									displayMSG = clearMSG;
	        									($('reorderNull')).value = "0";
        									}else{
	        									displayMSG = succMSG;
        									}
        								}else{
        									displayMSG = failMSG;
       									}
                         				$('reorderStatus').value = displayMSG;
                         				$('reorderBoolean').value = "";
                         				TheForm.submit();
   							},

                    onFailure: 	function (){
	                    			if($('messageInner')){
	                    				($('messageInner')).innerHTML = "<img src='"+sysIMG+"' align='absmiddle'> "+failMSG;
	                    				($('messageInner')).style.visibility = "visible";
										($('messageInner')).style.display = "inline";
									}else{
										($('errorMsgDiv')).innerHTML = "<img src='"+sysIMG+"' align='absmiddle'> "+failMSG;
									}
									if(($('albumSortable_1'))){
	   										seq = Sortable.sequence('albumSortable_1');
	   										Sortable.destroy('albumSortable_1');
	   									}
	   									if($('albumSortable_2')){
	   										seq2 = Sortable.sequence('albumSortable_2');
	   										Sortable.destroy('albumSortable_2');
	   									}
                    			}
                    };

	}else{
		options = {  method : 	'post',
                 parameters : 	{List1:Sortable.serialize('albumSortable_1'), List2:"1", List3:fidString, reorderNull:isNull},
                 onSuccess: 	function(transport){
	    	               				response = transport.responseText;
	                       				if(response == "1"){
	        								displayMSG = succMSG
        								}else{
	        								displayMSG = failMSG;
       									}
       									if($('messageInner')){
	       									($('messageInner')).innerHTML = "<img src='"+sysIMG+"' align='absmiddle'> "+displayMSG;
	       									($('messageInner')).style.visibility = "visible";
											($('messageInner')).style.display = "inline";
										}else{
											($('errorMsgDiv')).innerHTML = "<img src='"+sysIMG+"' align='absmiddle'> "+displayMSG;
										}
	   									TheForm.submit();
   									},

                 onFailure: 	function (){
	                 				if($('messageInner')){
	                 					($('messageInner')).innerHTML = "<img src='"+sysIMG+"' align='absmiddle'> "+failMSG;
	                 					($('messageInner')).style.visibility = "visible";
										($('messageInner')).style.display = "inline";
									}else{
										($('errorMsgDiv')).innerHTML = "<img src='"+sysIMG+"' align='absmiddle'> "+failMSG;
									}

									if(($('albumSortable_1'))){
	   										seq = Sortable.sequence('albumSortable_1');
	   										Sortable.destroy('albumSortable_1');
	   									}

	   									if($('albumSortable_2')){
	   										seq2 = Sortable.sequence('albumSortable_2');
	   										Sortable.destroy('albumSortable_2');
	   									}
                 				}
                 };

	}
	new Ajax.Request(URL,options);
}

function resetPos(){
  	if(noReorder == true){
  		if(($('albumSortable_1')))
   			Sortable.setSequence('albumSortable_1', originalSequence_1);

		if(($('albumSortable_2')))
   			Sortable.setSequence('albumSortable_2', originalSequence_2);
   	}
}

function addToCart(theValue, optItem){
	var URL= URLPREFIX+'album.addcart';
	var response= "";
	var username = loginUname;
	var addValue = "";
	addValue = theValue;

	if(addValue != " "){
	var options = { method: 'post',
					parameters:{user:username, addValue:addValue, optItem:optItem, type:'album'},
					onSuccess: function(transport){
						response = transport.responseText;

						var respString = response.split("|");
	                    document.getElementById('cartCount').innerHTML = "<b>"+respString[2]+"</b> "+cartDisplay[0];
	                    if(document.getElementById('emptyCart').style.visibility == "visible"){
	                    	document.getElementById('emptyCart').style.visibility = "hidden";
	                    	document.getElementById('emptyCart').style.display = "none";
	                    	document.getElementById('showCart').style.visibility = "visible";
	                    	document.getElementById('showCart').style.display = "inline";
	                    	document.getElementById('viewCartLink').style.visibility = "visible";
	                    	document.getElementById('viewCartLink').style.display = "inline";
	                   	}

	                   	if(respString[0] == "0"){
	                   		document.getElementById('addToCartMSG1').innerHTML = cartDisplay[2];
                   		}else{
	                   		document.getElementById('addToCartMSG1').innerHTML = respString[0]+"</b> "+cartDisplay[1];
                   		}

	                   	addConfirmation(totalImageCount, 'album', colorPattern);

					},
					onFailure: function(){
						if(document.getElementById('emptyCart').style.visibility == "visible"){
	                    	document.getElementById('emptyCart').style.visibility = "hidden";
	                    	document.getElementById('emptyCart').style.display = "none";
	                    	document.getElementById('showCart').style.visibility = "visible";
	                    	document.getElementById('showCart').style.display = "inline";
	                    	document.getElementById('viewCartLink').style.visibility = "visible";
	                    	document.getElementById('viewCartLink').style.display = "inline";

	                   	}

	                   	document.getElementById('addToCartMSG1').innerHTML = cartDisplay[2];
	                   	addConfirmation(totalImageCount, type, colorPattern);
					}

	};
	new Ajax.Request(URL, options);
	}
}

function submitFriend(TheForm){
	if(($('newNickname')).value.length > 0){
		TheForm.method = "POST";
		TheForm.submit();
	}else{
		alert();
	}

}

function cancelNewFriend(){
	($('blackLayer')).style.visibility = "hidden";

	($('addFriendDiv')).style.visibility="hidden";
	($('addFriendDiv')).style.display="none";
}

function checkAllEmail(emailCount){
	var isChecked = false;
	if($('checkAll').checked)
		isChecked = true;
	else
		isChecked = false;

	if(emailCount > 0 || emailCount != null){
		for(var i=0; i<emailCount; i++)
		($('friendEmail_'+i)).checked = isChecked;
	}
}

function funResetNull(imageCount){
	if(confirm(headerDisplay[38])){
		document.getElementById('reorderNull').value = "1";
		endReorder(imageCount);
	}
}


function displayAlbumTab(album){
	var offsets = Position.positionedOffset($(album));
	var wdth = offsets[0];
	var hght = offsets[1];
	($(tabDiv)).style.left = wdth+175;
	($(tabDiv)).style.top = hght;
	($('tabDiv')).style.visibility='visible';
	($('tabDiv')).style.display='block';

}

function hideAlbumTab(){
	if(mseoverAlbum == false && mseoverTab == false){
		($('tabDiv')).style.visibility='hidden';
		($('tabDiv')).style.display='none';
	}
}

function addCartFromTab(folderKey, optItem){
	setTimeout("addCartFromTab1('"+folderKey+"', "+optItem+")", 900);
}

function addCartFromTab1(folderKey, optItem){

	document.body.style.overflow = "hidden";
	document.getElementById('blackLayer').style.top = 0;
	document.getElementById('blackLayer').style.left = document.body.scrollLeft;
	document.getElementById('blackLayer').style.width = document.body.clientWidth;
	document.getElementById('blackLayer').style.height = document.body.scrollHeight;
	($('blackLayer')).style.visibility = "visible";

	if(IE){
		($('SCselect')).style.visibility = "hidden";
		($('viewBy')).style.visibility = "hidden";
	}

	($("waitingProcess")).style.left = (document.body.clientWidth-300)/2;
	($("waitingProcess")).style.top = document.body.scrollTop+(document.body.clientHeight/2)-50;
	($('waitingProcess')).style.visibility="visible";
	($('waitingProcess')).style.display="inline";

	setTimeout("addToCart('"+folderKey+"', "+optItem+")", 500);
}

function tabDetachMsg(index){
	var folderId = document.getElementById(index+"HiddenFolder").value;
	for (key in folder){
		if (folder[key] ==folderId){
			checkedItem = key;
			break;
		}
	}
	var memberFound = false;
	for(FID in memberNameWithFID){
		if(FID == folderId){
			for(member in memberNameWithFID[FID]){
				if(memberNameWithFID[FID][member] == loginUname){
					memberFound = true;
					break;
				}
			}
			break;
		}
	}

	if(isOwner[folderId] == 0){
		return headerDisplay[39];
	}else if(!memberName[checkedItem]){
		return headerDisplay[16];
	}else{
		return headerDisplay[19];
	}
}

function tabDetach(){
	document.frmAlbum.action = URLPREFIX+"album.group.detach";
	document.frmAlbum.submit();
}

function tabDelete(){
	document.frmAlbum.action =URLPREFIX+'album.delete';
	document.frmAlbum.submit();
}

function switchFeed(showFeed){
	switch(showFeed){
		case 'rate':	document.getElementById('rateFeedDiv').style.display = "inline";
						document.getElementById('commentFeedDiv').style.display = "none";
						document.getElementById('switchRateDiv').style.display = "none";
						document.getElementById('switchCommentDiv').style.display = "inline";
						break;
		case 'comment':	document.getElementById('rateFeedDiv').style.display = "none";
						document.getElementById('commentFeedDiv').style.display = "inline";
						document.getElementById('switchRateDiv').style.display = "inline";
						document.getElementById('switchCommentDiv').style.display = "none";
						break;
	}
}

function init(){
	document.getElementById('viewBy').style.display = "inline";
}

function startReorder(TheForm){
	$('reorderBoolean').value = 1;
	TheForm.submit();
}

function submitCancelReorder(TheForm){
	$('reorderBoolean').value = 0;
	TheForm.submit();
}