var dragObj = null;
var opacityOn = false;
// filter variables
//var filterArtistName = "";
//var filterArtistID = 0;
//var filterSize = "";
//var filterColor = "";
//var filterQuality = "";
//var filterPrice = "";
//var filterOrientation = "";
//var filterCopySpace = 0;
//var filterOrderBy = "";

function selectok() {
	if (!dragObj)
	{
		return true;
	} else {
		return false;
	}

}


var btHome = 1;
var btClose = 2;
var btCart = 3;
var btAccount = 4;
var btNewFolder = 5;
var btComplaint = 6;

function showSales(userid) {
	url = "index.php?n=Users&o=sales&id=" + userid;
	initObj();
	showWait();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=updateSales;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function updateSales() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("content");
	y= x[0].firstChild.data;
	el = document.getElementById("mainBody");
	el.innerHTML = y;
  }
}

function showPurchases(userid) {
	url = "index.php?n=Users&o=purchases";
	initObj();
	showWait();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=updatePurchases;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function showFiles(orderid) {
	url = "index.php?n=Users&o=view_files&id=" + orderid;
	initObj();
	showWait();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=updatePurchases;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function updatePurchases() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("content");
	y= x[0].firstChild.data;
	el = document.getElementById("mainBody");
	el.innerHTML = y;
  }
}

function changeFileStatus(fileid, status) {
	el=document.getElementById("ImgStatus" + fileid);
	if (status == "1") el.src="images/icn_yes.gif"; 
	if (status == "0") el.src="images/icn_no.gif";
	if (status == "1" || status == "0" ) {
		url = "index.php?n=Users&o=toggle_file&id=" + fileid + "&status=" + status;
		initObj();
		if (xmlhttp!=null) {
		  xmlhttp.onreadystatechange=doChangeFileStatus;
		  xmlhttp.open("GET",url,true);
		  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
		  xmlhttp.send(null);
		}
	}
}

function doChangeFileStatus() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
  }
}

function changeFileFolder(fileid) {
	url = "index.php?n=Users&o=get_folders&id=" + fileid;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_changeFileFolder;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

}

function _changeFileFolder() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("fileid");
	fileid= x[0].firstChild.data;
	x=response.getElementsByTagName("content");
	y= x[0].firstChild.data;
	el1 = document.getElementById("file" + fileid + "_folder");
	el = document.getElementById("change_folder_tbl");
	el.style.display="block";
	el.style.top = findPosY(el1) + "px";
	el.style.left = findPosX(el1) + "px";
	el = document.getElementById("change_folder_td");
	el.innerHTML = y;
  }
}

function updateFileFolder(fileid, folder) {
	url = "index.php?n=Users&o=update_file_folders&id=" + fileid + "&folder=" + folder;
	initObj();
	el = document.getElementById("change_folder_td");
	el.innerHTML = "Please wait ... ";

	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_updateFileFolder;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _updateFileFolder() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("fileid");
	fileid= x[0].firstChild.data;
	x=response.getElementsByTagName("content");
	y= x[0].firstChild.data;
	el1 = document.getElementById("file" + fileid + "_folder");
	el = document.getElementById("change_folder_tbl");
	el.style.display="none";
	el1.innerHTML = y;
  }
}


function requestPayout(userid) {
	url = "index.php?n=Users&o=req_payment&xml=1";
	initObj();
	showWait();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=updatePayout;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function updatePayout() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("content");
	y= x[0].firstChild.data;
	el = document.getElementById("mainBody");
	el.innerHTML = y;
  }
}


function editProfile(section) {
	url = "index.php?n=Users&o=edit&section="+section+"&xml=1";
	initObj();
	showWait();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=updateProfile;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function updateProfile() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("content");
	y= getXMLNode(x);
	el = document.getElementById("mainBody");
	el.innerHTML = y;
  }
}

function selectPrice(id) {
	url = "index.php?n=Files&o=show_pricing&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_selectPrice;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

var pricingStructure = [];
function _selectPrice() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	
	pricingStructure = [];
	x1=response.getElementsByTagName("size_id");
	x2=response.getElementsByTagName("time_id");
	x3=response.getElementsByTagName("price");
	for (i=0; i<x1.length;i++ )
	{
		pricingStructure[pricingStructure.length] = {sizeid: x1[i].firstChild.data, timeid: x2[i].firstChild.data, price: x3[i].firstChild.data};
	}
	x=response.getElementsByTagName("content");
	y= x[0].firstChild.data;
	showMessage(y);
  }
}

function updateLicensePrice() {
	el = document.getElementById("selectedPrice");
	el1 = document.getElementById("LicenseTerm");
	el2 = document.getElementById("Quality");
	if (!el1.selectedIndex || !el2.selectedIndex)
	{
		el.innerHTML =  " ";
	} else {
		for (i=0; i<pricingStructure.length ; i++ )
		{
			if (pricingStructure[i].sizeid == el2.options[el2.selectedIndex].value && pricingStructure[i].timeid == el1.options[el1.selectedIndex].value)
			{
				el.innerHTML =  '$' + pricingStructure[i].price;
			}
		}
	}
}

function addToCartWithLicense() {
	el1 = document.getElementById("selectedPrice");
	el2 = document.getElementById("LicenseTerm");
	el3 = document.getElementById("Quality");
	el4 = document.getElementById("selectedFile");
	if (!el2.selectedIndex || !el3.selectedIndex)
	{
		alert("You must choose the licensing options before you can continue");
		return true;
	}
	url = "index.php?n=Files&o=addtocart2&id=" + el4.value + "&term=" + el2.value + "&quality=" + el3.value;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_addToCartWithLicense;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _addToCartWithLicense() {
	  if(checkReadyState(xmlhttp)) {
//		var response = xmlhttp.responseXML.documentElement;
//		response.normalize;
//		x=response.getElementsByTagName("content");
//		y= x[0].firstChild.data;
		closeMessage();
		showAlert("info", "File added to cart", "Your file was addded to the cart", btClose, btCart);
	  }
}

function addToCart(id) {
	return selectPrice(id);
	url = "index.php?n=Files&o=addtocart&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_addToCart;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _addToCart() {
	  if(checkReadyState(xmlhttp)) {
//		var response = xmlhttp.responseXML.documentElement;
//		response.normalize;
//		x=response.getElementsByTagName("content");
//		y= x[0].firstChild.data;
		showAlert("info", "File added to cart", "Your file was addded to the cart", btClose, btCart);
	  }
}

function displayFile2(id, e) {
//	el = document.getElementById("imageOverIMG");
//	el.src = "";
	
	el1 = document.getElementById("divImage" + id);

	url = "index.php?n=Files&o=display_over2&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_displayFile2;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _displayFile2() {
	  if(checkReadyState(xmlhttp)) {
		setOpacity(10);
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		x=response.getElementsByTagName("content");
		y1= getXMLNode(x);
		x=response.getElementsByTagName("id");
		y2= x[0].firstChild.data;



		el = document.getElementById("divImageOverTD");
		if (!el)
		{
			tmp = '<table id="imageOverTable" border="0" cellspacing="0" cellpadding="0" style="background-color: #fff; border: 1px solid #333;" ondblclick="hideFile();" >';
			tmp += '<tr>';
			tmp += '<td align="left" valign="top" id="imageOverTD" style="padding: 10px;">&nbsp;</td>';
			tmp += '</tr>';
			tmp += '</table>';
			bdy = document.getElementsByTagName("body");
			el = document.createElement("div");
			el.id = "divImageOverTD";
			el.style.display="none";
			el.style.position =  "absolute";
			el.innerHTML = tmp;
			bdy[0].appendChild(el);
		}

		el = document.getElementById("imageOverTD");
		el.innerHTML = y1;
		

		el = document.getElementById("divImageOverTD");
		el.style.display='block';
		el2 = document.getElementById("tdMainBody");
		w = el.offsetWidth;
		h = el.offsetHeight;
		posx = findPosX(el2);
		posy = findPosY(el2);
		
		maxx = getScrollLength("left") + document.documentElement.clientWidth - w - 20; //cannot position to the right of this 
		maxy = document.documentElement.clientHeight - h -20; //cannot position below this
		
		if (posx > maxx) posx = maxx; if (posx <=10) posx = 10;
		if (posy > maxy) posy = maxy;if (posy <=10) posy = 10;
		posy=0;
		posy = getScrollLength("top")  + posy;

//		posy = mouseY;
//		maxy = getScrollLength("top") + document.documentElement.clientHeight - h;
//		if (posy >= maxy) posy = maxy;
//
//		posx = mouseX;
//		maxx = getScrollLength("left") + document.documentElement.clientWidth - w;
//		if (posx >= maxx) posx = maxx;
		center = getCenter2(w,h);
//		el.style.top =(parseInt(posy) + 10) + "px";
//		el.style.left = (parseInt(posx) + 10) + "px";
		el.style.top =(parseInt(center.y)) + "px";
		el.style.left = (parseInt(center.x) ) + "px";

	  }
}

function displayFile(id, e) {
	el = document.getElementById("imageOverIMG");
	el.src = "";
	
	el1 = document.getElementById("divImage" + id);

	url = "index.php?n=Files&o=display_over&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_displayFile;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _displayFile() {
	  if(checkReadyState(xmlhttp)) {
		el = document.getElementById("divImageOverTD");

		el.style.top =(mouseY + 10) + "px";
		el.style.left = (mouseX + 10) + "px";

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		x=response.getElementsByTagName("content");
		y1= x[0].firstChild.data;
		x=response.getElementsByTagName("id");
		y2= x[0].firstChild.data;

		el = document.getElementById("imageOverIMG");
		el.src = y1;
		el.onload = _displayFileEnd;

	  }
}

function moveFile() {
	el = document.getElementById("divImageOverTD");

	el.style.top =(mouseY + 10) + "px";
	el.style.left = (mouseX + 10) + "px";
}

function _displayFileEnd() {
	el = document.getElementById('divImageOverTD');
	el.style.display='block';
}

function hideFile(id) {
//	alert(event.toElement.id);
//if (event.fromElement.id == "imageOverTable") return false;
//if (event.fromElement.id == "imageOverTD") return false;
//if (event.fromElement.id == "imageOverIMG") return false;
//if (event.fromElement.id == "thumb") return false;
	setOpacity(100);
	try
	{
		el = document.getElementById('divImageOverTD');
		el.style.display='none';
		
	}
	catch (e)
	{
		;
	}
}

function showSearch() {
	window.location = '#mainDiv';
	url = "index.php?n=Files&o=get_search";
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_showSearch;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _showSearch() {
	  if(checkReadyState(xmlhttp)) {
  		setOpacity(10);
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		x=response.getElementsByTagName("content");
		y1=getXMLNode(x);


		el = document.getElementById("adsearchDiv");
		el.innerHTML = y1;
		el.style.display = "inline";

		el1 = document.getElementById("topTable");
		el.style.top = (findPosY(el1) - 30) + "px";
		el.style.left = (findPosX(el1) - 5) + "px";

		el = document.getElementById("tdMainBody");
		help = document.getElementById("searchtable");
		tmpHeight = el.offsetHeight;
		el.style.height = help.offsetHeight + "px";;
	  }
}

function hideSearch() {
		setOpacity(100);
		el = document.getElementById("adsearchDiv");
		el.innerHTML = y1;
		el.style.display = "none";
		hideTips();
		window.location = "#mainDiv";
}

function showTips() {
	url = "index.php?n=Files&o=get_search_tips";
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_showTips;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _showTips() {
	  if(checkReadyState(xmlhttp)) {
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		x=response.getElementsByTagName("content");
		y1=getXMLNode(x);


		el = document.getElementById("adsearchTips");
		el.innerHTML = y1;
		el.style.display = "block";


		el1 = document.getElementById("adsearchDiv");
//		el.style.top = (findPosY(el1) - 30) + "px";
		el.style.left = (parseInt(el1.style.left) - 262) + "px";
		el.style.top= el1.style.top;

//		el1 = document.getElementById("adsearchDiv");
//		el1.style.top = el.style.top;
//		el1.style.left = (parseInt(findPosX(el)) + 242) + "px";

		el.style.height = el1.offsetHeight + "px";;
//		el.style.height = el1.offsetHeight + "px";;

		el = document.getElementById("tipsIcon");
		el.src = "images/btn_closesearchtips2.gif";

		el.onclick = hideTips;
	  }
}

function hideTips() {
		el = document.getElementById("adsearchTips");
		el.innerHTML = y1;
		el.style.display = "none";
		try
		{
			el = document.getElementById("tipsIcon");
			el.src = "images/btn_searchtips2.gif";
			el.onclick = showTips;
		}
		catch (e)
		{
		}

}

cells = [0,0,0,0,0,0,0,0,0];
function searchHighlight(id) {
	if (cells[id] == 1) return false;
	el = document.getElementById("copyspacetd" + id);
	el.style.backgroundColor = "#ff6600";
}

function searchUnHighlight(id) {
	if (cells[id] == 1) return false;
	el = document.getElementById("copyspacetd" + id);
	el.style.backgroundColor = "#cccccc";
}

function searchToggle(id) {
	el = document.getElementById("copyspacetd" + id);
	if (cells[id] == 1) {
		cells[id] = 0;	
		el.style.backgroundColor = "#cccccc";
	} else {
		cells[id] = 1;		
		el.style.backgroundColor = "#ff6600";
	};

}

function searchSaveHighlight() {
	el = document.getElementById("srcCopySpace");
	el.value="";
	tmp = "";
	for (i=0; i<=8 ; i++)
	{
		tmp	= tmp + "" + cells[i] + ";" ;
	}
	el.value = tmp;
}

function searchClearHighlight() {
	el = document.getElementById("srcCopySpace");
	el.value="";
	for (i=0; i<=8 ; i++)
	{
		el = document.getElementById("copyspacetd" + i);
		el.style.backgroundColor = "#cccccc";
	}
	
}

showIndex = 0;
function showFolderSlideShow() {
	myimg = new Image();
	for (i=0; i<folderItems.length; i++)
	{
		myimg.src = folderItems[i];
	}	
	fillSlots();
}

function fillSlots() {
	for (i=0;i<=4 ;i++ )
	{
		if (i<folderItems.length)
		{
			xx= parseInt(i) + 1;
			el=document.getElementById("slot" + xx);
			el.innerHTML = "<a href='index.php?n=Files&o=view&id="+getSlideImageLink(i)+"'><img width='80' src='" + getSlideImage(i) + "'></a>";
		}
	}
}

function getSlideImage(id) {
	pos = id + showIndex;
	if (pos < 0) pos = pos + folderItems.length;
	if (pos >= folderItems.length) pos = pos - folderItems.length;
	return folderItems[pos];
}

function getSlideImageLink(id) {
	pos = id + showIndex;
	if (pos < 0) pos = pos + folderItemsLinks.length;
	if (pos >= folderItemsLinks.length) pos = pos - folderItemsLinks.length;
	return folderItemsLinks[pos];
}

function slideRight() {
	showIndex ++;
	if (showIndex >= folderItems.length ) showIndex = 0;
	fillSlots();
}

function slideLeft() {
	showIndex = showIndex - 1;
	if (showIndex < 0) showIndex = folderItems.length - 1;
	fillSlots();
}

function loadStates(pCountry) {
	
	url = "index.php?n=Ajax&o=getStates&id=" + pCountry;
	el = document.getElementById('StateID');
	el.options.length= 0;
	option = new Option();
	option.text = ' loading, please wait .... ';
	option.value = 0;
	el.options[0] = option;

	if (window.XMLHttpRequest)
	  {
	  xmlhttp=new XMLHttpRequest();
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (xmlhttp!=null)
	  {
	  xmlhttp.onreadystatechange=_loadStates;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }


}

function _loadStates() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x1=response.getElementsByTagName("id");
	x2=response.getElementsByTagName("name");
	el = document.getElementById('StateID');
	
	el.options.length = 0;
	for (i=0;i<x1.length ;i++ )
	{
		option = new Option();
		option.text = x2[i].firstChild.data;
		option.value = x1[i].firstChild.data;
		el.options[el.options.length] = option;
	}

  }
 }

function setOpacity(level) {
	opacityOn = true;
	if (level == 100) opacityOn = false;
	if (opacityOn)
	{
		closeHelp();
	}
	el = document.getElementById("loginTable");
	if (el)
	{
		el.style.filter="alpha(opacity="+level+")";
		el.style.mozOpacity=level/100;
		el.style.opacity=level/100;
	}
	
	el = document.getElementById("topTable");
	if (el)
	{
		el.style.filter="alpha(opacity="+level+")";
		el.style.mozOpacity=level/100;
		el.style.opacity=level/100;
	}

	el = document.getElementById("masterTable");
	if (el)
	{
		el.style.filter="alpha(opacity="+level+")";
		el.style.mozOpacity=level/100;
		el.style.opacity=level/100;
	}

}

function showAlert(type, title, msg, bt1, bt2) {
	setOpacity(10);
	el = document.getElementById("mainAlert");
	el.style.zIndex = 2;

	x = document.getElementById("alertIcon");
	x.style.display='inline';
	switch (type)
	{
		case "info": x.src="images/popup/alert2.png";break;
		case "alert": x.src="images/popup/alert2.png";break;
		case "error": x.src="images/popup/alert1.png";break;
		case "data": x.style.display='none';break;
	}

	x = document.getElementById("alertTitle");
	x.innerHTML = title;
	x = document.getElementById("alertMsg");
	x.innerHTML = msg;


	getDefaultAction(1, bt1);
	getDefaultAction(2, bt2);
	
	el.style.display='block';

	y=getScrollLength("top") + document.documentElement.clientHeight / 2 - 150;
	x=getScrollLength("left") + document.documentElement.clientWidth /2 -100;

	el.style.top = y + "px";
	el.style.left = x + "px";

}

function moveAlert(x,y) {
	el = document.getElementById("mainAlert");
	el.left = x;
	el.top = y;
}

function getDefaultAction(button, action) {
	btn = document.getElementById("alertBtn" + button);
	btn.style.display="block";
	switch (action)
	{
	case 1: 
		btn.onclick=actionHome;
		btn.src="images/btn_ok_orange.gif";
		break;
	case 2: 
		btn.onclick=hideAlert;
		btn.src="images/btn_close.gif";
		break;
	case 3: 
		btn.onclick=actionCart;
		btn.src="images/btn_gotocart.gif";		
		break;
	case 4: 
		btn.onclick=actionAccount;
		btn.src="images/btn-myaccount.png";		
		break;
	case 5:
		btn.onclick=createNewFolder;
		btn.src="images/btn_ok_orange.gif";		
		break;
	case 6:
		btn.onclick=submitComplaintBox;
		btn.src="images/btn_ok_orange.gif";		
		break;
	default: btn.style.display="none";
	}
}

function actionHome() {
	if (dragObj) endDrop();
	window.location='index.php';
}

function actionCart() {
	if (dragObj) endDrop();
	window.location='index.php?n=Cart';
}

function actionAccount() {
	if (dragObj) endDrop();
	window.location='index.php?n=Users&o=mine';
}

function hideAlert() {
	if (dragObj) endDrop();

	el = document.getElementById("mainAlert");
	el.style.display='none';

	setOpacity(100);
}

allowRating = true;
function getRateSrc(rating, i) {
	if ((2 * i < rating) && (2*(i+1) > rating)) return "star_orange_half_l.gif";
	if (2 * i < rating) return "star_orange_full.gif";
	if (2*(i+1) > rating) return "star_grey.gif";
}

function rateOn(id, i) {
	if (!allowRating) return false;
	rating = document.getElementById("rated_image_value");
	el=document.getElementById("rate_" + id + "_" + i);
	pieces = el.src.split('/');
	src = pieces[pieces.length-1];
	orig_src = getRateSrc(rating.value, i);
	if (src == orig_src) {
		state = 1;
	} else {
		state = 0;
	}

	for (j=0; j<=4 ; j++ )
	{
		el=document.getElementById("rate_" + id + "_" + j);
		if (j <=i) el.src = "images/star_black.gif"; else el.src = "images/star_grey.gif";
	}
}

function rateOff(id, i) {
	return false;
}

function rateSelect(id, i) {
	if (!allowRating) return false;
	url = "index.php?n=Files&o=rate&id=" + id + "&rate=" + i;
	el=document.getElementById("rated_image_value");
	el.value = (i+1) * 2;
	rateRestore(id, true);
	if (window.XMLHttpRequest)
	  {
	  xmlhttp=new XMLHttpRequest();
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (xmlhttp!=null)
	  {
	  xmlhttp.onreadystatechange=_rateSelect;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }
	
}

function _rateSelect() {
  if(checkReadyState(xmlhttp)) {
//	alert("rate recorded");
  }
}

function rateRestore(id, disableRating) {
	if (!allowRating) return false;
	rating = document.getElementById("rated_image_value");
	if (!rating) {allowRating = false; return false;};
	for (i=0; i<=4; i++)
	{
		el=document.getElementById("rate_" + id + "_" + i);
		orig_src = getRateSrc(rating.value, i)
		el.src= "images/" + orig_src;
	}
	allowRating = !disableRating;
}

function showWait() {
	el = document.getElementById("mainBody");
	el.innerHTML = "please wait ... ";
}

function catchEnter() {
	if (window.event.keyCode==13){
		hideAlert();
	}
}


var helpID = 0;
var tmpHeight = 0;
var tmpHeight2 = 0;
helpLoaded = false;
function showHelp(helpPage) {
	if (!helpPage || typeof(helpPage) == "undefined") helpPage = '';

	if (opacityOn) return true;
	el = document.getElementById("tdMainBody");
	help = document.getElementById("helpTable");
	help.style.zIndex = 999;
	help.style.display = 'block';
	help.style.left=findPosX(el) + "px";
	help.style.top=findPosY(el) + "px";
	tmpHeight = el.offsetHeight;
	el.style.height = help.offsetHeight + "px";;
	el.style.filter="alpha(opacity=0)";
	el.style.mozOpacity=0;
	el.style.opacity=0;


	el = document.getElementById("tdLeftBody");
	help = document.getElementById("helpMenu");
	help.style.display = 'block';
	help.style.left=findPosX(el) + "px";
	help.style.top=findPosY(el) + "px";
//	help.style.width=el.offsetWidth;
	tmpHeight2 = el.offsetHeight;
	el.style.height = help.offsetHeight + "px";;
	el.style.filter="alpha(opacity=0)";
	el.style.mozOpacity=0;
	el.style.opacity=0;

	if (!helpLoaded) loadHelp(helpPage);
}

function closeHelp () {
	el = document.getElementById("tdMainBody");
	help = document.getElementById("helpTable");
	help.style.display = 'none';
	el.style.height = tmpHeight + "px";
	el.style.filter="alpha(opacity=100)";
	el.style.mozOpacity=1;
	el.style.opacity=1;

	el = document.getElementById("tdLeftBody");
	help = document.getElementById("helpMenu");
	help.style.display = 'none';
	el.style.height = tmpHeight + "px";
	el.style.filter="alpha(opacity=100)";
	el.style.mozOpacity=1;
	el.style.opacity=1;
}

function printPage() {

	y=(document.documentElement.clientHeight - 800)/2;
	x=(document.documentElement.clientWidth-600)/2;
	window.open("index.php?n=Pages&o=print_help&id=" + helpID, "print_window", "width=600, height=800, top="+y+", left="+x+"");
}

function loadHelp(helpPage) {
	if (!helpPage) page = getQueryVariable("n") + getQueryVariable("o"); else page = helpPage;
	url = "index.php?n=Pages&o=getHelp&id=" + page;
	initObj();
	showHelpWait();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_loadHelp;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	
}

function showHelpWait() {
	help1 = document.getElementById("helpMenuContent");
	help1.innerHTML = "";
	help2 = document.getElementById("helpContentTxt");
	help2.innerHTML = "";
	help3 = document.getElementById("helpTitle");
	help3.innerHTML = "";
}

function _loadHelp() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("content");
	y1= getXMLNode(x);
	x=response.getElementsByTagName("leftmenu");
	y2= getXMLNode(x);
	x=response.getElementsByTagName("title");
	y3= getXMLNode(x);
	x=response.getElementsByTagName("id");
	helpID = getXMLNode(x);

	help1 = document.getElementById("helpMenuContent");
	help1.innerHTML = y2 ;
	help2 = document.getElementById("helpContentTxt");
	help2.innerHTML = y1;
	help3 = document.getElementById("helpTitle");
	help3.innerHTML = '<br><strong>'+ y3+'</strong><br /></br>';

	el = document.getElementById("tdMainBody");
	help = document.getElementById("helpTable");
	el.style.height = help.offsetHeight + "px";
	el = document.getElementById("tdLeftBody");
	help = document.getElementById("helpMenu");
	el.style.height = help.offsetHeight + "px";
	helpLoaded = true;
  }
}

function testHelp() {
el = document.getElementById("masterTable");
//	el.getPosX();
//	el.getPosY();
	alert();
}

function toggleHelpSection(id) {
	mainel=document.getElementById('menuTable' + id);
//	src = el.style.display;
//	if (src == 'none') show = "block"; else show="none";

	for (i=1; i<=6 ;i++ )
	{
		el=document.getElementById('menuTable' + i);
		el.style.display='none';
		el=document.getElementById('menuTableIcon' + i);
		el.src='images/icon_plus.gif';
	}

	mainel.style.display = "block";
	el=document.getElementById('menuTableIcon' + id);
	el.src='images/icon_minus.gif';

}


function showHelpEntry(id) {
	helpID = id;
	url = "index.php?n=Pages&o=getHelpEntry&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_showHelpEntry;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _showHelpEntry() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;
	x=response.getElementsByTagName("content");
	y1= getXMLNode(x);
	x=response.getElementsByTagName("title");
	y3= getXMLNode(x);

	help2 = document.getElementById("helpContentTxt");
	help2.innerHTML = "<font size=2>" + y1 + "</font>";

	help3 = document.getElementById("helpTitle");
	help3.innerHTML = '<br><strong><font size=2>'+ y3+'</font></strong><br /><br>';

	el = document.getElementById("tdMainBody");
	help = document.getElementById("helpTable");
	el.style.height = help.offsetHeight + "px";;

  }
}

tooltipid = 0;
function showHelpAlert(id) {
	url = "index.php?n=Pages&o=getToolTip&id=" + id;
	tooltipid = id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_showHelpAlert;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _showHelpAlert() {
	if(checkReadyState(xmlhttp)) {
		setOpacity(10);
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		x=response.getElementsByTagName("content");
		y1= getXMLNode(x);
		x=response.getElementsByTagName("title");
		y3= getXMLNode(x);

//		el = document.getElementById("loginTable");
//		el.style.filter="alpha(opacity=10)";
//		el.style.mozOpacity=0.1;
//		el.style.opacity=0.1;
//		
//		el = document.getElementById("topTable");
//		el.style.filter="alpha(opacity=10)";
//		el.style.mozOpacity=0.1;
//		el.style.opacity=0.1;
//
//		el = document.getElementById("masterTable");
//		el.style.filter="alpha(opacity=10)";
//		el.style.mozOpacity=0.1;
//		el.style.opacity=0.1;

		el = document.getElementById("mainAlert");

		x = document.getElementById("alertIcon");
		x.src="images/icon_help2.gif";

		x = document.getElementById("alertTitle");
		x.innerHTML = y3;
		x = document.getElementById("alertMsg");
		x.innerHTML = y1;


		getDefaultAction(1, 0);
		getDefaultAction(2, btClose);
		
		el.style.display='block';
		el.style.visibility='hidden';

		icon = document.getElementById("tooltipid" + tooltipid);
		y=findPosY(icon) - 155;
		x=findPosX(icon) - 230;

		el.style.top = y + "px";
		el.style.left = x + "px";

		el.style.visibility='visible';
	}
}

function getXMLNode(x) {
	if (BrowserDetect.browser == "Firefox") {
		return x[0].textContent;
	} else return x[0].firstChild.data

}

function frmEditPassword() {
	el = document.getElementById("OldPassword");
	if (el.value == "")
	{
		showAlert("error", "", "Your password is incorrect",0,btClose);
		return false;
	}
	el = document.getElementById("Password");
	el2 = document.getElementById("Password2");
	if (el.value.length < 6)
	{
		showAlert("error", "", "Password must be at least 6 characters",0,btClose);
		return false;
	}

	if (el.value != el2.value)
	{
		showAlert("error", "", "Passwords don't match",0,btClose);
		return false;
	}
	return true;
}

function checkPassword() {
	el = document.getElementById("OldPassword");
	url = "index.php?n=Ajax&o=checkPassword&pwd=" + encodeURIComponent(el.value);
	if (window.XMLHttpRequest)
	  {
	  xmlhttp=new XMLHttpRequest();
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (xmlhttp!=null)
	  {
	  xmlhttp.onreadystatechange=_checkPassword;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }
	
}

function _checkPassword() {
	  if(checkReadyState(xmlhttp)) {
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		x=response.getElementsByTagName("content");
		y= x[0].firstChild.data;
		_username = document.getElementById("OldPassword");
		if (y!="ok")
		{
			_username.style.backgroundColor = "#FFF1EA";
			_username.style.borderStyle = "solid";
			_username.style.borderWidth = "2px";
			_username.style.borderColor = "#ff6633";
//			_username.focus();
//			_username.select();
			_username.value="";
			showAlert("error", "", y, 0, btClose);
		} else {
			_username.style.backgroundColor = "#fff";
			_username.style.borderStyle = "solid";
			_username.style.borderWidth = "2px";
			_username.style.borderColor = "#aaa";
		}
	  }
}

function printit(){  
if (window.print) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}

function showFileHistory() {
	el=document.getElementById("FileHistory");
	el.style.display="block";
}

function removeFilter(filterType) {
	window.location='index.php?n=Files&o=reset_filter&type=' + filterType;
}

function showError(msg) {
	showAlert('error', "", msg, btClose, 0);
}

function showComplaintBox(id) {
	txt = "<div style='width: 300;'><p>While we do our best to insure that the integrity of sharefolder.com is adhered to and that every member has read and understood all our terms of conditions, we ask that you help us maintain the site by adhering to the rules and regulations and reporting any malicious matter or content.</p>";
	txt += "<p>If you suspect or notice any instances of copyright violations or infringements please bring it to our attention immediately. Kindly contact complaints@sharefolder.com. You can be rest assured that this matter will be treated with the utmost respect and your identity will remain anonymous.</p>";
	txt += "<p>Once a complaint has been registered, the image will be removed while under investigation. If the image is found to be spurious the owner’s account will be suspended and further action shall be taken. If the image is legitimate or the complaint does not meet our copyright criterion it will be reinstated.</p></div>";
//	txt = "<input type=\"hidden\" name=\"complaintFileID\" id=\"complaintFileID\" value=\""+id+"\">";
//	txt += "<p>Your name and email address are optional, but, without supplying an email address we won't be able to communicate our decision regarding your complaint. You MUST provide a reason for your complaint.</p>";
//	txt += "<table><tr><td>Your name: </td><td><input type=\"text\" name=\"complaintName\" id=\"complaintName\" value=\"\"></td></tr>";
//	txt += "<tr><td>Your email: </td><td><input type=\"text\" name=\"complaintEmail\" id=\"complaintEmail\" value=\"\"></td></tr>";
//	txt += "<tr><td>Reason(s): </td><td><input type=\"text\" name=\"complaintReason\" id=\"complaintReason\" value=\"\"></td></tr></table>";

	showAlert("data", "File a complaint", txt, 0, btClose);
}

function submitComplaintBox() {
	url = "index.php?n=Files&o=complain";
	el = document.getElementById("complaintFileID");
	url += "&id=" + el.value;
	el = document.getElementById("complaintEmail");
	url += "&email=" + el.value;
	el = document.getElementById("complaintName");
	url += "&name=" + el.value;
	el = document.getElementById("complaintReason");
	url += "&reason=" + el.value;

	initObj();
	showWait();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_submitComplaintBox;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

}

function _submitComplaintBox() {

}