function SetImage()
{
	if (bSmartBrowser && !tiled)
	{
		document.images.htmlImage.src = szImageURL+"&vx=0&vy=0&vw="+vw+"&vh="+vh+"&zp="+zp+"&qf="+iqString+"&rc="+rc+"&sh=0&sw=0";
		document.images.htmlImage.width = vw;
		document.images.htmlImage.height = vh;
	}
	else
	{
		Submit();
	}
}
function SetZoomCookie()
{
	window.focus(); // remove flicker
	setDictionaryCookie("BROWSES", "Z"+dbid ,escape(zp*2), null, null);
}
function SetCookieIQ()
{
	setDictionaryCookie("BROWSE", "XIQ", iq, null, "Tue, 02 Jan 2035 00:00:00 UTC");
	iq==0?iqString="mc":iqString="pq";
}
function Submit()
{
    if (email == "")
        Navigate(szBaseURL + "&rc=" + rc + "&zp=" + zp);
    else
        Navigate(email + "&rc=" + rc + "&zp=" + zp);
}
function GoToInstall()
{
	installUrl = installUrl.replace('&a=0','');
	Navigate(installUrl+'&a=1');	
}
function Navigate(url)
{
	if(document.fNavigate)
	{
		document.fNavigate.action = url;
		document.fNavigate.submit();
	}
	else
	{
		window.location.href=url;
	}
}
function SetZoom(_this)
{
	zp = _this.options[_this.selectedIndex].value;
	vw = Math.round(iw * zp/100);
	vh = Math.round(ih * zp/100);

	SetZoomDivs(zp);
	SetImage();
	SetZoomCookie();
}
function ZoomOut()
{
	var oZoom = _findObj("zoom");
	if (oZoom.selectedIndex > 0)
	{
		oZoom.selectedIndex = oZoom.selectedIndex-1;
		SetZoom(oZoom);
	}
}
function ZoomIn()
{
	var oZoom = _findObj("zoom");
	if (oZoom.selectedIndex < oZoom.length-1)
	{
		oZoom.selectedIndex = oZoom.selectedIndex+1;
		SetZoom(oZoom);
	}
}
function SetZoomDivs(zoom)
{
	if (zoom >= 100)
	{
		document.getElementById('zoomin').style.display = "none";
		document.getElementById('zoomin_no').style.display = "";
	}
	else
	{
		document.getElementById('zoomin').style.display = "block";
		document.getElementById('zoomin_no').style.display = "none";	
	}
	if (zoom <= 25)
	{
		document.getElementById('zoomout').style.display = "none";
		document.getElementById('zoomout_no').style.display = "";
	}
	else
	{
		document.getElementById('zoomout').style.display = "";
		document.getElementById('zoomout_no').style.display = "none";
	}
}
function GotoImage(idx)
{
	if (currentImageNo != idx)
	{
		if(isBook)
		{
				Navigate("/Browse/BookView.aspx?dbid=" + dbid + "&pageno=" + idx);
		}
		else
		{
			var bNaN = isNaN(parseInt(idx));
			if (bNaN || idx < 1 || idx > cImages)
			{
				alert(numRange + cImages + ".");	// from resource file via ViewerHTML.ascx
			}
			else if(1 == idx && 1 == cImages)
			{
			}
			else
			{
				Navigate("/Browse/View.aspx?dbid=" + dbid + "&path=" + imagePath + "."+idx);
			}
		}
	}
	return false;
}
function PrevPage()
{
	if (prevUrl.length>0)
	{
		Navigate(prevUrl);
	}
}
function NextPage()
{
	if (nextUrl.length>0)
	{
		Navigate(nextUrl);
	}
}
function Help()
{
	window.open("/Browse/help_u.aspx","Help","toolbar=no,scrollbars=1,resizable=1,menubar=no,location=no,height=375,width=456");
}
function Share()
{
	EmailFriend();
}
function PrintPopup(bOrder)
{
	OptionsPopup(false);
	SavePopup(false);
	if('undefined' == typeof OrderPrint)
	{
		Print();
	}
	else
	{
		var pop;
		if(bOrder)
			pop = document.getElementById( "orderPrintDialogHtml" );
		else
			pop = document.getElementById( "printDialogHtml" );
		
		if(null != pop)
		{
			var dialogWidth = pop.getAttribute("width");
			var dialogHeight = pop.getAttribute("height");
			var dialogPosX = Math.max(0, ( document.body.clientWidth / 2 ) - ( dialogWidth / 2 ));
			var dialogPosY = Math.max(0, ( document.body.clientHeight / 3 ) - ( dialogHeight / 2 )); 
			
			pop.style.left = Math.round(dialogPosX);
			pop.style.top  = Math.round(dialogPosY);
			pop.style.width = dialogWidth;
			pop.style.height = dialogHeight;
			pop.style.position = "absolute";
			pop.style.zIndex = 3;
			pop.style.backgroundColor = "#EEEEEE";
			pop.style.border = "1px solid #999999";
			pop.style.display = "block";
		}
		else
		{
			Print();
		}
	}
}
function printDialogPrint() 
{
    var myRes = new Image();
    var successURL = "/handler/ajax/SuccessHandler.ashx?op=Write&dbid=" + dbid + "&unq=" + Math.floor(Math.random() * 1999999999) + "&pagetype=Image&successtype=" + SuccessType + "&eventtype=print";
    myRes.src = successURL;
	printDialogCancel();
	Print();
}
function printDialogCancel()
{
	var pop;
	pop = document.getElementById( "orderPrintDialogHtml" );
	if(null != pop)
		pop.style.display = 'none';
	pop = document.getElementById( "printDialogHtml");
	if(null != pop)
		pop.style.display = 'none';
}
function Print()
{
	window.open("/Browse/print_u.aspx?" + printUrlParams,"Print");
}
function printDialogGotoApress( host, action, query )
{
    var eventtype = "printCanvas";
    if (query == "&ptid=15")
        eventtype = "print";

    var myRes = new Image();
    var successURL = "/handler/ajax/SuccessHandler.ashx?op=Write&dbid=" + dbid + "&unq=" + Math.floor(Math.random() * 1999999999) + "&pagetype=Image&successtype=" + SuccessType + "&eventtype=" + eventtype + " ";
    myRes.src = successURL;    
	printDialogCancel();
	var url = "http://" + host + "/index.aspx?action=" + action + "&ppvhash=" + ppv + "&dbid=" + dbid + "&iid=" + iid + "&pid=" + pid + query;
	var newwindow = window.open(url,'_blank','status=0,location=0,toolbar=0,menubar=0,resizable=1,scrollbars=1,titlebar=0');
	if (newwindow != null) { newwindow.focus(); }
}
function SavePopup(show)
{
var pop;
	if(show)
	{
		OptionsPopup(false);
		printDialogCancel();
		if('undefined' == typeof SaveThis)
		{
			Save();
		}
		else
		{
			if('undefined' == typeof SaveOwt)
			{
				var owtLink = _findObj("owtLink");
				owtLink.style.display = "none";
			}

			pop = _findObj("saveHTML");
			pop.style.left = document.body.offsetWidth/2-250;
			pop.style.top  = 185;//document.body.offsetHeight/2-77;
			pop.style.display = "block";
		}
	}
	else
	{
			pop = _findObj("saveHTML");
			pop.style.display = "none";
	}
}
function OkSave(radio)
{
	_findObj('saveHTML').style.display = 'none';

var st = "";
	for(i=0;i<radio.length;i++)
	{
		if(radio[i].checked)
		{
			st = radio[i].value;
			break;
		}
	}
	if(st == "saveOwt")
		SaveOwt();
	else if(st == "savePt")
		SavePt();
	else if(st == "savePtOther")
		SavePtOther();
	else if(st == "savePtStart")
		SavePtStart();
	else if(st == "saveShoebox")
		SaveThis("Image");
	else
		Save();
}
function Save() 
{
    var myRes = new Image();
    var successURL = "/handler/ajax/SuccessHandler.ashx?op=Write&dbid=" + dbid + "&unq=" + Math.floor(Math.random() * 1999999999) + "&pagetype=Image&successtype=" + SuccessType + "&eventtype=savDisk";
    myRes.src = successURL;
    if(tiled)
    {
	    window.open("/Browse/print_u.aspx?" + printUrlParams,"Save");
    }
    else
	    alert(copyAlert);		// from resource file via ViewerHTML.ascx
}
function OptionsPopup(show)
{
	if(show)
	{
		printDialogCancel();
		SavePopup(false);
	}
	var pop = _findObj("optionsHTML");
	pop.style.left = document.body.offsetWidth/2-134;
	pop.style.top  = 150;//document.body.offsetHeight/2-72;
	pop.style.display = show?"block":"none";
}
var origIQ = iq; 
function OptionsOk()
{
	var radio = _findObj("quality");
	if (radio[0]==undefined)
	{ //netscape, firefox
		if(radio.checked)
			iq = "1";
		else
			iq = "0";
	}
	else
	{ //IE
		if(radio[0].checked)
			iq = "1";
		else
			iq = "0";	
	}
	SetCookieIQ(iq);
	
	var viewer = _findObj("viewer");
	var goToInstall = false;
	if (viewer != null)
	{
		if(viewer[0]==undefined)
		{//netscape, firefox
			if(viewer.checked)
			{
				GoToInstall();
				goToInstall = true;
			}
		}
		else
		{ //IE
			if(viewer[0].checked)
			{		
				GoToInstall();
				goToInstall = true;
			}
		}
	}	
	if(0 == origIQ && 1 == iq && goToInstall == false)
	{
		Navigate(szBaseURL+"&rc="+rc+"&qf=pq");
	}
}
