var browser = navigator.appName;
var b_version = navigator.appVersion;
var version = parseFloat(b_version);
var bFF = false; //document.getElementById ? 1 : 0;
var bIE6 = false; 
var bIE7 = false; 
var bSafari = false;
var bOpera = false;
var g_bPictureVisible = false;
var g_mapPictureRate = Array();

if( browser == "Netscape" ) 
{
	bFF = true;
	if( b_version.search("Safari") != -1 ) bSafari = true;
}
else if( browser == "Microsoft Internet Explorer" && version == 4 )
{
	if( b_version.search("MSIE 7") != -1 ) bIE7 = true;
	else if( b_version.search("MSIE 6") != -1 )	bIE6 = true;
}
else if( browser == "Opera" ) 
{
	bOpera = true;
}
//alert(browser + ", " + b_version + ", " + version);
//alert(bFF + ", " + bIE6 + ", " + bIE7);

var g_nHeight = -1;

function ReSizeBGR()
{
	var xScroll = GetScrollDistanceX();
	var yScroll = GetScrollDistanceY();

	var nWidth = GetInnerWidth();
	var nHeight = document.body.scrollHeight;
	var nHeight2 = GetInnerHeight();
	if( nHeight2 > nHeight ) nHeight = nHeight2;

	var left = 0 /*nWidth / 2 - 0 +*/;
	var top = 0 /*nHeight / 2 - 0 +*/;
	var width = nWidth + xScroll + xScroll;
	var height = nHeight + yScroll + yScroll + 100;
	
	
	//alert( window.innerHeight );
	//alert( window.scrollMaxY );
	//alert( nHeight );
	/*alert( self.innerHeight ); // 626, -, 605
	alert( document.documentElement.clientHeight ); // 626, 683, 605, O(1379)
	alert( document.body.clientHeight ); //1404,1404, 1398
	alert( window.scrollMaxY ); //819, -, -
	alert( document.documentElement.scrollHeight );//1445, 1434, 1439, O(1379)
	alert( document.body.scrollHeight );//1404, 1404, 1439, O(1379)*/

	//	save the max height of the page
	/*if( g_nHeight == -1 )
	{
		g_nHeight = height;
	}
	
	if( height > g_nHeight )
	{
		height = g_nHeight;
	}*/
	
	if( bIE7 || bIE6 )
	{
		document.all('body_bgr').style.left = left + "px";
		document.all('body_bgr').style.top = top + "px";
		document.all('body_bgr').style.width = width + "px";
		document.all('body_bgr').style.height = height + "px";
	}
	else if( bFF || bOpera )
	{
		document.getElementById('body_bgr').style.left = left + "px";
		document.getElementById('body_bgr').style.top = top + "px";
		document.getElementById('body_bgr').style.width = width - (bSafari ? 0 : 16) + "px";
		document.getElementById('body_bgr').style.height = height + "px";
	}
	
	//	if picture is visible update
	if( g_bPictureVisible )
	{
		UpdateCurrentPicture();
	}
	
}

function GetXYPos( strName, bX )
{
	var objPic;
	if( !bFF )
	{
		objPic = document.all(strName);
	}
	else
	{
		objPic = document.getElementById(strName)
	}
	if( bX )
	{
		return objPic.style.left;
	}
	return objPic.style.top;
}

//	stores the current position
var g_yScroll = 0;

function OpenPicture( strImg, nIndex,nUserID,nUserType,nPictureID,bKeepOriginalPosition,nRate )
{
	g_nPictureIndex = nIndex;
	if( nRate <= 0 && nRate != -2 ) nRate = g_arrPicturesRate[ g_nPictureIndex ];

	//alert( g_nPictureIndex );
	//alert( "nUserID: " + nUserID + ", nPictureID: " + nPictureID + ", nRate: " + nRate );
	if( nUserID > 0 && nPictureID > 0 )	UpdatePictureClick(nUserID,nPictureID,2)

	//ClosePicture();
		
	var xScroll = GetScrollDistanceX();
	var yScroll = GetScrollDistanceY();

	if( bKeepOriginalPosition )
	{
		yScroll = g_yScroll;
	}
	else
	{
		g_yScroll = yScroll;
	}

	var nWidth = GetInnerWidth();
	var nHeight = document.body.scrollHeight;
	var nHeight2 = GetInnerHeight();
	if( nHeight2 > nHeight ) nHeight = nHeight2;

	var left = 0 /*nWidth / 2 - 0 +*/;
	var top = 0 /*nHeight / 2 - 0 +*/;
	var width = nWidth + xScroll + xScroll;
	var height = nHeight + yScroll + yScroll + 99;
/*
	var strHTML = 
		"<table border=0 id=picture-table>" +
			"<tr><td></td><td><a href='javascript:ClosePicture()'>close</a></td></tr>" +
			"<tr><td><a href='javascript:ClosePicture()'><img src='" + strImg + "' /></a></td><td></td></tr>" +
		"</table>";
*/
//left:0%; right:100%; ;

	var strRateBlock = "";
	if( nRate > 0 )
	{
		strRateBlock = "";
		switch( nRate ) 
		{
			case 1:
				strRateBlock = "<b class=rate1>&#9829;</b>";
				break;

			case 2:
				strRateBlock = "<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;</b></b>";
				break;

			case 3:
				strRateBlock = "<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;</b></b></b>";
				break;

			case 4:
				strRateBlock = "<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;</b></b></b></b>";
				break;

			case 5:
				strRateBlock = "<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;" + 
				"<b class=rate1>&#9829;</b></b></b></b></b>";
				break;
		}
	}
	else
	{
		strRateBlock = 
			"rate: <b class=rate onclick='javascript:RatePicture(" + nIndex + "," + nUserID + "," + nPictureID + ",1)'>&#9829;" + 
			"<b class=rate onclick='javascript:RatePicture(" + nIndex + "," + nUserID + "," + nPictureID + ",2)'>&#9829;" + 
			"<b class=rate onclick='javascript:RatePicture(" + nIndex + "," + nUserID + "," + nPictureID + ",3)'>&#9829;" + 
			"<b class=rate onclick='javascript:RatePicture(" + nIndex + "," + nUserID + "," + nPictureID + ",4)'>&#9829;" + 
			"<b class=rate onclick='javascript:RatePicture(" + nIndex + "," + nUserID + "," + nPictureID + ",5)'>&#9829;</b></b></b></b></b>";
	}
	
	var strLinkToUser = "";
	if( nUserID > 0 && nUserType > 0 )
	{
		var strURLToUser = "";
		if( nUserType == 1 ) strURLToUser = "/model.php?n=" + nUserID;
		if( nUserType == 2 ) strURLToUser = "/photographer.php?n=" + nUserID;
		if( nUserType == 3 ) strURLToUser = "/make-up-artist.php?n=" + nUserID;
		strLinkToUser = "<a href='" + strURLToUser + "'><img class=icon3 src='/images/user.png' />View profile</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	}
	
	var strHTML = 
		"<div align=center id='picture-table' style='width:80%; min-width:900px; position: absolute; margin-left: 10%;margin-right: 10%;' ><div style=''>" +
			"<div class=round-corner><b class=rtop0><b class=r1></b> <b class=r2></b> <b class=r3></b> <b class=r4></b></b>" + 
			"<div class=content0>" +
			//"<b class='clicktoclose'><a href='javascript:ClosePicture()'></a></b>" +
			//"<a href='javascript:ClosePicture()'>" +
			"<table class=picturetable border=0 cellpadding=4 bgcolor=#ffffff>" + 
			"<tr><td colspan=2 align=right><a class=clicktoclosetext href='javascript:ClosePicture()'><img class=icon src='/images/cross.png' /></a></td></tr>" + 
			(nRate != -2 ? 
				"<tr><td align=center width=50%>" + 
				"<b class=rate1><b class=rate1>" + 
				strRateBlock + 
				"</b></b>" : "<td>" ) +
			"</td>" +
			(nRate != -2 && nUserID ? "<td align=center><a href='javascript:GetPrevPicture()' onclick=''><b><img class=icon2 src='/images/resultset_previous.png' /></b>previous</a>" + 
			"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + 
			"<a href='javascript:GetNextPicture()' onclick=''>next<b><img class=icon src='/images/resultset_next.png' /></b></a></td></tr>" : "" ) + 
			"<tr><td colspan=2 align=center>" + 
			(nRate != -2 && nUserID ? "<a href='javascript:GetNextPicture()' onclick=''>" : "" ) +
			" <img class=img_big src='/" + strImg + "' />" + 
			(nRate != -2 && nUserID ? "</a>" : "") + 
			"</td></tr>" +
			"</table>" + 
		"<div class=textSmallTextPicLink>" + strLinkToUser + "<a target=_blank href='http://www.vogue-models.co.uk/" + strImg + "'><img class=icon3 src='/images/link.png' /></a>- http://www.vogue-models.co.uk/" + strImg + "</div>" +
			"</div>" +
			"<b class=rbottom0><b class=r4></b> <b class=r3></b> <b class=r2></b> <b class=r1></b></b></div>" +
		"</div></div>";

	//<center></center>
	var objPic;
	var objPic2;
	/*if( !bFF )
	{
		objPic = document.all('picture-container');
		objPic2 = document.all('picture-container-bgr');
	}
	else*/
	{
		objPic = document.getElementById('picture-container')
		objPic2 = document.getElementById('picture-container-bgr')
	}
	objPic.style.visibility = "visible";
	objPic.style.display = "block";
	objPic.style.left = left + "px";
	objPic.style.top = top + "px";
	objPic.style.width = (width - (!bFF ? 0 : 16)) + "px";
	objPic.style.height = 0 /*height*/ + "px";

	objPic2.style.visibility = "visible";
	objPic2.style.display = "block";
	objPic2.style.left = left + "px";
	objPic2.style.top = top + "px";
	objPic2.style.width = (width - (!bFF ? 0 : 16)) + "px";
	objPic2.style.height = height + "px";

	objPic.innerHTML = strHTML;
	//alert( objPic.innerHTML );
	//objPic2.innerHTML = strHTML;

	if( !bFF )
	{
		document.all('picture-table').style.left = left + xScroll + "px";
		document.all('picture-table').style.top = top + yScroll + 40 + "px";
		//objPic.style.filter = "alpha(opacity=50)"; //filter:alpha(opacity=95)
		document.all('picture-table').style.filter = "alpha(opacity=100)"; //filter:alpha(opacity=95)
		objPic2.style.filter = "alpha(opacity=15)";
	}
	else
	{
		document.getElementById('picture-table').style.left = left + xScroll + "px";
		document.getElementById('picture-table').style.top = top + yScroll + 40 + "px";
		objPic.style.opacity = "1.0";
		objPic.style.MozOpacity = 1.0;
		objPic2.style.opacity = "0.15";
		objPic2.style.MozOpacity = 0.15;
	}
	//ReSizeBGR();
	g_bPictureVisible = true;
}

function ClosePicture()
{
	if( !bFF )
	{
		document.all('picture-container').style.visibility = "hidden";
		document.all('picture-container').style.display = "none";
		document.all('picture-container').innerHTML = "";
		document.all('picture-container-bgr').style.visibility = "hidden";
		document.all('picture-container-bgr').style.display = "none";
		document.all('picture-container-bgr').innerHTML = "";
	}
	else
	{
		document.getElementById('picture-container').style.visibility = "hidden";
		document.getElementById('picture-container').style.display = "none";
		document.getElementById('picture-container').innerHTML = "";
		document.getElementById('picture-container-bgr').style.visibility = "hidden";
		document.getElementById('picture-container-bgr').style.display = "none";
		document.getElementById('picture-container-bgr').innerHTML = "";
	}
	g_bPictureVisible = false;
}


/*
function AddNewPicture( nUserID )
{
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'AddPicture');
	newdiv.className = "AddPictureDlg";

	var xScroll = GetScrollDistanceX();
	var yScroll = GetScrollDistanceY();

	var nWidth = GetInnerWidth();
	var nHeight = GetInnerHeight();
		
	var left = nWidth / 2 - 150 + xScroll;
	var top = nHeight / 2 - 150 + yScroll;
	newdiv.style.left = left + "px";
	newdiv.style.top = top + "px";
	var html = "x:" + xScroll + ", y:" + yScroll;
	if(html) 
	{
		newdiv.innerHTML = html;
	} 
	else 
	{
		newdiv.innerHTML = "nothing";
	}
	document.body.appendChild( newdiv );
}
*/

function GetScrollDistanceX()
{
	if( self.pageYOffset ) // all except Explorer
	{
		xScroll = self.pageXOffset;
	}
	else if( document.documentElement && document.documentElement.scrollTop )
		// Explorer 6 Strict
	{
		xScroll = document.documentElement.scrollLeft;
	}
	else if( document.body ) // all other Explorers
	{
		xScroll = document.body.scrollLeft;
	}
	return xScroll;
}
function GetScrollDistanceY()
{
	if( self.pageYOffset ) // all except Explorer
	{
		yScroll = self.pageYOffset;
	}
	else if( document.documentElement && document.documentElement.scrollTop )
		// Explorer 6 Strict
	{
		yScroll = document.documentElement.scrollTop;
	}
	else if( document.body ) // all other Explorers
	{
		yScroll = document.body.scrollTop;
	}
	return yScroll;
}

function GetInnerWidth()
{
	if (self.innerHeight) // all except Explorer
	{
		nWidth = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		nWidth = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		nWidth = document.body.clientWidth;
		y = document.body.clientHeight;
	}	
	return nWidth;
}
function GetInnerHeight()
{
	if (self.innerHeight) // all except Explorer
	{
		nHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		nHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		nHeight = document.body.clientHeight;
	}	
	return nHeight;
}

function ShowHideDiv( divName )
{
	ShowHideDiv2( divName, -1 );
}

function ShowHideDiv2( divName, nShow )
{
	//	ignore override
	if( nShow == -1 )
	{
	
	}

	//	get status
	var strVisibility = "";
	var strDisplay = "";
	if( bFF || bSafari )
	{
		strVisibility = document.getElementById( divName ).style.visibility;
		strDisplay = document.getElementById( divName ).style.display;
	}
	else if( bIE7 )
	{
		strVisibility = document.all( divName ).style.visibility; 
		strDisplay = document.all( divName ).style.display; 
	}
	else if( bIE6 )
	{
		//alert( document.all( divName ).style.visibility )
		//alert( document.all( divName ).style.display )
		strVisibility = document.all( divName ).style.visibility; 
		strDisplay = document.all( divName ).style.display; 
	}
	else
	{
		alert("dont want to be here!!!");
	}
	var bVisible = true;
	//if( strVisibility == 'visible' ) { strVisibility = 'hidden'; } else { strVisibility == 'visible'; }
	//alert( "strDisplay : '" + strDisplay + "'" );
	if( strDisplay == 'none' ) { bVisible = true; strDisplay = 'inline'; } else { bVisible = false; strDisplay = 'none'; }
	if( strVisibility == 'hidden' ) { bVisible = true; strVisibility = 'visible'; } else { bVisible = false; strVisibility = 'hidden'; }

	if( nShow != -1 )
	{
		//alert( nShow );
		if( nShow ) { strDisplay = 'inline'; } else { strDisplay = 'none'; }
		if( nShow ) { strVisibility = 'visible'; } else { strVisibility = 'hidden'; }
	}

	//alert( strVisibility );
	//alert( "strDisplay : '" + strDisplay + "'" );
	
	//	show/hide
	if( bFF || bSafari )
	{
		document.getElementById( divName ).style.visibility = strVisibility;
		document.getElementById( divName ).style.display = strDisplay;
	}
	else if( bIE7 )
	{
		//document.getElementById( divName ).style.visibility = strVisibility;
		//document.all( divName ).style.visibility = strVisibility; 
		document.all( divName ).style.display = strDisplay; 
	}
	else if( bIE6 )
	{
		//if( strDisplay == '' ) { strDisplay = 'show'; } else {  }
		document.all( divName ).style.visibility = strVisibility; 
		document.all( divName ).style.display = strDisplay; 
		//alert( document.all( divName ).style.display );
	}
	else
	{
		alert("dont want to be here!!!");
	}
	//ReSizeBGR();
	return bVisible;
}


function UpdateCurrentPicture()	
{
	g_nPictureIndex;
	if( g_nPictureIndex >= g_nPictureCount ) g_nPictureIndex = 0;		
	ClosePicture();
	OpenPicture( g_arrPictures[ g_nPictureIndex ], g_nPictureIndex,g_nUserID,0,g_arrPicturesID[g_nPictureIndex], true, g_arrPicturesRate[ g_nPictureIndex ] );
}

function GetNextPicture()	
{
	g_nPictureIndex++;
	if( g_nPictureIndex >= g_nPictureCount ) g_nPictureIndex = 0;		
	ClosePicture();
	OpenPicture( g_arrPictures[ g_nPictureIndex ], g_nPictureIndex,g_nUserID,0,g_arrPicturesID[g_nPictureIndex], true, g_arrPicturesRate[ g_nPictureIndex ] );
}

function GetPrevPicture()	
{
	g_nPictureIndex--;
	if( g_nPictureIndex < 0 ) g_nPictureIndex = g_nPictureCount-1;		
	ClosePicture();
	OpenPicture( g_arrPictures[ g_nPictureIndex ], g_nPictureIndex,g_nUserID,0,g_arrPicturesID[g_nPictureIndex], true, g_arrPicturesRate[ g_nPictureIndex ] );
}



function GetXMLHttp()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		return xmlHttp;
	}
	catch( e )
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			return xmlHttp;
		}
		catch( e )
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			}
			catch( e )
			{
				alert("Your browser does not support AJAX!");
				return 0;
			}
		}
	}
}

function UpdatePictureClick(nUserID,nPictureID,nClickType)
{
	//	up-picture-click.php?n=52&p=208&ct=1
	var xmlhttp = GetXMLHttp();
	var strURL = "/up-picture-click.php?n=" + nUserID + "&p=" + nPictureID + "&ct=" + nClickType;
	//alert( "UpdatePictureClick: " + strURL);
	xmlhttp.open( "GET", strURL, false );
	xmlhttp.send( null );	
}

function RatePicture( nIndex, nUserID, nPictureID, nRateValue )
{
	if( g_arrPicturesRate[ nIndex ] >= 1 ) return;
	g_arrPicturesRate[ nIndex ] = nRateValue;
	
	//	rate-picture.php?n=44&p=1091&rv=3
	var xmlhttp = GetXMLHttp();
	var strURL = "/rate-picture.php?n=" + nUserID + "&p=" + nPictureID + "&rv=" + nRateValue;
	//alert("RatePicture: " + strURL );
	xmlhttp.open( "GET", strURL, true );
	xmlhttp.send( null );	
	
	GetNextPicture();
}

var nLastUniqueUpdateKey = 0;

function RatePicture2( nUniqueUpdateKey, nUserID, nPictureID, nRateValue, strRedirect )
{
	if( nLastUniqueUpdateKey == nUniqueUpdateKey ) return;
	nLastUniqueUpdateKey = nUniqueUpdateKey;
	
	window.location = strRedirect;
	
	//alert("RatePicture2");
	//	rate-picture.php?n=44&p=1091&rv=3
	var xmlhttp = GetXMLHttp();
	var strURL = "/rate-picture.php?n=" + nUserID + "&p=" + nPictureID + "&rv=" + nRateValue;
	//alert("RatePicture: " + strURL );

	xmlhttp.open( "GET", strURL, false );
	xmlhttp.send( null );	
	
}

function GoToUser(nUserID,nType,nPictureID)
{
	/*UpdatePictureClick(nUserID,nPictureID,1);
  alert( "GoToUser" );
	if( nType == 1 ) window.location = "/model.php?n=" + nUserID;
	if( nType == 2 ) window.location = "/photographer.php?n=" + nUserID;
	if( nType == 3 ) window.location = "/make-up-artist.php?n=" + nUserID;
	*/
	/*xmlhttp.onreadystatechange = function() 
	{	
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			if( xmlhttp.responseText == 0 ) // 0 == does not exist
			{
				//alert( xmlhttp.responseText );
				objForm.method = "POST";
				objForm.action = "dojoin.php";
				objForm.submit();
			}
			else
			{
				//objForm.strUserName.value = "user name exists";
				alert( "User Name exists!!!" );
			}
		}
	}	*/
}

function MovePictureToGallery(nUserID,nGalleryID,nPictureID,strCellID)
{
	//alert("MovePictureToGallery");
	CloseMoveToGallery();
	
	if( !bFF )
	{
		document.all("CellID-" + strCellID).innerHTML = "";
	}
	else
	{
		document.getElementById("CellID-" + strCellID).innerHTML = "";
	}
	
	var xmlhttp = GetXMLHttp();
	var strURL = "/move-picture-to-gallery.php?n=" + nUserID + "&p=" + nPictureID + "&g=" + nGalleryID;
	//alert( strURL );

	xmlhttp.onreadystatechange = function() 
	{	
		//alert(xmlhttp.status + " - " + xmlhttp.readyState );
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			//alert( xmlhttp.responseText );
		}
	}
	xmlhttp.open( "GET", strURL, false );
	xmlhttp.send( null );	
}

function MoveToGallery( nUserID, nPictureID, nGalleryID, strCellID )
{
	GetGalleryList( nUserID, nPictureID, nGalleryID, strCellID );
}

function CloseMoveToGallery()
{
	if( !bFF )
	{
		document.all('gallery_list_container').style.visibility = "hidden";
		document.all('gallery_list_container').style.display = "none";
		document.all('gallery_list_container').innerHTML = "";
	}
	else
	{
		document.getElementById('gallery_list_container').style.visibility = "hidden";
		document.getElementById('gallery_list_container').style.display = "none";
		document.getElementById('gallery_list_container').innerHTML = "";
	}
}

function GetGalleryList( nUserID, nPictureID, nGalleryID, strCellID )
{
	var xmlhttp = GetXMLHttp();
	var strURL = "/get-gallery-list.php?n=" + nUserID + "&p=" + nPictureID + "&g=" + nGalleryID + "&ci=" + strCellID;
	//alert( strURL );
	xmlhttp.open( "GET", strURL, true );
	xmlhttp.send( null );	

	//alert("1");

	xmlhttp.onreadystatechange = function() 
	{	
		//alert(xmlhttp.status + " - " + xmlhttp.readyState );
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			var obj;
			if( !bFF ) obj = document.all('gallery_list_container');
			else obj = document.getElementById('gallery_list_container')

			obj.style.visibility = "visible";
			
			//	position the box in the middle
			var xScroll = GetScrollDistanceX();
			var yScroll = GetScrollDistanceY();

			var nWidth = GetInnerWidth();
			var nHeight = document.body.scrollHeight;
			var nHeight2 = GetInnerHeight();
			if( nHeight2 > nHeight ) nHeight = nHeight2;

			var left = 0 /*nWidth / 2 - 0 +*/;
			var top = 0 /*nHeight / 2 - 0 +*/;
			var width = nWidth + xScroll + xScroll;
			var height = nHeight + yScroll + yScroll + 99;

			obj.style.visibility = "visible";
			obj.style.display = "block";
			obj.style.left = left + "px";
			obj.style.top = top + nHeight2/2 - 200 + "px";
			obj.style.width = (width - (!bFF ? 0 : 16)) + "px";
			obj.style.height = 0 /*height*/ + "px";

			var strHTML = 
				"<div id='gallery-table' style='position: absolute; z-index: 999;' ><div style='width: 300px'>" +
					"<div class=round-corner><b class=rtop5><b class=r1></b> <b class=r2></b> <b class=r3></b> <b class=r4></b></b>" + 
					"<div class=content5>" +
						"<div class=round-corner><b class=rtop1><b class=r1></b> <b class=r2></b> <b class=r3></b> <b class=r4></b></b>" + 
							"<div class=content1>" +
							xmlhttp.responseText +
							"<div class=align_center><b class=textSmallText><br>(to move the picture click on the gallery)<br><br></b></div>" +
							"<div class=align_right><a href='javascript:CloseMoveToGallery()'>cancel</a></div>" +
							"</div>" +
						"<b class=rbottom1><b class=r4></b> <b class=r3></b> <b class=r2></b> <b class=r1></b></b></div>" +
					"</div>" +
					"<b class=rbottom5><b class=r4></b> <b class=r3></b> <b class=r2></b> <b class=r1></b></b></div>" +
				"</div></div>";
			
			obj.innerHTML = strHTML;
			//obj.style.width = "auto";
			//obj.style.height = "auto";
			//alert( "obj.innerHTML: " + obj.innerHTML );
			//return xmlhttp.responseText;

			if( !bFF )
			{
				document.all('gallery-table').style.left = left + xScroll + nWidth / 2 - 150 + "px";
				document.all('gallery-table').style.top = top + yScroll + "px";
				//objPic.style.filter = "alpha(opacity=50)"; //filter:alpha(opacity=95)
				document.all('gallery-table').style.filter = "alpha(opacity=100)"; //filter:alpha(opacity=95)
			}
			else
			{
				document.getElementById('gallery-table').style.left = left + xScroll + nWidth / 2 - 150 + "px";
				document.getElementById('gallery-table').style.top = top + yScroll + 40 + "px";
				obj.style.opacity = "1.0";
				obj.style.MozOpacity = 1.0;
			}
			
		}
		/*else
		{
			return xmlhttp.responseText;
		}*/
	}
}

function AddTextTo( strField, myValue, strType )
{
	var myField = document.getElementById(strField);
	//alert( myField.id );
	//alert( strField );

	if( myValue == "link" ) myValue = "\nlink: <a target=_blank href=\"URL\">URL</a>";
	if( myValue == "bold" ) myValue = "<b>TEXT</b>";
	if( myValue == "italic" ) myValue = "<i>TEXT</i>";
	if( myValue == "strikethrough" ) myValue = "<s>TEXT</s>";
	if( myValue == "underline" ) myValue = "<span style='text-decoration: underline;'>TEXT</span>";
	if( myValue == "colortext" ) myValue = "<span style='color:#FF0000'>TEXT</span>";
	if( myValue == "largetext" ) myValue = "<span style='font-size:20px'>TEXT</span>";
	if( myValue == "img" ) myValue = "<img border=0 src='URL' alt=''>";
	if( myValue == "list" ) myValue = "<ul><li>item 1</li><li>item 1</li><li>item 1</li></ul>";
	if( myValue == "quote" ) myValue = "<blockquote><p style='padding:5px;border:solid 1px white;background-color:#dfdfdf;'>TEXT</p></blockquote>";


	//if( strType == "img" ) myValue = "<img class=icon1 src='/images/" + myValue + "'/>";

	if( strType == 'textarea' )
	{
		if( document.selection ) 
		{
			myField.focus();
			sel = document.selection.createRange();
			if( sel.text.length > 0 )
			{
				myValue = myValue.replace( "URL", sel.text );
				myValue = myValue.replace( "URL", sel.text );
				myValue = myValue.replace( "TEXT", sel.text );
				myValue = myValue.replace( "TEXT", sel.text );
			}
			sel.text = myValue;
		}

		//Mozilla/Firefox/Netscape 7+ support
		else if( myField.selectionStart || myField.selectionStart == '0' )
		{
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			var strSelection = myField.value.substring(startPos, endPos);

			//alert( "endPos:" + endPos + ", startPos:" + startPos + " - " + strSelection );
			
			if( strSelection.length > 0 )
			{
				myValue = myValue.replace( "URL", strSelection );
				myValue = myValue.replace( "URL", strSelection );
				myValue = myValue.replace( "TEXT", strSelection );
				myValue = myValue.replace( "TEXT", strSelection );
			}
			myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
		} 
		else 
		{
			myField.value += myValue;
		}
	}
	else if( strType == 'input' )
	{
		myField.value = "/images/" + myValue;
		var myIcon = document.getElementById('current_icon');
		myIcon.src = myField.value;
	}
}

function SizeDiv( id )
{
	var obj;
	if( bIE7 || bIE6 )
	{
		obj = document.all( id );
	}
	else if( bFF || bOpera )
	{
		obj = document.getElementById(id);
	}
	if( obj.className == "container_limit" )
	{
		obj.className = "container_all";
	}
	else
	{
		obj.className = "container_limit";
	}
	//ReSizeBGR();
}

function SizeDiv2( id )
{
	var obj;
	if( bIE7 || bIE6 )
	{
		obj = document.all( id );
	}
	else if( bFF || bOpera )
	{
		obj = document.getElementById(id);
	}
	if( obj.className == "container_limit2 icon_container" )
	{
		obj.className = "container_all icon_container";
	}
	else
	{
		obj.className = "container_limit2 icon_container";
	}
	//ReSizeBGR();
}


var g_bImagesLoaded = false;
var g_bImagesLoaded2 = false;
var g_strContainerID = "";

function LoadedImages( strContainerID, nType, strParam )
{
	var bImagesLoaded = nType == 1 ? g_bImagesLoaded : g_bImagesLoaded2;
	if( bImagesLoaded )
	{
		//alert( "g_bImagesLoaded:" + g_bImagesLoaded );
		SizeDiv2( strContainerID );
		return;
	}
	g_strContainerID = strContainerID;

	var xmlhttp = GetXMLHttp();

	var strURL = "/get-icon-list.php" + strParam;
	if( nType == 2 )
	{
		strURL = "/get-emotion-list.php" + strParam;
	}
	
	xmlhttp.onreadystatechange = function() 
	{	
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			if( xmlhttp.responseText == "" ) // 0 == does not exist
			{
				alert( "Failed to load icons!" );
			}
			else
			{
				var obj;
				if( bIE7 || bIE6 )
				{
					obj = document.all( g_strContainerID );
				}
				else if( bFF || bOpera )
				{
					obj = document.getElementById( g_strContainerID );
				}
				obj.innerHTML = xmlhttp.responseText;
				if( nType == 1 )
					g_bImagesLoaded = true;
				else
					g_bImagesLoaded2 = true;

				SizeDiv2( g_strContainerID )
			}
		}
	}	
	xmlhttp.open( "GET", strURL, true );
	xmlhttp.send( "" );	

}



function UpdateEventInviteList(nUserID,nEventID,strIDList)
{
	var xmlhttp = GetXMLHttp();
	var strURL = "/get-event-invite-list.php?n=" + nUserID + "&ne=" + nEventID;
	//alert( strURL );

	/*xmlhttp.onreadystatechange = function() 
	{	
		//alert( xmlhttp.readyState );
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			alert( xmlhttp.responseText );
			var obj;
			if( bIE7 || bIE6 )
			{
				obj = document.all( "SelectedPeopleList" );
			}
			else if( bFF || bOpera )
			{
				obj = document.getElementById( "SelectedPeopleList" );
			}
			obj.innerHTML = xmlhttp.responseText;
		}
	}*/
	
	xmlhttp.open( "POST", strURL, false );
	xmlhttp.send( null );	
	
	if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
	{
		//alert( xmlhttp.responseText );
		var obj;
		if( bIE7 || bIE6 )
		{
			obj = document.all( "SelectedPeopleList" );
		}
		else if( bFF || bOpera )
		{
			obj = document.getElementById( "SelectedPeopleList" );
		}
		obj.innerHTML = xmlhttp.responseText;
	}
}

//var g_bUpdateEventPerson = false;
function UpdateEventPerson(nID, nEventID, nUserID, bAdd)
{
	var xmlhttp = GetXMLHttp();
	var strURL = "/update-event-person.php?n=" + nID + "&ne=" + nEventID + "&nn=" + nUserID + "&f=" + (bAdd?1:0);
	//alert( strURL );
	/*
	xmlhttp.onreadystatechange = function() 
	{	
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			alert( xmlhttp.responseText );

			var obj;
			if( bIE7 || bIE6 )
			{
				obj = document.all( "SelectedPeopleList" );
			}
			else if( bFF || bOpera )
			{
				obj = document.getElementById( "SelectedPeopleList" );
			}
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	*/
	xmlhttp.open( "POST", strURL, false );
	xmlhttp.send( null );	
	
		//alert( xmlhttp.responseText );
	/*if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
	{

		var obj;
		if( bIE7 || bIE6 )
		{
			obj = document.all( "SelectedPeopleList" );
		}
		else if( bFF || bOpera )
		{
			obj = document.getElementById( "SelectedPeopleList" );
		}
		obj.innerHTML = xmlhttp.responseText;
	}*/
	
}


function UpdateGalleryShareList(nUserID,nGalleryID,strIDList)
{
	var xmlhttp = GetXMLHttp();
	var strURL = "/get-gallery-share-list.php?n=" + nUserID + "&g=" + nGalleryID;
	//alert( strURL );

	/*xmlhttp.onreadystatechange = function() 
	{	
		//alert( xmlhttp.readyState );
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			alert( xmlhttp.responseText );
			var obj;
			if( bIE7 || bIE6 )
			{
				obj = document.all( "SelectedPeopleList" );
			}
			else if( bFF || bOpera )
			{
				obj = document.getElementById( "SelectedPeopleList" );
			}
			obj.innerHTML = xmlhttp.responseText;
		}
	}*/
	
	xmlhttp.open( "POST", strURL, false );
	xmlhttp.send( null );	
	
	if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
	{
		//alert( xmlhttp.responseText );
		var obj;
		if( bIE7 || bIE6 )
		{
			obj = document.all( "SelectedPeopleList" );
		}
		else if( bFF || bOpera )
		{
			obj = document.getElementById( "SelectedPeopleList" );
		}
		obj.innerHTML = xmlhttp.responseText;
	}
}

//var g_bUpdateEventPerson = false;
function UpdateGallerySharePerson(nID, nGalleryID, nUserID, bAdd)
{
	var xmlhttp = GetXMLHttp();
	var strURL = "/update-gallery-share-person.php?n=" + nID + "&g=" + nGalleryID + "&nn=" + nUserID + "&f=" + (bAdd?1:0);
	//alert( strURL );
	/*
	xmlhttp.onreadystatechange = function() 
	{	
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			alert( xmlhttp.responseText );

			var obj;
			if( bIE7 || bIE6 )
			{
				obj = document.all( "SelectedPeopleList" );
			}
			else if( bFF || bOpera )
			{
				obj = document.getElementById( "SelectedPeopleList" );
			}
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	*/
	xmlhttp.open( "POST", strURL, false );
	xmlhttp.send( null );	
	
		//alert( xmlhttp.responseText );
	/*if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
	{

		var obj;
		if( bIE7 || bIE6 )
		{
			obj = document.all( "SelectedPeopleList" );
		}
		else if( bFF || bOpera )
		{
			obj = document.getElementById( "SelectedPeopleList" );
		}
		obj.innerHTML = xmlhttp.responseText;
	}*/
	
}

function UpdateQuickMsgList(nID)
{
	var strURL = "/quickmsglist-get.php?n=" + nID;
	//alert( strURL );
	
	var xmlhttp = GetXMLHttp();

	xmlhttp.onreadystatechange = function() 
	{	
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			//alert( xmlhttp.responseText );
			var obj;
			if( bIE7 || bIE6 )
			{
				obj = document.all( "quickmsglist" );
			}
			else if( bFF || bOpera )
			{
				obj = document.getElementById( "quickmsglist" );
			}
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.open( "POST", strURL, true );
	xmlhttp.send( null );	
}

function SaveQuickmsg(nUserIDLoggedIn,nUserID,strMsg)
{
	strMsg = URLEncode( strMsg );
	if( strMsg != "" )
	{
		var strURL = "/quickmsg-save.php?n=" + nUserID + "&nf=" + nUserIDLoggedIn + "&msg=" + strMsg;
		//alert( strURL );
		
		var xmlhttp = GetXMLHttp();
		
		xmlhttp.open( "POST", strURL, false );
		xmlhttp.send( null );	
		
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			UpdateQuickMsgList(nUserID);
		}
	}
}


function DeleteQuickmsg(nUserIDLoggedIn, nUserID, nMsgID)
{
	if( nMsgID > 0 )
	{
		var strURL = "/quickmsg-del.php?n=" + nUserID + "&nf=" + nUserIDLoggedIn + "&mn=" + nMsgID;
		//alert( strURL );
		var xmlhttp = GetXMLHttp();
		
		xmlhttp.open( "POST", strURL, false );
		xmlhttp.send( null );	
		
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
		{
			//alert( xmlhttp.responseText );
			UpdateQuickMsgList(nUserID);
		}
	}
}


function UpdateNudeWarning(nf,nPicID,nUserID,nGalleryID)
{
	//nude-warning-pictures.php?f=0&p=$nID&n=$nUserID&g=$nGalleryID
	var strURL = "/picture-report-nude.php?p=" + nPicID + "&n=" + nUserID + "&g=" + nGalleryID + "&v=" + nf;
	//alert( strURL );
	var xmlhttp = GetXMLHttp();
	
	xmlhttp.open( "POST", strURL, false );
	xmlhttp.send( null );	
	
	if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
	{
		//alert( xmlhttp.responseText );
		//UpdateQuickMsgList(nUserID);
	}
}


function RotatePicture(nPictureObjectID,nPicID,nUserID,nRotate)
{
	//picture-rotate.php?n=nUserID&p=nPicID&v=90
	var strURL = "/picture-rotate.php?p=" + nPicID + "&n=" + nUserID + "&v=" + nRotate;
	alert( strURL );
	var xmlhttp = GetXMLHttp();
	
	xmlhttp.open( "POST", strURL, false );
	xmlhttp.send( null );	
	
	if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
	{
		var obj;
		if( bIE7 || bIE6 )
		{
			obj = document.all( nPictureObjectID );
		}
		else if( bFF || bOpera )
		{
			obj = document.getElementById( nPictureObjectID );
		}
		//alert( obj.src );
		obj.src = xmlhttp.responseText;
		//obj.innerHTML = xmlhttp.responseText;
		//nPictureObjectID
		//alert( xmlhttp.responseText );
		//UpdateQuickMsgList(nUserID);
	}
}


function URLEncode(url) //Function to encode URL.
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" + // Numeric
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
	"abcdefghijklmnopqrstuvwxyz" +
	"-_.!~*'()"; // RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = url;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) 
	{
		var ch = plaintext.charAt(i);
		if (ch == " ") 
		{
			encoded += "+"; // x-www-urlencoded, rather than %20
		}
		else if (SAFECHARS.indexOf(ch) != -1) 
		{
			encoded += ch;
		}
		else
		{
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) 
			{
				alert( "Unicode Character '"
					+ ch
					+ "' cannot be encoded using standard URL encoding.\n" +
					"(URL encoding only supports 8-bit characters.)\n" +
					"A space (+) will be substituted." );
					encoded += "+";
			}
			else
			{
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
};


 

function URLDecode(url) //function decode URL
{
	// Replace + with ' '
	// Replace %xx with equivalent character
	// Put [ERROR] in output if %xx is invalid.
	var HEXCHARS = "0123456789ABCDEFabcdef";
	var encoded = url;
	var plaintext = "";
	var i = 0;
	while (i < encoded.length) 
	{
		var ch = encoded.charAt(i);
		if (ch == "+") 
		{
			plaintext += " ";
			i++;
		} 
		else if (ch == "%") 
		{
			if (i < (encoded.length-2)
				&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
				&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) 
			{
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} 
			else 
			{
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		}
		else
		{
			plaintext += ch;
			i++;
		}
	} // while

	return plaintext;
}; 
