///***********************************************************************///
///***<!-- Contains Copyrighted Materials by (c) ISPRODUCTIONS 2006 -->***///
///***********************************************************************///

function change1(newClass,id)
{
    var o=document.getElementById(id)//'MasterContainer')
    if(o)o.className = newClass;
}

function showHideSideBar(newClass)
{
    change1(newClass, 'container');
    srvSetActiveMenu('container', newClass);
    $('#scrolltree').jScrollPane();
}

function showhide(newClass, id)
{
    change1(newClass,id);
    srvSetActiveMenu(id, newClass);
    
    var arr = new Array('LbContainer', 'CatContainer');
    var flagAllIsClosed = true;
    for(var i = 0; i < arr.length; i++)
    {
        var o=document.getElementById(arr[i])//'MasterContainer')
        if(o)
            if (o.className == "sshow")
                flagAllIsClosed = false;
    }
    
    if (flagAllIsClosed)
    {
        change1('hide', 'container');
        srvSetActiveMenu('container', 'hide');
    }
    else
    {
        change1('show', 'container');
        srvSetActiveMenu('container', 'show');
    }
}
 
//////////////////////////////////////////////////

function setBtnShowBrowseMenu(topInc)
{
    if(ie||ns6)
    {
        var contData = document.all? document.all["contData"] : document.getElementById? document.getElementById("contData") : "";
        var btnShowBrowseMenu = document.all? document.all["btnShowMenu"] : document.getElementById? document.getElementById("btnShowMenu") : "";
        //btnShowBrowseMenu.style.top=(contData.offsetTop + topInc)+'px';        
    }
}

function AssignCssClass(thisObject, id, activeClass, inactiveClass)
{
    var obj = document.getElementById(id);
    if(obj)
    {
        if(thisObject)
        {
            obj.className = (thisObject.checked ? activeClass : inactiveClass);
        }
    }
}

function SaveFavorites(id, showId, hideId) {
	var flag = false;
	if(id == 0)
	    flag = true;
	else
	    if(confirm("Are you sure? \nAll selected files will be stored in a Renamed Lightbox."))
	        flag = true;
	if(flag)
	{
		var spListName = document.getElementById("spListName");
		if (spListName) 
			if (spListName.style.display == "none") {
				spListName.style.display = "";	
				document.getElementById(showId).style.display = "";
				document.getElementById(hideId).style.display = "none";
				document.getElementById("lbId").value = id;
				document.getElementById("sphdnListName").focus();
			}
	}
}

function createNewList() {
	var ListName = document.getElementById("sphdnListName").value;
	if (ListName == "" || ListName == null)  {
		alert("Please input list name first.");
		document.getElementById("sphdnListName").focus();
	} else {
		var svmode = document.getElementById("saveMode").value;
		document.ImgDetailsFrm.ListName.value = ListName;
		document.ImgDetailsFrm.action = ScriptName + "&action=saveFavs&svmode="+svmode;
		document.ImgDetailsFrm.submit();
	}
}
function SaveLightbox(what, newLbNameId) {
	/*if (confirm("You need to save this Lightbox under another name first.\n Do you want to continue?")){
		while ((lname = prompt("Enter name for the lightbox","")) != null) {
			if (lname!=null )
				switch (lname.toLowerCase()) {
				case "" :
					alert("Please enter some name");
					break;
				case "default" :
					alert("The 'Default' name is reserved. Please enter another name");
					break;
				default :
					document.location.href = ScriptName + "&action=saveFavs&ListName="+lname+"&svmode="+what;
					return;
				}
		}
	}*/
	
	var obj = document.getElementById(newLbNameId);		    
    if(obj)
    {
        var lname = obj.value;
        if (lname != null )
	        switch(lname.toLowerCase()) {
	            case "" :
		            alert("Please input request name first.");
		            obj.focus();
		            break;
	            case "default" :
		            alert("The 'Default' name is reserved. Please enter another name");
		            obj.focus();
		            break;
		        default :
			        document.location.href = ScriptName + "&action=saveFavs&ListName="+lname+"&svmode="+what;
					return;
		    }
	}
}
function findEl(sID){
	IsSafari = navigator.userAgent.indexOf("Safari") > -1;
	IsNS6=(document.getElementById&&!document.all)
	var ret = null;
	if (IsSafari || IsNS6)  return document.getElementById(sID);
	if (document.all) return document.all[sID];
	if(document.layers){
		ret = document.layers[sID];
	}
	else if(document.all){
		ret = document.all.tags("DIV")[sID];
		if(!ret) ret = document.all.tags("SPAN")[sID];
	}
	else if(document.getElementByID){
		ret = document.getElementById(sID);
	}
	return ret;
}
function showSpanContent (spanid, IsToShow) {
	var objel	= findEl (spanid);
	if (objel != null)
	{ 
		if (objel.style) {
			if (IsToShow)
				objel.style.display = "";
			else
				objel.style.display = "none";	 
	    }
	    return true;
	}
	return false;
}
function ChangeTab(ind) {
    if (ind == 1) {
        document.getElementById('trSearch').style.display="";
        document.getElementById('trBrowse').style.display='none';
     /* MM_findObj('Lcorner').src = "images/LrC_On.jpg";
        MM_findObj('Rcorner').src = "images/RrC_Off.jpg";
      */
        MM_findObj('Lcorner').className = "LcornerOn";
        MM_findObj('Rcorner').className = "RcornerOff";
        
        MM_findObj('tdSearch').className = "activeSPtab";
        MM_findObj('middleSPanel').className = "midPanelS";
        MM_findObj('tdBrowse').className = "inactiveSPtabBrowse";
    }
    else    {
        document.getElementById('trSearch').style.display='none';
        document.getElementById('trBrowse').style.display="";
      /*MM_findObj('Lcorner').src = "images/LrC_Off.jpg";
        MM_findObj('Rcorner').src = "images/RrC_On.jpg";
      */
        MM_findObj('Lcorner').className = "LcornerOff";
        MM_findObj('Rcorner').className = "RcornerOn";
        
        MM_findObj('tdSearch').className = "inactiveSPtabSearch";
        MM_findObj('middleSPanel').className = "midPanelB";
        MM_findObj('tdBrowse').className = "activeSPtab";
    }
    MM_findObj('selLeftMenuTab').value = ind;
    
    srvSetActiveMenu('selLeftMenuTab', ind);
}


function switchSearchMode1 (toValue) {
	var objel = document.getElementById("lblSearchBtn");//findEl ("lblSearchBtn");	
	
	if (objel != null) {
		arrBrowsertable = new Array('CatBrowserTable', 'LightboxBrowserTable');
		if ((objel.innerHTML == "Advanced Search" && toValue == null) || toValue == true) {
			objel.innerHTML = "SIMPLE SEARCH";
			showSpanContent ("AdvSearch", true);
			objel	= findEl ("lblSearchBtn");
			if (objel) objel.style.textAlign = "right"
			document.form1.hdnAdvSearchMode.value = "show";
			
			for(i = 0; i <= arrBrowsertable.length; i++)
			{
			    objel = findEl (arrBrowsertable[i]);
			    if (objel) objel.style.display = "none";
			}
		} else {
			objel.innerHTML = "Advanced Search";
			showSpanContent ("AdvSearch", false);
			objel	= findEl ("lblSearchBtn");
			if (objel) objel.style.textAlign = "left"
			// TODO clear advance search fields content
			clearFilterForm ();
			document.form1.hdnAdvSearchMode.value = "hide";
			for(i = 0; i <= arrBrowsertable.length; i++)
			{
			    objel = findEl (arrBrowsertable[i]);
			    if (objel) objel.style.display = "";
			}			
		}		
	}
	
	var objelBttm = document.getElementById("lblSearchBtnBttm");
	if (objelBttm != null) {
		objelBttm.innerHTML = document.getElementById("lblSearchBtn").innerHTML;
	}
	
}
function switchSearchMode (idLinkTab, toValue) {
	var objel = document.getElementById(idLinkTab);
	
	if (objel != null) {
	//	arrBrowsertable = new Array('CatBrowserTable', 'LightboxBrowserTable');
		arrBrowsertable = new Array('LightboxBrowserTable');
		if ((objel.innerHTML == "Advanced" && toValue == null) || toValue == true) {
			//document.getElementById('tdSimpleSearch').style.background="#E5E5E5";  //"#F7F7F7";
			//document.getElementById('tdAdvSearch').style.background="#E5E5E5";
			document.getElementById('lblSimpleSearch').className="inactiveSearchMode";
			document.getElementById('lblAdvSearch').className="activeSearchMode";
			showSpanContent ("AdvSearch", true);
			showSpanContent ("smplBtnSearch1", true);
			showSpanContent ("smplBtnSearch", false);
			
			setElementValue( document.getElementById('hdnAdvSearchMode'), "show");
			
			for(i = 0; i <= arrBrowsertable.length; i++)
			{
			    objel = findEl (arrBrowsertable[i]);
			    if (objel) objel.style.display = "none";
			}
			
			srvSetActiveMenu('hdnAdvSearchMode', 'show');
			
		} else {
			//document.getElementById('tdSimpleSearch').style.background="#E5E5E5";
			//document.getElementById('tdAdvSearch').style.background="#E5E5E5";  //"#F7F7F7";
			document.getElementById('lblSimpleSearch').className="activeSearchMode";
			document.getElementById('lblAdvSearch').className="inactiveSearchMode";
			showSpanContent ("AdvSearch", false);
			
			showSpanContent ("smplBtnSearch1", false);
			showSpanContent ("smplBtnSearch", true);
			// TODO clear advance search fields content
			
			clearFilterForm ();
			setElementValue(document.getElementById('hdnAdvSearchMode'), "hide");
			for(i = 0; i <= arrBrowsertable.length; i++)
			{
			    objel = findEl (arrBrowsertable[i]);
			    if (objel) objel.style.display = "";
			}
			
			srvSetActiveMenu('hdnAdvSearchMode', 'hide');			
		}		
	}	
}

function switchClassifMode (imgname, toValue) {
	var objel = findEl ("ClassifWin");
	var objImg = findEl (imgname);
	
	if (objel && objImg) {
		var imgSrc = "" + objImg.src;
		if ((imgSrc.indexOf("ic_down.gif") != -1 && toValue == null) || toValue == true) {
			objImg.src = abspath + "images/"+theCustomSkin+"/ic_up.gif";
			showSpanContent ("ClassifWin", true);
			setElementValue(document.getElementById('hdnClassifMode'), "show");    //document.form1.hdnClassifMode.value = "show";
		} else {
			objImg.src = abspath + "images/"+theCustomSkin+"/ic_down.gif";
			showSpanContent ("ClassifWin", false);
			setElementValue(document.getElementById('hdnClassifMode'), "hide");    //document.form1.hdnClassifMode.value = "hide";
			// TODO - clear checkboxes when
			clearCheckBoxes();
		}		
	}
}
function switchLicTypeMode (imgname, toValue) {
	var objel = findEl ("LicTypeSearch");
	var objImg = findEl (imgname);
	
	if (objel && objImg) {
		var imgSrc = "" + objImg.src;
		if ((imgSrc.indexOf("ic_down.gif") != -1 && toValue == null) || toValue == true) {
			objImg.src = abspath + "images/"+theCustomSkin+"/ic_up.gif";
			showSpanContent ("LicTypeSearch", true);
			setElementValue(document.getElementById('hdnLicTypeMode'),"show");    //document.form1.hdnLicTypeMode.value = "show";
		} else {
			objImg.src = abspath + "images/"+theCustomSkin+"/ic_down.gif";
			showSpanContent ("LicTypeSearch", false);
			setElementValue(document.getElementById('hdnLicTypeMode'),"hide");  //document.form1.hdnLicTypeMode.value = "hide";
			// TODO - clear checkboxes when
			clearCheckBoxes();
		}		
	}
}
function switchColorSearch (imgname, toValue) {
	spanName = "spanColorSearch";
	var objel = findEl (spanName);
	var objImg = findEl (imgname);
	
	if (objel && objImg) {
		var imgSrc = "" + objImg.src;
		if ((imgSrc.indexOf("ic_down.gif") != -1 && toValue == null) || toValue == true) {
			objImg.src = abspath + "images/"+theCustomSkin+"/ic_up.gif";
			showSpanContent (spanName, true);
			setElementValue(document.getElementById('hdnColorSearchMode'),"show");  //document.form1.hdnColorSearchMode.value = "show";
		} else {
			objImg.src = abspath + "images/"+theCustomSkin+"/ic_down.gif";
			showSpanContent (spanName, false);
			setElementValue(document.getElementById('hdnColorSearchMode'),"hide");  //document.form1.hdnColorSearchMode.value = "hide";
			// TODO - clear colors when
			setElementValue(document.getElementById('DomColor'),"");  //document.form1.DomColor.value = "";
			setSpanBackground ("DomColorExample","FFFFFF");
		}		
	}
}

function switchAllFieldsContent()
{
    var lbls = new Array('loc','lic','copy','rate','head','addinfo','iptc','author','email','url');
    
    for(var j = 0;j < lbls.length; j++)
        switchFieldContent('lbl_' + lbls[j], 'd' + lbls[j]);
}

function switchFieldContent (switchObjName, spanName)  {	
	var lbls;
	if(collapseFrontEndSection == '1')
	    lbls = new Array('desc', 'kwd','loc','lic','copy','rate','head','addinfo','iptc','author','email','url');
	else
	{
	    if(spanName.length <= 1) 
	    {
	        return false;
	    }
	    var temp = spanName.substring(1);
	    lbls = new Array(temp);	    
	}
		
	for(var i = 0; i < lbls.length; i++) {
		switchObj = MM_findObj('lbl_'+lbls[i])
		spanName = 'd'+lbls[i];
		objel = findEl(spanName);
        
        if (objel) {
            var firstSign;
            switchLabel = MM_findObj('menuSign_'+lbls[i])
			if (switchLabel) firstSign=switchLabel.src;
						
			if (switchObjName == ('lbl_'+lbls[i]))	{
				if (firstSign && firstSign.indexOf('__') > -1) {
					if (switchLabel)
					    switchLabel.src = "images/"+theCustomSkin+"/_.gif";
					//if (switchObj)
					//    switchObj.className = 'detailName000';
					showSpanContent(spanName,true);					
				}
				else {
					if(switchLabel)
					    switchLabel.src = "images/"+theCustomSkin+"/__.gif";
					//if(switchObj)
					//    switchObj.className = 'detailName';
					showSpanContent(spanName,false);
				}
			}
			else {
			    if(switchLabel)
				    switchLabel.src = "images/"+theCustomSkin+"/__.gif";
				//if(switchObj)
				//    switchObj.className = 'detailName';					
				showSpanContent(spanName,false);
			}
		}
	}
}

function ChBgrnd(ind,status) {
	line = document.getElementById('line'+ind);
	clName = line.className;
	
	if (status) {
		if( clName.indexOf("grayLineCCC") != -1 )
		{
		    MM_findObj('td'+ind).className = 'tabinfocus';
		    MM_findObj('sd'+ind).className = 'tabinfocus';
		}
	}
	else {
		if( clName.indexOf("grayLineCCC") != -1 )
		{
		    MM_findObj('td'+ind).className = "tabs";
		    MM_findObj('sd'+ind).className = "inactivetab";
		}
		else
		{
		    MM_findObj('td'+ind).className = "tabsBorder";
		    MM_findObj('sd'+ind).className = "activetab";
		}
	}
}

function ShowTabContent (tabnum)	{
	for(i=1;i<=3;i++) {
		tab = MM_findObj('tab_'+i);
		line = document.getElementById('line'+i)
		td = document.getElementById('td'+i)
		if ( tab )
			if (i==tabnum) {
				MM_changeProp('sd'+i,'','className','activetab');
				tab.style.display = "";
				line.className = "whiteLine"
				td.className = "tabsBorder"
				}
			else {
				MM_changeProp('sd'+i,'','className','inactivetab');
				tab.style.display = "none";
				line.className = "grayLineCCC"
				td.className = "tabs"
				}
	}	
}

function GenSimilarImgs(img) {
	if ( !areGeneratedImages) {
		if ( img != "" ) {
			
			frmObj = MM_findObj('gsfrm')
			
			if (frmObj) {
				areGeneratedImages = true;
				zz = "genSimImages.asp?" + G_SecData + "&imgid="+img;
				if(frmObj.document) frmObj.document.location.href=zz
				else 
					if(frmObj.src) frmObj.src = zz
				}
			else {
				alert("This feature is not supported");
				return false;
				}
		}
	}
	return true;
}

function clearCheckBoxes(){
	var arEl = new Array("RoyaltyFree","RightsManaged","ModelRelease","PropRelease");
	for (var i=0; i < arEl.length;i++)
        document.getElementById(arEl[i]).checked = false;		//document.form1[arEl[i]].checked = false;
}

function clearFilterForm () {
	var arEl = new Array("FilterCatID","FilterAuthor","FilterLocation","FilterMedium", "FilterColor", "FilterStyle", "FilterSubject");
	for (var i=0; i < arEl.length;i++)
        setElementValue(document.getElementById(arEl[i]), "");		//setElementValue(document.form1[arEl[i]], "");
		
	
	// at least clear check boxes
	clearCheckBoxes();	
	// clear Color selection
    setElementValue(document.getElementById('DomColor'), "");	//document.form1.DomColor.value = "";
	setSpanBackground ("DomColorExample","FFFFFF");
}

function popUpCats(prefix, flagIsFeaturedHome) {
	    var selCats = getElementValue(document.getElementById('AdvCatSearch'));    //var selCats = document.form1.AdvCatSearch.value;
	    openAjaxPopup('SelectCategoryLayer', 'SelectCategoryLayer.asp?' + G_SecData + '&cats='+selCats + '&prfx=' + prefix + (flagIsFeaturedHome != null && flagIsFeaturedHome != 'undefined' ? '&fhp=1' : ''), 600);
	    
	    //window.open('selectCategory.asp?' + G_SecData + &cats='+selCats,'selCatsPopup','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=250,left = 262,top = 50');
}
function isEnterPressed(e) {
      //return !(window.event && window.event.keyCode == 13); 
        if (!e) var e = window.event;
	    if (e.keyCode) code = e.keyCode;
	    else if (e.which) code = e.which;
	  
	    if (code == 13)  return true;  //enter key pressed
	   
	    return false;
      }
function CheckIfAdvancedFormIsFilled() {
    var fields = new Array('KeywordAllWords','KeywordWthWord','FilterMedium','FilterColor','FilterStyle','DomColor','FilterAuthor','FilterLocation','AdvCatSearch'); //'RoyaltyFree','RightsManaged','ModelRelease','PropRelease',
    for (var i=0; i < fields.length;i++)
        if ( MM_findObj(fields[i]).value != "" )  return true;
   
   return false;     
}   
function DoSearchIfSearchable(e)  {
    if (isEnterPressed(e)) {
        var check;
        //isSimpleMode = (findEl ("AdvSearch").style.display == "none");
        //if (isSimpleMode) check = "CheckIfNothingSelectedAndHasWord()"; else check = "CheckIfAdvancedFormIsFilled()";
        check = "CheckIfNothingSelectedAndHasWord()";
        if ( eval(check) ) 
        {
            document.forms['form1'].action+='&btnSrc=1'; 
            document.forms['form1'].submit();
        }
    }
 }
 
function popUpIPTC(URL, imgid) {
	
	URL += '&imgid=' + imgid;
	day = new Date();
	id = day.getTime();
	id = "ExifInfo";
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=400,left = 262,top = 50');");
	eval("page" + id + ".focus()");
}
function popUp(URL, imgid) {
	
	URL += '?imgid=' + imgid;
	day = new Date();
	id = day.getTime();
	id = "ExifInfo";
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=400,left = 262,top = 50');");
	eval("page" + id + ".focus()");
}
function popUpEmail(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=400,left = 262,top = 50');");
	eval("page" + id + ".focus()");
}

function popUpZoomify(URL) {
	id = "ZoomifyWin";
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=790,height=520,left = 50,top = 50');");
	eval("page" + id + ".focus()");
}

function popUpLarge(URL) {
	id = "largeview";
	eval("page" + id + " = window.open(URL, '" + id + "', '');");
	eval("page" + id + ".focus()");
}

function LogOut() {
	if (confirm('Are you sure?'))
	{
	    GoLoad();
		document.location.href = ScriptName + "&action=logout";
	}
}

function arrowGoBack(id)
{
    var opcids = document.getElementById(id); 
    if(opcids)
    {
        var indx = opcids.options.length;
        indx = (indx > 1 ? 1 : 0);
        var oArrowBack = document.getElementById("arrowBack");
        if(oArrowBack)
            oArrowBack.value = "1";
        var value = opcids.options[indx].value;
        if(parseInt(value) > -1)
            GoPage('cid', value);
    }
}

function GoPageBack(paramname, name) {
	var obj = document.forms["form1"][name];
	if(obj)
	{
	    var len = obj.length;
	    var paramvalue = obj[len-1].value;
	    if (paramname == "" && paramvalue == "" || paramvalue == "-1")  return
	    var page = ""+document.location.href;
	    var iPos = page.indexOf(paramname);
	    if (iPos == -1) {
		    // add param to form action
		    if (page.indexOf("?") == -1) 
			    page += "?" 
		    else
			    page += "&" 	
		    page += paramname + "=" + paramvalue;
	    } else {
		    var page2 = page.substr(iPos);
		    var iPos2 = page2.indexOf("&");
		    if (iPos2 == -1) {
			    // the last param 
			    page = page.substring(0,iPos + paramname.length + 1) + paramvalue;
		    } else {
			    page = page.substring(0,iPos + paramname.length + 1) + paramvalue + page2.substr(iPos2) ;
		    }
    			
	    }
	    document.form1.action = page;
	    document.form1.submit ();
	}
}

function GoToGoPage	(paramname,paramvalue,action) {
	var iPos,iPos2, page, page2;
	
	page = ""+document.location.href;
		
	if (action!="") {
		 iPos = page.indexOf('action');
		if (iPos != -1) {
			 page2 = page.substr(iPos);
			 iPos2 = page2.indexOf("&");
			if (iPos2 == -1) {
				// the last param 
				page = page.substring(0,iPos) ;
			} else {
				page = page.substring(0,iPos)  + page2.substr(iPos2+1) ;
			}
		}
	}
	
	var arr = new Array("act", "&whichpage", "cid", "currsrch", "hasSrchMode");
	//remove from queryString the pair 'act=refresh', or 'act='
	//remove from queryString the pair '&whichpage=2', or '&whichpage='
	for(var i=0; i < arr.length; i++)
	{
		flag = true;
		if(arr[i] == "cid" ) if(paramvalue != "") flag = false;
		if(flag)
		{
			iPos = page.indexOf(arr[i]);
			if (iPos != -1) {
					page2 = page.substr(iPos);
					iPos2 = page2.indexOf("&");
				if (iPos2 == -1) {
					// the last param 
					page = page.substring(0,iPos) ;
				} else {
					page = page.substring(0,iPos)  + page2.substr(iPos2+1) ;
				}
			}
		}
	}
		
	if (paramname == "" || paramvalue == "-1")  return
	if (!(paramname != "cid" || paramvalue == ""))
	{
		iPos = page.indexOf(paramname);
		if (iPos == -1) {
			// add param to form action
			if (page.indexOf("?") == -1) 
				page += "?" 
			else
				page += "&" 	
			page += paramname + "=" + paramvalue;
		} else {
			page2 = page.substr(iPos);
			iPos2 = page2.indexOf("&");
			if (iPos2 == -1) {
				// the last param 
				page = page.substring(0,iPos + paramname.length + 1) + paramvalue;
			} else {
				page = page.substring(0,iPos + paramname.length + 1) + paramvalue + page2.substr(iPos2) ;
			}
				
		}			
	}
	else
	{
		indx = page.indexOf("?");
		if (indx != -1 )
		{
			page = page.substr(0, indx);
		}
	}
	switchSearchMode("hide");
	if(page.substr(page.length-1,1) == "?") page = page.substr(0, page.length-1);
	if(page.substr(page.length-1,1) == "&") page = page.substr(0, page.length-1);	
	indx = page.indexOf("?&");
	if(indx != -1)
	{
		page = page.substr(0, indx+1) + page.substr(indx+2, page.length-indx);
	}
	document.location.href = page; 
}

function deleteItem (itemID, itemName) {
		if (confirm ('Delete "' + itemName + '" lightbox?'))
		    $.post('ViewLbLayer.asp?' + G_SecData + '&ListID=' + itemID + '&todel=' + itemID, $("#frmViewLb").serialize(), function(data){if(data.toLowerCase().indexOf("<div") != -1){var parent = $("#Lightbox").parent();$("#Lightbox").remove();parent.html(data);}else{eval(data);}});
}

function deletePendingItem (itemID) {
        //"Are you sure to delete List No "+ itemID +" ?"
		if (confirm ("Are you sure you want to remove this item?"))
		{
			//document.location.href = ScriptName + "&action=orderslist&isReqlist=1&todel=" + itemID;//+ "&GuestID=" + GuestID;	
		    		    
		    var frm = document.forms['formIQOTab'];
		    if (frm)
            {
                $.post(frm.action + "&trt=1&todel=" + itemID, $("#formIQOTab").serialize(), function(data){if(data.toLowerCase().indexOf("<div") != -1){var parent = $("#tabpanel").parent();$("#tabpanel").remove();parent.html(data);}});
            }
		}
}

function CheckIfNothingSelectedAndHasWord () {
   	obj = document.getElementById("KeywordAllWords") 
	if(obj)
	{
	    searchTermNotEntered = (obj.value == "");
	}
	else
	    searchTermNotEntered = false;   
	
	obj = document.getElementById("AdvCatSearch");
	if(obj)
	{
	    searchTermNotEntered1 = (obj.value == "" || obj.value == "0");
	}
	else
	    searchTermNotEntered1 = false; 

    if ( searchTermNotEntered && searchTermNotEntered1) {
	        return false;
	 }
	else
	{
	    //if ( isSimpleMode )
	    //{
		    document.getElementsByName('form1').action = ScriptName + "&hasSrchMode=1";
		    return true;
	    //}
	    //else
	    //{
	    //    setElementValue(document.getElementById('form1').hdnAdvSearchMode, "show" );
	    //    return true;
	   // }
    }
		
}

function NothOrjustAnyCh(){
	var i,yes=true;
	
	for (var i=1; i < document.form1.cid.length; i++)
		if (document.form1.cid[i].checked)
			yes=false;
	return yes;
}

function ShowSimilarImages(){
 	document.location.href = ScriptName + '&btnPressed=showsimilar&imageid=' + ImageID + '&hdnAdvSearchMode=' + hdnAdvSearchMode + '&orderby=' + OrderBy + '&rpp=' + RPP;
}

function uploadfiles(catId) {
	popUpWin ("galleryupload.aspx?" + G_SecData + "&categoryid=" + catId,600,400);
}

function ChangeDisplayCat(obj){
	var allselected = true;
	var cids = getSetCheckbox(document.form1.cid);
	
	for (var j = 0; j < document.form1.cid.length; j++)
		if (!document.form1.cid[j].checked ) allselected = false;
	
	var objel = findEl ("displayCat");
	var objel2 = findEl("dCat2");
	
	if (objel && objel2) {
		if (!obj.checked) {
			objel.innerHTML = "<a href=\"famain.asp?" + G_SecData + "&cid="+cids+"\">Click to show </a>";
			objel2.innerHTML = " <a href=\"famain.asp?" + G_SecData + "&cid="+cids+"\">selections </a>";
			allselected = false;}
			
		else 
			if (allselected) {
				objel.innerHTML = " Displaying ";
				objel2.innerHTML = "";}
	}
}

function refreshThumbs() {
	var cids, incArch, obj, act="refresh";
	
	obj = document.form1.cid;
	
	cids = getSetCheckbox(obj);
	if (cids=="" ) if( getCheckbox(obj)) cids = obj.value; else act="";
	if (document.form1.incArchived.checked) incArch="&incArchived="+"yes"; else incArch="";
	if (document.form1.recPP.value !="") rpp="&recPP="+document.form1.recPP.value; else rpp="";
	if (OrderBy != "") ob="&orderby=" + OrderBy; else ob="";
	if (document.form1.parCatID.value != "") oc = "&oldCat="+document.form1.parCatID.value; else oc="";
	
	document.location.href = "famain.asp?" + G_SecData + "&act="+act+"&cid="+cids+incArch+rpp+ob+oc+"&refThumb=1&oldRootID=" + rootID;
}

function GoToGoPage1(s1,s2) {
	flag=false;
	oSel=MM_findObj("pcids");
	if (oSel){
	    var len = oSel.options.length;
		if (len < 4){
			if (len == 3){
				res=oSel.options[1].value;
				flag=true;
			}
			else{res=""}
		}
		else{
			res=oSel.options[len-2].value;
			flag=true;
		}

		if (flag) {
			GoToGoPage(s1,res, s2);
		}
	}
}

function SearchBySuggestKeyword(val, sForm){
	var keyw = val;
	var temp1, temp2, temp3;
	
	temp1 = hdnAdvSearchMode;
	if (temp1!="") {temp1 = "&hdnAdvSearchMode="+temp1;}
	temp2 = OrderBy;
	if (temp2!="") {temp2 = "&orderby="+temp2;}
	temp3 = RPP;
	if (temp3!="") {temp3 = "&rpp="+temp3;}
	
	document.getElementById("KeywordAllWords").value = keyw;
	document.forms[sForm].action = "famain.asp?" + G_SecData + "&hdnPageMode=1" + temp1 + temp2 + temp3;
	document.forms[sForm].submit();
}		

function SetLimitButtonValue(sels){
	var btnText = "Limit Search to Folders";
	if (sels.indexOf('0,')>-1) sels='0';
	if (sels!=0){
		var selArr = sels.split(",");
		if ((num=selArr.length) > 1) ending="s"; else ending="";
		MM_findObj("numberSelected").innerHTML = btnText + "<br><strong>" + num+ " Folder"+ending+" selected</strong>";
	}
	else MM_findObj("numberSelected").innerHTML = btnText;
	MM_findObj("AdvCatSearch").value = sels;
}

function SetLightbox(alvalue,ovalue,o, newLbNameId) {
	if ( alvalue.length != 0 )
		{ 
		    if ( alvalue != "-" )
		    {
		        fillSetLightboxInfo(alvalue);
		    }
		    else
		        for (i=0; i<o.options.length; i++)
			        if ( o.options[i].value==alvalue) {
				        o.selectedIndex=i;
				        break;
				        }
	} else {
		if( SetLightboxCondition && newLbNameId != "newLbName")
		{
		    var url = 'LightboxEdit.asp?' + G_SecData + '&ug=' + SessUGID;
		    window.open(url, 'setLB', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=650,left = 50,top = 50');
        }
        else
        {
		    var obj = document.getElementById(newLbNameId);		    
		    if(obj)
		    {
		        var lname = obj.value;
		        if (lname != null )
			        switch(lname.toLowerCase()) {
			            case "" :
				            alert("Please input list name first.");
				            obj.focus();
				            break;
			            case "default" :
				            alert("The 'Default' name is reserved. Please enter another name");
				            obj.focus();
				            break;
				        default :
					        if ( confirm("Do you want to set this lightbox as active?")) sa=1; else sa=0;
					        fillSetLightboxInfo(0, 1, lname, sa);
					        return;
				    }
			}
		    //if cancel or close choosen - >then reset the seleted option to the previous
		    if(o)
		    {
		        for (i=0; i<o.options.length; i++)
			        if ( o.options[i].value==ovalue) {
				        o.selectedIndex=i;
				        break;
				    }
			}
        }				    
	}
 }
 
 function addtomybox3(img,list,ln) {
	if (img!="" & list!="" ) document.location.href='famain.asp?' + G_SecData + '&action=rmfromlbx&ListID='+list+'&imgid='+img+'&ln='+ln;
 }
 
 function RDReload(){
	var page = ""+document.location.href;
		var iPos = page.indexOf('todel');
		if (iPos != -1) {
			var page2 = page.substr(iPos);
			var iPos2 = page2.indexOf("&");
			if (iPos2 == -1) {
				// the last param 
				page = page.substring(0,iPos-1);
			} else {
				page = page.substring(0,iPos-1 ) + page2.substr(iPos2) ;
			}
		}
		document.forms[0].action = page;
		document.forms[0].submit ();
 }
 
 function showSearchMenu(flag)
 {
	srvSetActiveMenu('leftMenu_browseSearchPnlContent', 0);
	srvSetActiveMenu('leftMenu_Personal', 0);
	
	var loc = document.location.href;
	var arr = new Array("lm");
	for(var i=0; i < arr.length; i++)
	{
		iPos = loc.indexOf(arr[i]);
		if (iPos != -1) {
				page2 = loc.substr(iPos);
				iPos2 = page2.indexOf("&");
			if (iPos2 == -1) {
				// the last param 
				loc = loc.substring(0,iPos) ;
			} else {
				loc = loc.substring(0,iPos)  + page2.substr(iPos2+1) ;
			}
		}
	}
	if(loc.substr(loc.length-1,1) == "&") loc = loc.substr(0, loc.length-1);
	if(loc.substr(loc.length-1,1) == "?") loc = loc.substr(0, loc.length-1);
	var lm;
	if(flag == "hide") lm = "1";
	else lm = "2";
	if (loc.indexOf('?') != -1) loc += '&'; else loc += '?';
	loc += 'lm=' + lm;
	if (loc.indexOf('hasSrchMode=1') != -1)
	{
		document.forms["form1"].action = loc;
		document.forms["form1"].submit();
	}
	else
		document.location.href = loc; 
 }
 
 function switchTab(showIdCont, hideIdCont)
{
    var arr = new Array(new Array(showIdCont,true), new Array(hideIdCont, false));
    
    for(i = 0; i < arr.length; i++)
    {
        var obj = document.getElementById(arr[i][0]);
        if( obj )
        {
           
             var tdObj = document.getElementById('a'+arr[i][0]);
            if( arr[i][1] )
            {
                obj.style.display = '';
                if( tdObj )
                {
                    tdObj.className = "activeSearchMode";                        
                 }
            }
            else
            {
                obj.style.display = "none";
                if( tdObj )
                    tdObj.className = "inactiveSearchMode";
            }
            
        /*
            var tdObj = document.getElementById('td'+arr[i][0]);
            if( arr[i][1] )
            {
                obj.style.display = '';
                if( tdObj )
                {
                    tdObj.className = "activeBackground";                        
                 }
            }
            else
            {
                obj.style.display = "none";
                if( tdObj )
                    tdObj.className = "inactiveBackground";
            }
          */
        }
    }      
}

function HideLeftmenuLBTasks(hasSelections, cont, message, lineOverLogin, skin)
{
    var msg = ""
    var oCont = document.getElementById(cont);
    var oMess = document.getElementById(message);
    var oLineOverLogin = document.getElementById(lineOverLogin);
    
    if( !hasSelections )
    {
        msg = "<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" width=\"90%\">";
        msg += "<tr><td width=\"200\" align=\"center\" class=\"inactiveNavArr\" style=\"font-size:11px\">No Images Selected</td></tr>";
        msg += "<tr><td width=\"200\" align=\"center\" class=\"inactiveNavArr\">&nbsp;</td></tr>";
        msg += "<tr><td align=\"left\" width=\"200\" class=\"inactiveNavArr\" style=\"font-weight:normal\">Click \"Select\" under any image to add it to the Active Lightbox. ";
        if (window.parent.SessGuestID > 0)
            msg += "To rename the Active Lightbox, create more lightboxes, and manage all of your selections, go to My Lightbox Manager.";
        msg += "</td></tr>";
        msg += "<tr><td width=\"200\" align=\"center\" class=\"inactiveNavArr\">&nbsp;</td></tr>";
        msg += "</table>";
        
        if( oLineOverLogin ) oLineOverLogin.style.display = '';
                
    }
    else
    {
       if( oCont ) oCont.style.display = ''; 
       if( oMess ) oMess.style.display = "none";
       if( oLineOverLogin ) oLineOverLogin.style.display = "none"; 
    }
    
    if( msg.length > 0 )
    {   
        if( oCont ) oCont.style.display = "none";            
        if( oMess )
        {   
            oMess.style.display = '';
	        oMess.innerHTML = msg;
        }
    }
}

function SetLightboxNew(listvalue, cont, message, active, skin)
{
    var arr = listvalue.split('|');
    var value = arr[0];
    var lboxId = arr[1];
    var typeLbox = arr[2];
    
    var msg = ""
    var oCont = document.getElementById(cont);
    var oMess = document.getElementById(message);
    
    if( value != "" )
    {
        if( value == 0 )
        {
            if(typeLbox  > 0) grParam = "&gr=" + typeLbox;
            else grParam = "";
            
            msg = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
            msg += "<tr ><td height=\"1\" width=\"200\" class=\"lightGrayLine\"></td></tr>";
            msg += "<tr><td class=\"whiteLine\" width=\"200\"></td></tr>";
            msg += "<tr><td width=\"200\"><img src=\"images/"+skin+"/mssg.jpg\" /></td></tr>";
            msg += "<tr ><td height=\"1\" width=\"200\" class=\"lightGrayLine\"></td></tr>";
            msg += "<tr><td class=\"whiteLine\" width=\"200\"></td></tr>";
            msg += "<tr><td align=\"center\" width=\"200\" class=\"readOnlyMsgLink\">To rate this lightbox, <a href=\"javascript:void(0);\" onclick=\"document.location.href='famain.asp?" + G_SecData + "&action=mybox&ListID=" + lboxId + "&rateImg=1" + grParam + "';return false;\" style=\"font-weight:bold\">click here</a></td></tr>";
            msg += "<tr ><td height=\"1\" width=\"200\" class=\"lightGrayLine\"></td></tr>";
            msg += "<tr><td class=\"whiteLine\" width=\"200\"></td></tr>";
            msg += "<tr><td align=\"center\" width=\"200\" class=\"readOnlyMsgLink\">For other tasks, <a href=\"javascript:void(0);\" onclick=\"document.location.href='famain.asp?" + G_SecData + "&action=favslist" + grParam + "';return false;\" style=\"font-weight:bold\">click here</a></td></tr>";
            msg += "<tr ><td height=\"1\" width=\"200\" class=\"lightGrayLine\"></td></tr>";
            msg += "<tr><td class=\"whiteLine\" width=\"200\"></td></tr>";
            msg += "</table>";
            
        }
        else if( value == active )
        {
           if( oCont ) oCont.style.display = ''; 
           if( oMess ) oMess.style.display = "none"; 
        }
        else
        {
            fillSetLightboxInfo(value);            
        }
    }
    else
    {
        msg = "To change active lightbox use the above drop down."
    }
    
    if( msg.length > 0 )
    {   
        if( oCont ) oCont.style.display = "none";            
        if( oMess )
        {   
            oMess.style.display = '';
	        oMess.innerHTML = msg;
        }
    }
}

function fillSetLightboxInfo(aLight, isnew, lname, isa)
{  
    if (isnew == null || isnew == 'undefined') isnew = "";
    if (lname == null || lname == 'undefined') lname = "";
    if (isa == null || isa == 'undefined') isa = "";
    var objFrm = document.getElementById('setlbfrm');
    if( objFrm )
    {
        var oFrm = objFrm.contentWindow.document;
        if( oFrm )
        {
            oFrm.frm["aLight"].value = aLight;
            oFrm.frm["isnew"].value = isnew;
            oFrm.frm["lname"].value = lname;
            oFrm.frm["isa"].value = isa;
            
            oFrm.frm["isSave"].value = "1";
            
            setCookie("showAboutSelections", 1, expiredate);
            
            oFrm.frm.submit();		            
        }
    }
}

function MoveLBoxPanel(topid, bottomid, showid, hideid, paddingLbox, moveToBottom)
{
    var oTop = document.getElementById(topid);
    var oBottom = document.getElementById(bottomid);
    var oShow = document.getElementById(showid);
    var oHide = document.getElementById(hideid);
    var oPaddingLbox = document.getElementById(paddingLbox);
    if(oTop && oBottom)
    {
        var showSrchBrowseMenuOnTop;
        if(oShow)
            oShow.style.display = '';
        if(oHide)
            oHide.style.display = "none";
        var obj = document.getElementById("miniThmb");
        if(obj)
            obj.innerHTML = "";
        
        cleartimerLb();
        isOverImageLb = false;
        
        if(floatobjLB)
            floatobjLB.innerHTML = "";
                
        if(window.parent.aListImages)
            ShowActiveLightBoxContent(LBpage, document);
        
        if(moveToBottom)
        {
            oBottom.innerHTML = oTop.innerHTML;
            oTop.innerHTML = "";             
            if(oPaddingLbox)
                oPaddingLbox.style.display = "none";
            idObjFloatieLB = "lbthumbfloatie2";
            floatobjLB = document.getElementById(idObjFloatieLB);
            
            showSrchBrowseMenuOnTop = 1;
        }
        else
        {
            oTop.innerHTML = oBottom.innerHTML;
            oBottom.innerHTML = "";
            if(oPaddingLbox)
                oPaddingLbox.style.display = '';
            idObjFloatieLB = "lbthumbfloatie";
            floatobjLB = document.getElementById(idObjFloatieLB);
            
            showSrchBrowseMenuOnTop = 0;
        }
        
        srvSetActiveMenu('ShowSrchBrowseMenuOnTop', showSrchBrowseMenuOnTop);
    }
}

//go to server and set session variables related to ActiveMenuTab using AJAX
var xmlHttp

function srvSetActiveMenu(str, value)
{
    if (str.length==0)
        return;
        
    xmlHttp=GetXmlHttpObject();
    
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
    var url="ActiveMenuTab.asp"
    url=url+"?" + G_SecData + "&sn=" + str + "&sv=" + value;
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
} 

function stateChanged() 
{ 
    if( window["xmlHttp"] != undefined )
    {
        if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
        { 
            
        }
    } 
} 

function GetXmlHttpObject()
{ 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Reorder Items in LightBox
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function srvSaveNewSortValue()
{
    xmlHttp=GetXmlHttpObject();
    
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
    var olbId = document.getElementById("lbId");    
    if(olbId)
    {
        var lbId = olbId.value;
        var listItems = "";
        $('div.thumbs').each(function()
            {
                var cellId = $(this).attr('id');
                cellId = cellId.replace("lCell", "lbImgId");
                var olbImgId = document.getElementById(cellId);                
                if(olbImgId)
                    listItems += (listItems == "" ? "" : ",") + olbImgId.value;
            }            
        )
        
        if(listItems.length > 0)
        {
            var url="SaveNewSortValue.asp"
            url=url+"?" + G_SecData
            xmlHttp.onreadystatechange=stateChanged 
            xmlHttp.open("POST",url,true)
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send("lbId=" + lbId + "&listItems=" + listItems);
        }
    }
} 
//function srvSaveNewSortValue()
//{
//    xmlHttp=GetXmlHttpObject();
//    
//    if (xmlHttp==null)
//    {
//        alert ("Browser does not support HTTP Request");
//        return;
//    } 
//    var olbId = document.getElementById("lbId");
//    if(olbId)
//    {
//        var lbId = olbId.value;
//        var oCont = document.getElementById("itemContent");
//        
//        if(oCont)
//        {
//            var listItems = "";
//            var oList = oCont.getElementsByTagName("DIV");
//            for(i = 0; i < oList.length; i++)
//            {
//                var cellId = oList[i].id;
//                if(cellId == "") 
//                {
//                    setTimeout("srvSaveNewSortValue()",50);
//                    return;
//                }
//                
//                if(cellId.indexOf("cell") != 0) continue;
//                    
//                cellId = cellId.replace("cell", "lbImgId");
//                
//                var olbImgId = document.getElementById(cellId);
//                if(olbImgId)
//                    listItems += (listItems == "" ? "" : ",") + olbImgId.value;
//            }
//            
//            if(listItems.length > 0)
//            {
//                var url="SaveNewSortValue.asp"
//                url=url+"?" + G_SecData
//                xmlHttp.onreadystatechange=stateChanged 
//                xmlHttp.open("POST",url,true)
//                xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//                xmlHttp.send("lbId=" + lbId + "&listItems=" + listItems);
//            }
//        }
//    }
//} 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Send Forget Password by email
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SendForgetPassword()
{
    var oUserEmail = document.getElementById("usrEmail");
    if(oUserEmail)
    {
        if (!isNonBlank(oUserEmail.value))
        {
            oUserEmail.focus();
            return false;      
        }
        
        if (!isValidEmail(oUserEmail.value))
        {
            oUserEmail.focus();
            return false;      
        }
        
        var userEmail = oUserEmail.value;
        
        var oMsgForgetPwd = document.getElementById("msgForgetPwd");
        if(oMsgForgetPwd)
        {
            xmlHttp=GetXmlHttpObject();
        
            if (xmlHttp==null)
            {
                alert ("Browser does not support HTTP Request");
                return;
            } 
            var url="SendForgetPassword.asp"
            url=url+"?" + G_SecData
            xmlHttp.onreadystatechange=function(){
                if( window["xmlHttp"] != undefined )
                {
                    if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
                    { 
                        var message = xmlHttp.responseText;
                        if(message != "")
                        {
                            oMsgForgetPwd.innerHTML = message;
                            oMsgForgetPwd.style.display = '';
                        }
                    }
                }  
            }
            xmlHttp.open("POST",url,true)
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send("usrEmail=" + userEmail);
        }
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Check if an image is protected with password(show login form), check if entered password is valid using AJAX
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
var redirectUrl;
var protectedCatId = 0;
var pwdImgId;
var flagEnlarge;
var flagViewLb;
function checkForPassword(catid, imgid, str, aflagEnlarge)
{
    if ( (catid.length == 0 && imgid.length == 0))
        return;
    
    xmlHttp=GetXmlHttpObject();
    
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
    
     if (aflagEnlarge == null || aflagEnlarge == 'undefined') 
        aflagEnlarge = false;
    
    redirectUrl = str;
    protectedCatId = catid;
    pwdImgId = imgid;
    flagEnlarge = aflagEnlarge;
    
    var url="CheckForPassword.asp"
    url=url+"?" + G_SecData + "&catid=" + catid + "&imgid=" + imgid;
    xmlHttp.onreadystatechange=stateChangedPass
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
} 

function stateChangedPass() 
{ 
    var IsNotPasswordProtected;
    var sArrPass;
    var arrPass;
    if( window["xmlHttp"] != undefined )
    {
        if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
        { 
            sArrPass = xmlHttp.responseText;
            arrPass = sArrPass.split("|");
            IsNotPasswordProtected = arrPass[0];
            protectedCatId = arrPass[1]; 
            showPasswordScreen1(redirectUrl, IsNotPasswordProtected != 'true', pwdImgId);                     
        }
    } 
}

function showPasswordScreen1(str, flag, imgid)
{
    if(!flag)
    {
        var url = document.location.href;
        var indx = url.indexOf("famain.asp");
        if(indx != -1)
            url = url.substring(indx);
        if(url != str)
        {
            if (thumbnailClickAction == '1' || !flagEnlarge)
            {
                GoLoad();
                document.location.href = str;
            }
            else
            {
                $.closePopupLayer(false, 'thumblayer');
                ShowLargeImage('large/LargeImgLayer.asp?' + G_SecData + '&imageid=' + imgid + '&cmd=large&lid=0', imgid);
            }
        }
        else
        {
            $.closePopupLayer();
        }
    }
    else
    {
        openAjaxPopup('PasswordProtectedLayer', 'incPublicPasswordScreen.asp?' + G_SecData, 450);
    }
}

//function validatePassword()
//{
//    var opass = document.getElementById("password");
//    if(!opass) return;
//    var pass = opass.value;
//    
//    if (protectedCatId.length == 0 || pass.length == 0)
//        return;
//        
//    xmlHttp=GetXmlHttpObject();
//    
//    if (xmlHttp==null)
//    {
//        alert ("Browser does not support HTTP Request");
//        return;
//    } 
//        
//    var url="ValidatePassword.asp"
//    url=url+"?" + G_SecData + "&catid=" + protectedCatId + "&pwd=" + pass;
//    xmlHttp.onreadystatechange=stateCheckPass
//    xmlHttp.open("GET",url,true)
//    xmlHttp.send(null)
//} 

//function stateCheckPass() 
//{ 
//    var IsValidPass;
//    if( window["xmlHttp"] != undefined )
//    {
//        if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
//        { 
//            IsValidPass = xmlHttp.responseText;  
//            passScreenSubmit(redirectUrl, IsValidPass == 'true');                     
//        }
//    } 
//}

//function passScreenSubmit(str, flag)
//{
//    if(flag)
//    {
//        if(str.length > 0)
//            document.location.href = str;
//        else
//            document.location.href += str;
//    }
//    else
//    {
//        var obj = document.getElementById("msgImg");
//        if(obj)
//        {
//            obj.src = "images/" + theCustomSkin + "/passwordScreen/errMessage.jpg";
//        }
//        obj = document.getElementById("password");
//        if(obj)
//        {
//            obj.value = "";
//            obj.focus();
//        }
//    }
//}

var ie=document.all
var ns6=document.getElementById && !document.all
function ietruebody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function doScroll()
{
    var cY=(ns6)?window.pageYOffset : event.y+ietruebody().scrollTop;
    var obj = document.getElementById("contentTable")
    var spacerW;
    var layerWidth;
    var flagIsFullTreeScreen = false;
    if(obj)spacerW = obj.clientWidth;
    //var arr = new Array("passScreen", "assignFolderScreen", "secureUnsecureScreen", "howToOrderScreen", "createPersonalLBScreen", "fullTreeScreen", "aboutSelectionsScreen", "comeFromFlaShowScreen");    
    var arr = new Array("passScreen", "secureUnsecureScreen", "howToOrderScreen", "createPersonalLBScreen", "fullTreeScreen", "aboutSelectionsScreen", "comeFromFlaShowScreen", "processRequestScreen");    
    
    for(var i = 0; i < arr.length; i++)
    {
        var obj1 = document.getElementById(arr[i]);
        if(obj1 && obj1.style.display == '')
        {
            obj = obj1;
            if (arr[i] == "fullTreeScreen")
                flagIsFullTreeScreen = true;
            break;
        }
        else
        {
            if (i < arr.length - 1) 
                continue;
            else
                obj = null;
        }
    }
                           
    if(obj)
    {
        if(obj.style.display == '')
        {   
            layerWidth = obj.style.width;
            layerWidth = layerWidth.replace("px", "").replace(" ", "");
            var sWidth = spacerW - layerWidth;
            sWidth = (sWidth < 0 ? 0 : sWidth);
            a = (flagIsFullTreeScreen ? 50 : Math.round(sWidth/8));
            obj.style.top = (a + cY) + 'px';
        }             
    }
    else
        return null;
}

//window.onscroll = doScroll;

function ShowActionToCart(id, placeId)
{
    var obj = document.getElementById(placeId);
    if(obj)
    {
        if(obj.innerHTML == "")
        {
            xmlHttp=GetXmlHttpObject();
    
            if (xmlHttp==null)
            {
                alert ("Browser does not support HTTP Request");
                return;
            } 
                
            var url="CheckActionToCart.asp"
            url=url+"?" + G_SecData + "&imageid=" + id;
            xmlHttp.onreadystatechange=stateCheckActionToCart
            xmlHttp.open("GET",url,true)
            xmlHttp.send(null) 
        }
        obj.style.display = '';
    }
}

function stateCheckActionToCart()
{
    var imgId;
    var contentForAction;
    var sArr;
    var subArr;
    if( window["xmlHttp"] != undefined )
    {
        if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
        { 
            sArr = xmlHttp.responseText;
            subArr = sArr.split("|");
            imgId = subArr[0];
            contentForAction = subArr[1];        
            ShowCheckedAction(imgId, contentForAction);
        }
    } 
}

function ShowCheckedAction(id, content)
{
    var obj = document.getElementById('cartAct' + id);
    if(obj)
        obj.innerHTML = content;
}

function getPrevNextLargeImg(imageId, flagLb)
{
    if (flagLb == null || flagLb == 'undefined')
        flagLb = false;

    var oListImages = document.getElementById((flagLb ? "allLbImages" : "allImages"));
    var prevNextList = "";
    var nextId = "";
    var prevId = "";
    if(oListImages)
    {
        var list = oListImages.value;
        if(list != "")
        {
            var temp = list.split(',');
            if(temp.length == 1)
            {
                nextId = "";
                prevId = "";
                
            }
            else
            {
                switch("" + imageId)
                {
                    case temp[0]:
                        nextId = temp[1];
                        prevId = "";
                        break;
                    case temp[temp.length - 1]:
                        nextId = "";
                        prevId = temp[temp.length - 2];
                        break;
                    default:
                        list = "," + list + ",";
                        var reg, temp, arr;
                        reg = new RegExp("[,]*[0-9]*," + imageId + ",[0-9]*[,]*");
                        temp = list.match(reg);
                        if(temp)
                        {
                            arr = temp[0].split(',');
                            prevId = arr[1];
                            nextId = arr[3];                            
                        }
                }
            }
            prevNextList += "&prevId=" + prevId + "&nextId=" + nextId;                   
        }
    }
    
    var navWidth, navHeight;
    if (self.innerWidth != undefined)
    {
        navWidth = self.innerWidth;
        navHeight = self.innerHeight;
    }
    else
    {
        navWidth = document.documentElement.clientWidth;
        navHeight = document.documentElement.clientHeight;
    }
    
    prevNextList += "&navH=" + navHeight + "&navW=" + navWidth;
    
    return new Array(prevNextList, nextId);
}

function BackToThumbnails()
{
    getAlterImagesList();
    var oBackToImages = document.getElementById("BackToImages");
    var listBackToImages = (oBackToImages ? oBackToImages.value : "");
    var URL = "famain.asp?";
    
    var oBrowseMyBoxUrl = document.getElementById("BrowseMyBoxUrl");
    var BrowseMyBoxUrl = (oBrowseMyBoxUrl ? oBrowseMyBoxUrl.value : "");
    
    if(BrowseMyBoxUrl != "")
        URL += G_SecData + "&action=mybox&" + BrowseMyBoxUrl;
    else    
        URL += (listBackToImages.length > 0 ? listBackToImages : G_SecData);
    document.location.href = URL;    
}

function getAlterImagesList()
{
    xmlHttp=GetXmlHttpObject();
    
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
    var oListImages = document.getElementById("allImages");
    if(oListImages)
    {
        var list = oListImages.value;
        if(list.length > 0)
        {
            var oBackToImages = document.getElementById("BackToImages");
            var listBackToImages = (oBackToImages ? oBackToImages.value : "");
            var oBrowseMyBoxUrl = document.getElementById("BrowseMyBoxUrl");
            var BrowseMyBoxUrl = (oBrowseMyBoxUrl ? oBrowseMyBoxUrl.value : "");
            
            var url="GetAlterImagesList.asp"
            url=url+"?" + G_SecData
            xmlHttp.onreadystatechange=stateChanged 
            xmlHttp.open("POST",url,true)
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send("allImages=" + list + "&BackToImages=" + escape(listBackToImages) + "&BrowseMyBoxUrl=" + escape(BrowseMyBoxUrl));
        }
    }
}

function GetNextLargeImage(url, imageId)
{
    var obj = document.getElementById("largeImgLayer");
    if(obj)
    {
        var oLargeId = document.getElementById("largeObj" + imageId);
	    if(!oLargeId)
	    {
            xmlHttp=GetXmlHttpObject();

            if (xmlHttp==null)
            {
                alert ("Browser does not support HTTP Request");
                return;
            }
            
            if(url.indexOf("&prevId") == -1)
            {
                var flagLb = (url.indexOf("&lid=0") == -1)
                var prevNextArray = getPrevNextLargeImg(imageId, flagLb) ;
                var prevNextList = prevNextArray[0];
	            url += prevNextList;
	        }
	    
	    
            xmlHttp.onreadystatechange = function(){
                if( window["xmlHttp"] != undefined )
                {
                    if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
                    {
                        obj.innerHTML += xmlHttp.responseText;
                    }
                }           
            }
            xmlHttp.open("GET",url,true)
            xmlHttp.send(null)
        }
    }
}

function ShowLargeImage(url, imageId)
{       
    if(url.indexOf("&prevId") == -1)
    {
        var flagLb = (url.indexOf("&lid=0") == -1)
        var prevNextArray = getPrevNextLargeImg(imageId, flagLb) ;
        var prevNextList = prevNextArray[0];
        url += prevNextList;
    }
	var slideshow = (url.indexOf("&slideshow=on") != -1);
	        
    if (document.getElementById("enlargelayer"))
    {
       // $.get(url, function(data){if(data.toLowerCase().indexOf("<div") != -1){var parent = $("#enlargelayer").parent();$("#enlargelayer").remove();parent.html(data);} else{eval(data);}});
        $("#enlargelayer").load(url);
    }
    else            
        openAjaxPopup('showLargeImageLayer', url, 'auto');
}

function sleep(delay)
{
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

function showLargeImageScreen(slideshow, imageId)
{
    var obj = document.getElementById("contentTable");
    var spacerW = 0;
    var spacerH = 0;
    if(obj)
    {
        obj.className = "hideContLargeScreen";
        spacerW = obj.clientWidth;
        spacerH = obj.clientHeight;        
    }
    
    var layerWidth = 700;
    var layerHeight = 450;
    
    
    var selObj = document.getElementsByTagName("SELECT");
    for(i = 0; i < selObj.length; i++)
        selObj[i].className = "hideSelect";
    
    if( window['hideddrivetip'] != undefined ) hideddrivetip();
    obj = document.getElementById("LoadingDiv");
    var SpacerLH = 0;
    var SpacerLW = 0;
    if(obj && obj.style.display == "none")
    {
        obj = document.getElementById("largeImgLayer");
        if(obj)
        {
            addLargeStyle(imageId);
            var oLargeIdList = document.getElementsByTagName("DIV");
            var brLayers = 0
            for(i = 0; i < oLargeIdList.length; i++)
            {
                if(oLargeIdList[i].id && oLargeIdList[i].id.indexOf("largeObj") != -1)
                {   
                    brLayers++;                 
                    if(oLargeIdList[i].id == "largeObj" + imageId)
                    {
                        oLargeIdList[i].style.display = '';
                    }
                    else
                        oLargeIdList[i].style.display = "none";
                }
            }
            
            var maxLayers = 15;
            if (brLayers > maxLayers)
            {
                for(i = 0, j = (brLayers - maxLayers); i < oLargeIdList.length && j > 0; i++)
                {
                    if(oLargeIdList[i].id && oLargeIdList[i].id.indexOf("largeObj") != -1)
                    {   
                        j--;                 
                        var el = oLargeIdList[i];
                        el.parentNode.removeChild(el);
                    }
                }
            }
            
            var oLargeImgId = document.getElementById("largeImgId")
            if(oLargeImgId)
            {
                oLargeImgId.value = imageId;
            }
            
            /*if(slideshow)
            {
                document.getElementById("slideshowmodeoffLarge" + imageId).style.display='';
                document.getElementById("slideshowmodeonLarge" + imageId).style.display='none';
            }
            else
            {
                document.getElementById("slideshowmodeoffLarge" + imageId).style.display='none';
                document.getElementById("slideshowmodeonLarge" + imageId).style.display='';
            }*/  
             
            var oWidth = document.getElementById("layerWidth" + imageId);
            var oHeight = document.getElementById("layerHeight" + imageId);
            if(oWidth)
                layerWidth = oWidth.value;
            if(oHeight)
                layerHeight = oHeight.value;
            var sWidth = spacerW - layerWidth;
            sWidth = (sWidth < 0 ? 0 : sWidth);
            
            SpacerLH = Math.round(sWidth/8);
            SpacerLW = Math.round(sWidth/2);
            obj.style.top = SpacerLH + 'px';            
            obj.style.left = SpacerLW + 'px';
            obj.style.display = '';
        }
        
        obj = document.getElementById("largeImgLayerSpacer");
        if(obj)
        {
            var objSpacer = document.getElementById('largeImgLayerSpacerScreen');
            if(objSpacer)
            {
                objSpacer.style.width = SpacerLW + 50 + parseInt((spacerW > layerWidth ? spacerW : layerWidth)) + 'px';
                objSpacer.style.height = SpacerLH + 70 + parseInt((spacerH > layerHeight ? spacerH : layerHeight)) + 'px';
            }
            obj.style.width = SpacerLW + 50 + parseInt((spacerW > layerWidth ? spacerW : layerWidth)) + 'px';
            obj.style.height = SpacerLH + 70 + parseInt((spacerH > layerHeight ? spacerH : layerHeight)) + 'px';
            obj.style.display = '';
        }
        
        idObjFloatie = "dhtmlfloatieLarge" + imageId;
        floatobj=document.getElementById(idObjFloatie);
    }
    else
    {
        setTimeout("showLargeImageScreen(" + slideshow + ", " + imageId + ")", 50);
    }
}

function addLargeStyle(imageId)
{
    var obj = document.getElementById("dhtmlfloatieLarge" + imageId);
    if(obj)
    {
        obj.style.position = "absolute";
        obj.style.border = "2px solid #999999";
        obj.style.backgroundColor = "#E5E5E5";
        obj.style.padding = "5px";
        obj.style.zIndex = "100";
        obj.style.width = "130px";
        obj.style.visibility = "hidden";
        obj.style.textAlign = "left";
        obj.style.cursor = "pointer";
        obj.style.mozOpacity = "0";
        obj.style.filter = "alpha(opacity=0)";
    }    
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//End functions using AJAX
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Assigned Folders PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function selectDefProofFolder(objId)
{
    var obj = document.getElementById(objId);
    if (obj)
    {
        if (obj.options.length == 2)
        {
            obj.selectedIndex = 1;
            GetFolderInfo(obj.options[1].value, 'QLinksFolderInfo', true);
        }
    }    
}

function showAssFolderScreen(flag)
{
    if(flag)
    {
        var obj = document.getElementById("contentTable");
        var spacerW = 0;
        var spacerH = 0;
        if(obj)
        {
            obj.className = "hideContPassScreen";
            spacerW = obj.clientWidth;
            spacerH = obj.clientHeight;
        }
        
        var selObj = document.getElementsByTagName("SELECT");
        for(i = 0; i < selObj.length; i++)
            if(selObj[i].id != "privateFolders" && selObj[i].id != "pricesLb" && selObj[i].id != "proofPublicFolders")
                selObj[i].className = "hideSelect";
        
        if( window['hideddrivetip'] != undefined ) hideddrivetip();
        obj = document.getElementById("LoadingDiv");
        if(obj && obj.style.display == "none")
        {
            obj = document.getElementById("assignFolderScreen");
            if(obj)
            {
                
                var cY=(ns6)?window.pageYOffset : ietruebody().scrollTop;
                var a = Math.round((spacerW - 975)/8);
                obj.style.top = (a + cY) + 'px';            
                obj.style.left = Math.round((spacerW - 975)/2) + 'px';
                obj.style.display = '';
                
                //obj.style.width = (Math.min(spacerW, 1000) - 100) + 'px'; 
                //obj.style.height = Math.round((Math.min(spacerW, 1000) - 100)/2) + 'px';
            }
            
            obj = document.getElementById("assignFolderScreenSpacer");
            if(obj)
            {
                var objSpacer = document.getElementById('folderSpacerScreen');
                if(objSpacer)
                {
                    objSpacer.style.width = spacerW + 'px';
                    objSpacer.style.height = spacerH + 'px';
                }
                obj.style.display = '';
            }            
        }
        else
        {
            setTimeout("showAssFolderScreen(" + flag + ")", 50);
        }
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Process Request PopUp Layer LB edit page
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showProcRequestScreen(hasItemsToCart)
{
    var obj = document.getElementById("contentTable");
    var spacerW = 0;
    var spacerH = 0;
    if(obj)
    {
        obj.className = "hideContPassScreen";
        spacerW = obj.clientWidth;
        spacerH = obj.clientHeight;
    }
    
    var selObj = document.getElementsByTagName("SELECT");
    for(i = 0; i < selObj.length; i++)
        selObj[i].className = "hideSelect";
    
    if( window['hideddrivetip'] != undefined ) hideddrivetip();
    obj = document.getElementById("LoadingDiv");
    if(obj && obj.style.display == "none")
    {
        obj = document.getElementById("processRequestScreen");
        if(obj)
        {            
            var cY=(ns6)?window.pageYOffset : ietruebody().scrollTop;
            var a = Math.round((spacerW - 452)/8);
            obj.style.top = (a + cY) + 'px';            
            obj.style.left = Math.round((spacerW - 452)/2) + 'px';
            obj.style.display = '';
            
            obj.style.width = (Math.min(spacerW, 1000) - 100) + 'px'; 
            obj.style.height = Math.round((Math.min(spacerW, 1000) - 100)/2) + 'px';
            
            var flagHasComments = false;
            var olistItems = document.getElementById("allIDs");
            if(olistItems)
            {
                var arrItems = olistItems.value.split(",");
                for(i = 0; i < arrItems.length; i++)
                {
                    var oComment = document.getElementById("hdnIsChanged" + arrItems[i]);
                    if(oComment)
                    {
                        if(oComment.value == "1")
                            flagHasComments = true;
                    }
                }
            }
            
            obj = document.getElementById("procRequest");
            if(obj)
            {
                if(flagHasComments)
                    obj.checked = true;
                else
                    obj.checked = false;
            }
            
            obj = document.getElementById("procDraft");
            if(obj)
            {
                obj.checked = false;
            }
            
            if(hasItemsToCart)
            {
                obj = document.getElementById("lblCart");
                if(obj)
                {
                    obj.style.display = '';
                    
                    obj = document.getElementById("procCart");
                    if(obj)
                    {
                        obj.checked = true;
                    }
                    
                    obj = document.getElementById("lblCountItems");
                    if(obj)
                    {
                        var selItems = getElementValue(document.forms["frm"]["ImgPrice"]);
                        obj.innerHTML = selItems.replace(" ", "").split(',').length;
                    }
                }
            }
        }
        
        obj = document.getElementById("processRequestScreenSpacer");
        if(obj)
        {
            var objSpacer = document.getElementById('processRequestSpacerScreen');
            if(objSpacer)
            {
                objSpacer.style.width = spacerW + 'px';
                objSpacer.style.height = spacerH + 'px';
            }
            obj.style.display = '';
        }
    }
    else
    {
        setTimeout("showProcRequestScreen()", 50);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Contact PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showContactScreen()
{
    var url = "incPublicContactScreen.asp?" + G_SecData;
    openAjaxPopup('contactScreen', url, 650); 
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Front Page Info PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showFrontPageInfoScreen()
{
    var url = "incPublicFrontPageInfoScreen.asp?" + G_SecData;
    openAjaxPopup('frontpageInfoScreen', url, 650); 
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SecureUnsecure PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showSecureUnsecureScreen()
{    
    var obj = document.getElementById("contentTable");
    var spacerW = 0;
    var spacerH = 0;
    if(obj)
    {
        obj.className = "hideContPassScreen";
        spacerW = obj.clientWidth;
        spacerH = obj.clientHeight;
    }
    
    var selObj = document.getElementsByTagName("SELECT");
    for(i = 0; i < selObj.length; i++)
        if(selObj[i].id != "privateFolders")
            selObj[i].className = "hideSelect";
        
    obj = document.getElementById("LoadingDiv");
    if(obj && obj.style.display == "none")
    {
        obj = document.getElementById("secureUnsecureScreen");
        if(obj)
        {
            var cY=(ns6)?window.pageYOffset : ietruebody().scrollTop;
            var a = Math.round((spacerW - 452)/8);
            obj.style.top = (a + cY) + 'px';            
            obj.style.left = Math.round((spacerW - 452)/2) + 'px';
            obj.style.display = '';
        }
        
        obj = document.getElementById("secureUnsecureScreenSpacer");
        if(obj)
        {
            var objSpacer = document.getElementById('SecUnsecSpacerScreen');
            if(objSpacer)
            {
                objSpacer.style.width = spacerW + 'px';
                objSpacer.style.height = spacerH + 'px';
            }
            obj.style.display = '';
        }
        
        if(document.all)
        {
            obj = document.getElementById("secureUnsecureImg");
            if(obj && obj.src)pngFixOne(obj);
        }
    }
    else
    {
        setTimeout("showSecureUnsecureScreen()", 50);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//HowToOrder PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function showHowToOrderScreen(imgId)
{
    var obj = document.getElementById("contentTable");
    var spacerW = 0;
    var spacerH = 0;
    if(obj)
    {
        obj.className = "hideContPassScreen";
        spacerW = obj.clientWidth;
        spacerH = obj.clientHeight;        
    }
    
    
    var selObj = document.getElementsByTagName("SELECT");
    for(i = 0; i < selObj.length; i++)
        selObj[i].className = "hideSelect";
    
    if( window['hideddrivetip'] != undefined ) hideddrivetip();
    obj = document.getElementById("LoadingDiv");
    if(obj && obj.style.display == "none")
    {
        obj = document.getElementById("howToOrderScreen");
        if(obj)
        {
            var cY=(ns6)?window.pageYOffset : ietruebody().scrollTop;
            var a = Math.round((spacerW - 292)/8);
            obj.style.top = (a + cY) + 'px'; 
            obj.style.left = Math.round((spacerW - 292)/2) + 'px';
            var obj1 = document.getElementById("howToOrderLink");
            if(obj1)
                obj1.href = "famain.asp?" + G_SecData + "&action=pricereq&imgid=" + imgId;
            obj.style.display = '';
        }
        
        obj = document.getElementById("howToOrderScreenSpacer");
        if(obj)
        {
            var objSpacer = document.getElementById('toOrderSpacerScreen');
            if(objSpacer)
            {
                objSpacer.style.width = spacerW + 'px';
                objSpacer.style.height = spacerH + 'px';
            }
            obj.style.display = '';
        }
        
        if(document.all)
        {
            obj = document.getElementById("howToOrderImg");
            if(obj && obj.src)pngFixOne(obj);
        }
    }
    else
    {
        setTimeout("showHowToOrderScreen(" + imgId + ")", 50);
    }
}

function showComeFromFlaShowScreen()
{
    var obj = document.getElementById("contentTable");
    var spacerW = 0;
    var spacerH = 0;
    if(obj)
    {
        obj.className = "hideContPassScreen";
        spacerW = obj.clientWidth;
        spacerH = obj.clientHeight;        
    }
    
    
    var selObj = document.getElementsByTagName("SELECT");
    for(i = 0; i < selObj.length; i++)
        selObj[i].className = "hideSelect";
    
    if( window['hideddrivetip'] != undefined ) hideddrivetip();
    obj = document.getElementById("LoadingDiv");
    if(obj && obj.style.display == "none")
    {
        obj = document.getElementById("comeFromFlaShowScreen");
        if(obj)
        {
            var cY=(ns6)?window.pageYOffset : ietruebody().scrollTop;
            var a = Math.round((spacerW - 292)/8);
            obj.style.top = (a + cY) + 'px'; 
            obj.style.left = Math.round((spacerW - 292)/2) + 'px';            
            obj.style.display = '';
        }
        
        obj = document.getElementById("comeFromFlaShowScreenSpacer");
        if(obj)
        {
            var objSpacer = document.getElementById('fromFlaShowSpacerScreen');
            if(objSpacer)
            {
                objSpacer.style.width = spacerW + 'px';
                objSpacer.style.height = spacerH + 'px';
            }
            obj.style.display = '';
        }
        
        if(document.all)
        {
            obj = document.getElementById("comeFromFlaShowImg");
            if(obj && obj.src)pngFixOne(obj);
        }
    }
    else
    {
        setTimeout("showComeFromFlaShowScreen()", 50);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CreateGroupLB PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function showCreateGroupLBScreen()
{
    var url = 'LightboxEdit.asp?' + G_SecData + '&ug=' + SessUGID;
	window.open(url, 'setLB', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=650,left = 50,top = 50');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CreatePersonalLB PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function showCreatePersonalLBScreen(actionLb, id)
{
    /*
    switch(actionLb)
    {
        case 1: create new LB;break;
        case 2: rename LB;break;
        case 3: request info;break;
    }
    */
    
    if (id && (actionLb == 2 || actionLb == 3))
    {
        if(actionLb == 3 || confirm("Are you sure? \nAll selected files will be stored in a Renamed Lightbox."))
            openAjaxPopup('CreatePersonalLBLayer', 'incPublicCreatePersonalLBScreen.asp?' + G_SecData + '&a=' + actionLb + '&listId=' + id, 450);
    }
    else
    {
        openAjaxPopup('CreatePersonalLBLayer', 'incPublicCreatePersonalLBScreen.asp?' + G_SecData + '&a=' + actionLb, 450);
    }

//    var obj = document.getElementById("contentTable");
//    var spacerW = 0;
//    var spacerH = 0;
//    if(obj)
//    {
//        obj.className = "hideContPassScreen";
//        spacerW = obj.clientWidth;
//        spacerH = obj.clientHeight;        
//    }
//    
//    
//    var selObj = document.getElementsByTagName("SELECT");
//    for(i = 0; i < selObj.length; i++)
//        selObj[i].className = "hideSelect";
//    
//    if( window['hideddrivetip'] != undefined ) hideddrivetip();
//    obj = document.getElementById("LoadingDiv");
//    if(obj && obj.style.display == "none")
//    {
//        obj = document.getElementById("createPersonalLBScreen");
//        if(obj)
//        {
//            var anchor = "";
//            if (isCreateLB)
//            {
//                anchor = "<a href=\"javascript:void(0);\" onclick=\"SetLightbox('', null, null, 'newLbName');\" class=\"abutton\">Save</a>";
//            }
//            else
//            {
//                anchor = "<a href=\"javascript:void(0);\" onclick=\"SaveLightbox('rqp', 'newLbName');\" class=\"abutton\">Save</a>";
//            }
//            
//            var oAnch = document.getElementById("addNewLbScreen");
//            if (oAnch)
//            {
//                oAnch.innerHTML = anchor;
//            }
//            
//            var cY=(ns6)?window.pageYOffset : ietruebody().scrollTop;
//            var a = Math.round((spacerW - 292)/8);
//            obj.style.top = (a + cY) + 'px'; 
//            obj.style.left = Math.round((spacerW - 292)/2) + 'px';
//            obj.style.display = '';
//        }
//        
//        obj = document.getElementById("createPersonalLBScreenSpacer");
//        if(obj)
//        {
//            var objSpacer = document.getElementById('newPersonalLBSpacerScreen');
//            if(objSpacer)
//            {
//                objSpacer.style.width = spacerW + 'px';
//                objSpacer.style.height = spacerH + 'px';
//            }
//            obj.style.display = '';
//        }
//        
//        if(document.all)
//        {
//            obj = document.getElementById("createPersonalLBImg");
//            if(obj && obj.src)pngFixOne(obj);
//        }
//    }
//    else
//    {
//        setTimeout("showCreatePersonalLBScreen(" + isCreateLB + ")", 50);
//    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//AboutSelections PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doShowAbtSelLayer(oChBx)
{
    if (oChBx.checked)
    {
        setCookie("showAboutSelections", 0, expiredate);
    }
    else
    {
        setCookie("showAboutSelections", 1, expiredate);
    }
}

function checkAboutSelectionsScreen(imgId, LbName)
{
    if(! getCookie('showAboutSelections')) setCookie("showAboutSelections", 1, expiredate);
    var flagShow = (getCookie("showAboutSelections") == "1" ? true : false);
    
    if (flagShow)
    {
        openAjaxPopup('checkAboutSelectionsLayer', 'incPublicAboutSelectionsScreen.asp?' + G_SecData + '&imgid=' + imgId + '&lbname=' + LbName.replace("'", "\'"), 300);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//AboutItemInCart PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doShowAbtCartLayer(oChBx)
{
    if (oChBx.checked)
    {
        setCookie("showAboutItemInCart", 0, expiredate);
    }
    else
    {
        setCookie("showAboutItemInCart", 1, expiredate);
    }
}

function checkAddToCartScreen(imgId, priceId)
{
    if(! getCookie('showAboutItemInCart')) setCookie("showAboutItemInCart", 1, expiredate);
    var flagShow = (getCookie("showAboutItemInCart") == "1" ? true : false);
    
    if (flagShow)
    {
        openAjaxPopup('checkItemInCartLayer', 'incPublicAddToCartScreen.asp?' + G_SecData + '&imgid=' + imgId + '&prid=' + priceId, 450);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Full Tree PopUp Layer
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function showFullScreen(valType, params, leftDistance)
{
    if (valType == null || valType == 'undefined')
        valType = 1;
    if (params == null || params == 'undefined')
        params = G_SecData;
    if (leftDistance == null || leftDistance == 'undefined')
        leftDistance = 100;
        
    var obj = document.getElementById("contentTable");
    var spacerW = 0;
    var spacerH = 0;
    if(obj)
    {
        obj.className = "hideContPassScreen";
        spacerW = obj.clientWidth;
        spacerH = obj.clientHeight;        
    }
    
    var selObj = document.getElementsByTagName("SELECT");
    for(i = 0; i < selObj.length; i++)
        selObj[i].className = "hideSelect";
    
    if( window['hideddrivetip'] != undefined ) hideddrivetip();
    obj = document.getElementById("LoadingDiv");
    if(obj && obj.style.display == "none")
    {
        obj = document.getElementById("fullTreeContent");        
        if(obj)
        {
            obj.style.width = (Math.min(spacerW, 1000) - leftDistance) + 'px'; 
            obj.style.height = Math.round((Math.min(spacerW, 1000) - leftDistance)/2) + 'px';
            
            var url="";
            switch(valType)
            {
                case 1:
                    //Full Tree            
                    obj = document.getElementById("hasTreeView");
                    if(!obj)
                        url = "GetFullTree.asp?" + params;
                    break;
                case 2:
                    //Print Lightbox
                    url = "PrintLightbox.asp?" + params;
                    break;
                case 3:
                    //Email Lightbox
                    url = "EmailLightbox.asp?" + params;
                    break;
                case 4:
                    //Download Zip Selections
                    url = "DownloadZipSelections.asp?" + params; 
            }
            
            if (url.length > 0)
            {
                GetFullLayerContent("fullTreeContent", url);
            }
        }
        
        obj = document.getElementById("fullTreeScreen");
        if(obj)
        {
            var cY=(ns6)?window.pageYOffset : ietruebody().scrollTop;
            obj.style.top = (50 + cY) + 'px'; 
            obj.style.left = Math.round((spacerW - (Math.min(spacerW, 1000) - leftDistance))/2) + 'px';
            obj.style.display = '';
        }
        
        obj = document.getElementById("fullTreeScreenSpacer");
        if(obj)
        {
            var objSpacer = document.getElementById('treeSpacerScreen');
            if(objSpacer)
            {
                objSpacer.style.width = spacerW + 'px';
                objSpacer.style.height = spacerH + 'px';
            }
            obj.style.display = '';
        }
        
        if(document.all)
        {
            //obj = document.getElementById("createPersonalLBImg");
            //if(obj && obj.src)pngFixOne(obj);
        }
    }
    else
    {
        setTimeout("showFullScreen(" + valType + ", '" + params + "', " + leftDistance + ")", 50);
    }
}

function GetFullLayerContent(placeId, url, isMethodGet, postParams)
{
    if (isMethodGet == null || isMethodGet == 'undefined')
        isMethodGet = true;
    if (postParams == null || postParams == 'undefined')
        postParams = null;
        
    var obj = document.getElementById(placeId);
    
    if(obj && obj.style.display != "none")
    {
        if (!(url.indexOf("DownloadZipSelections.asp") != -1 && url.indexOf("&s=") != -1))
            obj.innerHTML = '<img src="images/' + theCustomSkin + '/progressbar.gif" alt="" border="0" />';
        xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        } 
                
        xmlHttp.onreadystatechange=function(){
            if( window["xmlHttp"] != undefined )
            {
                if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
                {                     
                    var content = xmlHttp.responseText;
                    if (content.indexOf("&action=login") != -1)
                    {
                        obj.innerHTML = '<span class="BigOrangeCopy">You must be logged in to process this Job!</span>';
                        eval(content);
                    }
                    else
                        obj.innerHTML = xmlHttp.responseText;
                    if (url.indexOf("DownloadZipSelections.asp") != -1)
                    {
                        var objZipProgress = document.getElementById("zipprogress");
                        if (objZipProgress)
                        {
                            var valZip = objZipProgress.value;
                            objZipProgress.value = "0";
                            if (valZip == "1")
                            {
                                url = url.replace("&s=2", "&s=1");                            
                                setTimeout("GetFullLayerContent('" + placeId + "', '" + url + "', " + isMethodGet + ", '" + postParams + "')", 60000);
                            }
                        }
                    }
                }
            } 
        }
        
        if (isMethodGet)
        {
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }
        else
        {
            xmlHttp.open("POST",url,true)
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send(postParams);
        }        
    }
    else
    {
        setTimeout("GetFullLayerContent('" + placeId + "', '" + url + "', " + isMethodGet + ", '" + postParams + "')", 5000); 
    }
}

function SendLbbyEmail()
{
    var frm = document.forms['formEmailLbx'];
    if (frm)
    {
        var msg = frm['MsgBody'].value;
        frm['MsgBody'].value = msg.replace(/\n/g, '<br />');
        
        $.post(frm.action, $("#formEmailLbx").serialize(), function(data){if(data.toLowerCase().indexOf("<div") != -1){var parent = $("#share").parent();$("#share").remove();parent.html(data);}});
    }
}

function PreviewPostcard()
{
    var frm = document.forms['formSendPostcard'];
    if (frm)
    {
        $.post(frm.action, $("#formSendPostcard").serialize(), function(data){if(data.toLowerCase().indexOf("<div") != -1){var parent = $("#postcard").parent();$("#postcard").remove();parent.html(data);}});
    }
}

function URLEncode(str) 
{ 
    str = escape(str); 

    // JScript doesn't think '/' needs to be escaped... 
    // I'm not sure it does either, but take it out to be 
    // consistent with VBScript's built-in URLEncode() 

    while (str.indexOf("/")!=-1) 
    { 
        str = str.replace("/","%2F"); 
    } 
    return str; 
} 

function myprint()
{
	var tmpVal = "";
	var arr = new Array("tbPrntComments", "lbPrntComments")
	for (var i = 0; i < arr.length; i = i + 2)
	{
	    var obj1 = document.getElementById(arr[i]);
	    if (obj1)
	    {
	        tmpVal = obj1.value;
	        obj1.style.display = "none";
	        obj1 = document.getElementById(arr[i+1]);
	        if (obj1)
	        {
	            obj1.innerHTML = tmpVal.replace(/\n/g, '<br />');
	            obj1.style.display = "";
	            tmpVal = "";
	        }
	    }
	}	
	
	var prtContent = document.getElementById("printContent");
    var WinPrint =
    window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.write(cssstyle + prtContent.innerHTML);
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
    
    
    for (var i = 0; i < arr.length; i = i + 2)
	{
	    var obj1 = document.getElementById(arr[i]);
	    if (obj1)
	    {
	        obj1.style.display = "";
	        obj1 = document.getElementById(arr[i+1]);
	        if (obj1)
	        {
	            obj1.innerHTML = "";
	            obj1.style.display = "none";
	        }
	    }
	}	
}

function hideLayer(layerId, spacerId)
{
    var flag = true;
    var obj;
    if(layerId == "largeImgLayer")
    {
        var oImgId = document.getElementById("imgid");
        if(oImgId)
        {
            var oldImgId = oImgId.value;
            oImgId = document.getElementById("largeImgId");
            var newImgId = oImgId.value;
            if(oldImgId != newImgId)
                flag = false;
        }
        if(!flag)
        {
            var LBoxId, GroupId;
            var oLBoxId = document.getElementById("lid");
            if(oLBoxId) LBoxId = oLBoxId.value;
            var oGroupId = document.getElementById("groupId");
            if(oGroupId) GroupId = oGroupId.value;
            obj = document.getElementById("goToImgDetails" + newImgId);
            if(obj)
            {
                var url = obj.href;
                if(LBoxId != "" || GroupId != "")
                {
                    url = url.replace("';", "");
                    if(LBoxId != "") url += "&lid=" + LBoxId;
                    if(GroupId != "") url += "&gr=" + GroupId;
                    url += "';";
                }
                eval(url);
            }
        }
    }
    
    if(flag)
    {
        obj = document.getElementById("contentTable");
        if(obj)
            obj.className = "showContPassScreen";
         
        
        var selObj = document.getElementsByTagName("SELECT");
        for(i = 0; i < selObj.length; i++)
            selObj[i].className = "showSelect";
        
        obj = document.getElementById(layerId);
        if(obj)
            obj.style.display = "none";
        
        obj = document.getElementById(spacerId);
        if(obj)
            obj.style.display = "none";
        
        idObjFloatie = "dhtmlfloatie";
        floatobj=document.getElementById(idObjFloatie);    
    }
}

//////////////////////////////////////////////////////
//Close Flash Video Player
/////////////////////////////////////////////////////
function closeVideoPlayer(args)
{
    var arr = args.split(",");
    if (arr.length == 2)
        hideLayer(arr[0], arr[1]);
}
////////////////////////////////////////////////////

////////////////////////////////////////////////////
//SlideShow
/////////////////////////////////////////////////
function showSlideShowScreen()
{
    var obj = document.getElementById("contentTable");
    var spacerW = 0;
    var spacerH = 0;
    if(obj)
    {
        obj.className = "hideContFlashSlideShow";
        spacerW = obj.clientWidth;
        spacerH = obj.clientHeight;        
    }
    
    var layerWidth = 800;
    var layerHeight = 650;
    
    obj = document.getElementById("slideShowFrame");
    if(obj)
    {
        layerWidth = obj.style.width.replace("px", "");
        layerHeight = obj.style.height.replace("px", "");        
    }
    
    obj = document.getElementById("LoadingDiv");
    var SpacerLH = 0;
    var SpacerLW = 0;
    if(obj && obj.style.display == "none")
    {
        obj = document.getElementById("flashSlideShow");
        if(obj)
        {
            var sWidth = Math.round(spacerW/2) + Math.round(layerWidth/2);
            sWidth = (sWidth < 0 ? 0 : sWidth);
            var sHeight = Math.round(spacerH/2) - Math.round(layerHeight/2);// - 25;
            sHeight = (sHeight < 0 ? 0 : sHeight);
            
            SpacerLH = sHeight;
            SpacerLW = sWidth;
            obj = document.getElementById("slideshowImgLayer");
            if(obj)
            {
                obj.style.top = Math.max(20, Math.min(20, (SpacerLH - 100))) + 'px';            
                obj.style.left = (SpacerLW - 125) + 'px';
                obj.style.display = '';                 
            }
            
            obj = document.getElementById("slideshowSpacer");
            if(obj)
            {
                var objSpacer = document.getElementById('slideshowSpacerScreen');
                if(objSpacer)
                {
                    objSpacer.style.width = parseInt((spacerW > layerWidth ? spacerW : SpacerLW)) + 'px';
                    objSpacer.style.height = parseInt((spacerH > layerHeight ? spacerH : layerHeight)) + 'px';
                    
                    var oBgColor = document.getElementById("flaShowBgColor");
                    if (oBgColor)
                    {
                        var bgColorSld = oBgColor.value;
                        if (bgColorSld.length > 0)
                            objSpacer.style.backgroundColor = bgColorSld;
                    }
                }
                obj.style.width = parseInt((spacerW > layerWidth ? spacerW : SpacerLW)) + 'px';
                obj.style.height = parseInt((spacerH > layerHeight ? spacerH : layerHeight)) + 'px';
                obj.style.display = '';
            }
            
            obj = document.getElementById("slideshowImgClose");
            if(obj)
            {
                var objColorBtn = document.getElementById('flaShowCloseBg');
                if(objColorBtn)
                {
                    if(objColorBtn.value.length > 0)
                        obj.style.backgroundColor = objColorBtn.value;
                }
                
                objColorBtn = document.getElementById('flaShowBtnCloseTxtColor');
                if(objColorBtn)
                {
                    if(objColorBtn.value.length > 0)
                        obj.style.color = objColorBtn.value;
                }
                
            }
            
            obj = document.getElementById("slideshowTxtClose");
            if(obj)
            {
                var objColorTxt = document.getElementById('flaShowTxtCloseColor');
                if(objColorTxt)
                {
                    if(objColorTxt.value.length > 0)
                        obj.style.color = objColorTxt.value;
                }
                
            }
        }
    }
    else
    {
        setTimeout("showSlideShowScreen()", 50);
    }
}
////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Get Full IPTC Description
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ShowIptcDesc(objId, lnkId, imgId)
{
    var oPlace = document.getElementById(objId);
    if(oPlace)
    {
        if(parseInt(imgId) > 0)
        {
            xmlHttp=GetXmlHttpObject();
        
            if (xmlHttp==null)
            {
                alert ("Browser does not support HTTP Request");
                return;
            } 
            var url="ShowIptcDesc.asp"
            url=url+"?" + G_SecData
            
            xmlHttp.onreadystatechange=function(){
                if( window["xmlHttp"] != undefined )
                {
                    if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
                    { 
                        var message = xmlHttp.responseText;
                        var oLink = document.getElementById(lnkId);                    
                        if(message != "")
                        {
                            oPlace.innerHTML = message;
                        }
                        else
                        {
                            if (oLink)
                                oLink.style.display = "none";
                        }
                    }
                }  
            }
            xmlHttp.open("POST",url,true)
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send("imgId=" + imgId);
        }
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Update Quote Archive Status
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function UpdateArchiveStatus()
{
    var frm = document.forms['formIQOTab'];
    if (frm)
    {
        $.post(frm.action + "&trt=2", $("#formIQOTab").serialize(), function(data){if(data.toLowerCase().indexOf("<div") != -1){var parent = $("#tabpanel").parent();$("#tabpanel").remove();parent.html(data);}});
    }
//    var oArchiveList = document.getElementById("quoteArchiveList");
//    if(oArchiveList)
//    {
//        xmlHttp=GetXmlHttpObject();
//    
//        if (xmlHttp==null)
//        {
//            alert ("Browser does not support HTTP Request");
//            return;
//        }
//        
//        var archiveList = oArchiveList.value;
//        var arr = archiveList.split(',');
//        archiveList = "";
//        for(var i = 0; i < arr.length; i++)
//        {
//            var obj = document.getElementById("arch" + arr[i]);
//            if(obj)
//            {
//                if(obj.checked)
//                    archiveList += (archiveList.length > 0 ? "," : "") + arr[i];
//            }
//        }
//         
//        var url="UpdateArchiveStatus.asp"
//        url=url+"?" + G_SecData
//        xmlHttp.onreadystatechange=function(){
//            if( window["xmlHttp"] != undefined )
//            {
//                if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
//                { 
//                    var message = xmlHttp.responseText;
//                    if(message == "true")
//                    {
//                        alert("Archive Status was updated!");
//                    }
//                }
//            }  
//        }
//        xmlHttp.open("POST",url,true)
//        xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//        xmlHttp.send("arch=" + archiveList);
//    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////
//Quick Links
///////////////////////////////////////////////////
function showPrivateFolders(id, imgId, showImgName, hideImgName)
{
    var obj = document.getElementById(id);
    if (obj)
    {
        var ind;   
        var oImg = document.getElementById(imgId)
        if (obj.style.display == "none")
        {
            ind = 1;
            obj.style.display = '';
            if (oImg)
                oImg.src = "images/" + theCustomSkin + "/" + hideImgName;
        }
        else
        {
            ind = 0;
            obj.style.display = "none";
            if (oImg)
                oImg.src = "images/" + theCustomSkin + "/" + showImgName;
        }
        
        srvSetActiveMenu('showPrivateFolders', ind);
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Check Lightbox by Add to Cart
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkListByAddToCart(id)
{
    xmlHttp=GetXmlHttpObject();
        
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    
    xmlHttp.onreadystatechange=function(){
        if( window["xmlHttp"] != undefined )
        {
            if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
            { 
                var status = xmlHttp.responseText;
                var message = "";
                switch(status)
                {
                    case "3":
                        message = "Use the cart to modify quantity or to add/edit item options.";
                        if (confirm(message))
                        {
                            $.closePopupLayer(false);
                            setTimeout('openAjaxPopup("cart", "Cart1.asp?' + G_SecData + '&ListID=' + id + '&action=addtocart&addall=1", 950)', 500);
                            //document.location.href="famain.asp?" + G_SecData + "&action=addtocart&ListID=" + id + "&addall=1";
                        }
                        break;
                    case "4":
                        message = "The images from this Lightbox have no pricing information.\nIf you have requested pricing information please wait for the administrator to price these images before you add them to the cart.";
                        alert(message);break;
                    case "5":
                        message = "Not all images have pricing information.\nIf you have requested pricing information please wait for the administrator to price these images before you add them to the cart.\nTo add only images to the cart that have pricing press continue, otherwise press cancel";
                        if (confirm(message))
                        {
                            $.closePopupLayer(false);
                            setTimeout('openAjaxPopup("cart", "Cart1.asp?' + G_SecData + '&action=addtocart&ListID=' + id + '", 950)', 500);
                            //document.location.href="famain.asp?" + G_SecData + "&action=addtocart&ListID=" + id;
                        }
                        break;
                }
            }
        } 
    }
    
    var url="CheckListByAddToCart.asp";
    url=url+"?" + G_SecData + "&ListId=" + id;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Get Count Images In Depth
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetCountImagesInDepth(id)
{
    var oList = document.getElementById(id);
    if(oList)
    {
        var arr = oList.value.split(',');
        for(var i = 0; i < arr.length; i++)
        {
            GetFolderCountImages(arr[i]);
        }
    }
}

function GetFolderCountImages(id)
{   
    var obj = document.getElementById("countImages" + id);
    if (obj)
    {
        xmlHttp=GetXmlHttpObject();
        
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        
        xmlHttp.onreadystatechange=function(){
            if( window["xmlHttp"] != undefined )
            {
                if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
                { 
                    var message = xmlHttp.responseText;
                    obj.innerHTML = message;
                }
            } 
        }
        
        var url="GetCountImagesInDepth.asp";
        url=url+"?" + G_SecData + "&catId=" + id;
        xmlHttp.open("GET",url,false);
        xmlHttp.send(null);
    }
    else
        setTimeout("GetFolderCountImages(" + id + ")",50);
           
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////
///Get Folder Info
///////////////////////////////////////////////////////////////////////////////////////
function GetFolderInfo(folderId, placeId, isProof)
{
    var obj = document.getElementById(placeId);
    
    if(obj)
    {
        xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        } 
        
        var url="GetFolderInfo.asp"
        url=url+"?" + G_SecData + "&cid=" + folderId + (isProof ? "&fl=1" : "");
        xmlHttp.onreadystatechange=function(){
            if( window["xmlHttp"] != undefined )
            {
                if((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") && xmlHttp.status == 200)
                { 
                    obj.innerHTML = xmlHttp.responseText;
                }
            } 
        }
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    else
    {
        setTimeout("GetFolderInfo('" + folderId + "', '" + placeId + "')", 5000); 
    }
}
//////////////////////////////////////////////////////////////////////////////////////

function switchPnlSrch(id)
{
    var obj = document.getElementById(id);
    if (obj)
        if(obj.style.display == "none")
            obj.style.display = '';
        else
            obj.style.display = "none";
}

function switchPnlMenu(showId, hideId)
{
    var obj = document.getElementById(showId);
    if (obj)
        obj.style.display = '';
    obj = document.getElementById(hideId);
    if (obj)
        obj.style.display = "none";
}

function selectOptMult(value, id)
{
   var objSelect = document.getElementById(id);
   if (objSelect)
   {
        for(var i = 0; i < objSelect.options.length; i++)
        {
            var opt = objSelect.options[i];
            if (opt.value == value)
                opt.selected = true;
            else
                opt.selected = false;
        }
   }
   checkStatusSelectedNarrow(); 
}

function checkStatusSelectedNarrow()
{
    var objLbl = document.getElementById("lblStatusNarrow");
    if (objLbl)
    {
        var countSelCategories = 0;
        var arrCategory = new Array("FilterMedium", "FilterColor", "FilterStyle", "FilterSubject");
        for (var i = 0; i < arrCategory.length; i++)
        {
            var objSelect = document.getElementById(arrCategory[i]);
            if (objSelect)
            {
                if (objSelect.selectedIndex != -1)
                {
                    countSelCategories++;
                }
            }
        }
        objLbl.innerHTML = (countSelCategories == 0 ? "No" : countSelCategories) + " " + (countSelCategories == 1 ? "Category" : "Categories") + " Selected";
        objLbl.className = (countSelCategories == 0 ? "inactiveNavArr" : "activeNavArr");
    }
}

function clearSrchPanel()
{
    var obj = document.getElementById("AdvCatSearch");
    if ( obj ) obj.value = "";
    selectSrchItem("srchAllF", "frmSimpleSearch");
    obj = document.getElementById("KeywordAllWords");
    if ( obj ) obj.value = "";
    obj = document.getElementById("kwdtypeAll");
    if ( obj ) obj.checked = true;
    
    var arrSelCategory = new Array("FilterMedium", "FilterColor", "FilterStyle", "FilterSubject");
    for (var i = 0; i < arrSelCategory.length; i++)
    {
        var id = arrSelCategory[i];
        selectOptMult("", id);
        selectOptMult("", id + "Single");
    }
    
    var arrLicense = new Array("RightsManaged", "RoyaltyFree", "ModelRelease", "PropRelease");
    for (var i = 0; i < arrLicense.length; i++)
    {
        var id = arrLicense[i];
        var objChbx = document.getElementById(id);
        if ( objChbx ) objChbx.checked = false;
    }
}

function selectSrchItem(id, formname, prefix)
{
    if (prefix == null || prefix == 'undefined') prefix = "";
    var ofrm = document.forms[formname];
    var obj = document.getElementById(id);
    if(obj)
    {
        switch(id)
        {
            case prefix + "srchAllF":
                obj = document.getElementById(prefix + 'srchThisF');
                if(obj)
                {
                    obj.style.background = "url('images/" + theCustomSkin + "/folder_1.gif') no-repeat top left";
                }
                obj = ofrm.incAlterResults;
                if(obj)
                {
                    obj.value = "";
                }
                obj = document.getElementById(prefix + 'srchSelectF');
                if(obj)
                {
                    obj.style.background = "url('images/" + theCustomSkin + "/folder_3.gif') no-repeat top left";
                }
                obj = document.getElementById(prefix + 'mainSrchImg');
                if(obj)
                {
                    obj.src = "images/img/" + theDefaultIconSet + "/folder_select.gif"; //"images/" + theCustomSkin + "/folder_select.gif";
                }
                obj = ofrm.AdvCatSearch;
                if(obj)
                {
                    obj.value = "";
                }
                break;
            case prefix + "srchThisF":
                obj.style.background = "url('images/" + theCustomSkin + "/folder_3r.gif') no-repeat top left";
                
                obj = document.getElementById(prefix + 'srchAllF');
                if(obj)
                {
                    obj.style.background = "url('images/" + theCustomSkin + "/folder_2.gif') no-repeat top left";
                }
                obj = ofrm.incAlterResults;
                if(obj)
                {
                    obj.value = "yes";
                }
                obj = document.getElementById(prefix + 'srchSelectF');
                if(obj)
                {
                    obj.style.background = "url('images/" + theCustomSkin + "/folder_3.gif') no-repeat top left";
                }
                obj = document.getElementById(prefix + 'mainSrchImg');
                if(obj)
                {
                    obj.src = "images/img/" + theDefaultIconSet + "/folder_select.gif"; //"images/" + theCustomSkin + "/folder_selected.gif";
                }
                obj = ofrm.AdvCatSearch;
                if(obj)
                {
                    obj.value = "";
                }
                break;
            case prefix + "srchSelectF":
                obj.style.background = "url('images/" + theCustomSkin + "/folder_3r.gif') no-repeat top left";
                
                obj = document.getElementById(prefix + 'srchThisF');
                if(obj)
                {
                    obj.style.background = "url('images/" + theCustomSkin + "/folder_1.gif') no-repeat top left";
                }
                obj = ofrm.incAlterResults;
                if(obj)
                {
                    obj.value = "";
                }
                obj = document.getElementById(prefix + 'srchAllF');
                if(obj)
                {
                    obj.style.background = "url('images/" + theCustomSkin + "/folder_2.gif') no-repeat top left";
                }
                obj = document.getElementById(prefix + 'mainSrchImg');
                if(obj)
                {
                    obj.src = "images/img/" + theDefaultIconSet + "/folder_select.gif"; //"images/" + theCustomSkin + "/folder_selected.gif";
                }
                break;
        }
    }
}

function closeLeftMenu(hideId, checkId, showBtn, hideBtn)
{
    var obj = document.getElementById(hideId);
    if(obj)
    {
        obj.style.display = "none";
        
        obj = document.getElementById(checkId);
        if(obj)
        {
            if(obj.style.display == "none")
                showSearchMenu('hide');
        }
        
        obj = document.getElementById(showBtn);
        if(obj)
        {
            obj.style.display = '';
        }
        
        obj = document.getElementById(hideBtn);
        if(obj)
        {
            obj.style.display = "none";
        }
        srvSetActiveMenu('leftMenu_' + hideId, 1);
    }
}

function openLeftMenu(showId, showBtn, hideBtn)
{
    var obj = document.getElementById(showId);
    if(obj)
    {
        obj.style.display = '';
                
        obj = document.getElementById(showBtn);
        if(obj)
        {
            obj.style.display = '';
        }
        
        obj = document.getElementById(hideBtn);
        if(obj)
        {
            obj.style.display = "none";
        }
        srvSetActiveMenu('leftMenu_' + showId, 0);
    }
}

function playFile(id)
{
    var stopId = stopFile();
    if(stopId != id)
    {
        var oImg = document.getElementById("img" + id);
        if(oImg)
        {
            var oBtn = document.getElementById("play" + id);
            if(oBtn)
            {
                var oFr = document.getElementById("fr" + id);
                if(oFr)
                {
                    var oPlay = document.getElementById("hdnPlayId");
                    if(oPlay)
                    {
                        oPlay.value = id;
                        oFr.style.display = "";
                        oFr.style.visibility = "visible";
                        //oFr.contentWindow.document.body.style.display = "";
//                        var oCell = document.getElementById("imgCont" + id);
//                        if (oCell)
//                        {
//                            if (parseInt(navigator.appVersion) > 3) {
//                                if (navigator.appName == "Netscape") {
//                                    height = oCell.clientHeight;
//                                }
//                            }
//                            if (navigator.appName.indexOf("Microsoft") != -1) {
//                                height = oCell.offsetHeight;
//                            }
//                            alert(height);
//                            oCell.style.height = (1 * height - 65) + 'px';
//                        }
                        oImg.style.display = "none";
                        sleep(1000);
                        
                        oBtn.src = "images/" + theCustomSkin +"/stop.gif";
                    }
                }
            }
        }
    }
}

function stopFile()
{
    var id = 0;
    var oPlay = document.getElementById("hdnPlayId");
    if(oPlay)
    {
        id = oPlay.value;
        if(id.length > 0)
        {
            var oImg = document.getElementById("img" + id);
            if(oImg)
            {
                var oBtn = document.getElementById("play" + id);
                if(oBtn)
                {
                    var oFr = document.getElementById("fr" + id);
                    if(oFr)
                    {
                        oFr.style.display = "none";
                        oFr.style.visibility = "hidden";
                        //oFr.contentWindow.document.body.style.display = "none";
//                        var oCell = document.getElementById("imgCont" + id);
//                        if (oCell)
//                        {
//                            oCell.style.height = "";
//                        }
                        oImg.style.display = "";
                        //sleep(1000);
                        
                        oBtn.src = "images/" + theCustomSkin +"/play.gif";
                        oPlay.value = "";
                    }
                }
            }
        }
    }
    return id;
}
