// functions to manage the annotation property dialog
var _properties = new Array(
	"propOutlineColor",
	"propOutlineWidth", 
	"propFillColor",
	"propShadowColor",
	"propFontName",
	"propFontSize",
	"propFontColor",
	"propFontBold",
	"propFontItalics",
	"propFontUnderline",
	"propFontStrike",
	"propShadow");

function getAnnoPropertiesDlg()
{
	return getObj('AnnoPropDlg');
}

function AnnoProperties()
{
	WebAnnotationViewer1.RemoteInvoked = OnAnnoPropertyDialogInvoked;
	WebAnnotationViewer1.RemoteInvoke('PopupAnnoDialog', new Array()); 
}

function OnAnnoPropertyDialogInvoked()
{
	WebAnnotationViewer1.RemoteInvoked = function() {};
	var ret = WebAnnotationViewer1.getReturnValue();
	var props = ret.split(":");
	var n = 60;
	
	for (var i = 0; i < _properties.length; i++){
		n += setPropVal(_properties[i], props[i]);
	}
	
	Animation_Properties.slideIn.attributes.height.to = (494-n);
	Animation_Properties.slideIn.animate();
}

function setPropVal(id, val){
	var o = getObj(id);
	var v = getObj(id + 'Value')
	var n = 0;
	
	if (v){
		if (val && val != 'Not Used'){
			if (v.type === 'checkbox'){
				if (val == 'true'){
					v.checked = true;
				}
				else{
					v.checked = false;
				}
			}
			
			if (val.charAt(0) == "#"){
				var hex = val.substr(1);
				var ch = hex2argb(hex);
				setSwatchColor(ch[0], ch[1], ch[2], ch[3], hex, v);
			}
			
			v.value = val;
			v.disabled = false;
			
			if (o){
				if (o.tagName == 'DIV'){
					o.style.display = 'inline';
					n = 5;
				}
				else {
					o.style.display = '';
					n = 22;
				}
			}
		}
		else{
			v.value = '';
			v.disabled = true;
			
			if (o){
				o.style.display = 'none';
			}
		}
	}
	
	return n;
}

function FormatProperty(id)
{
	var v = getObj(id + 'Value')
	var c;
	if (v.type === 'checkbox'){
		v.value = v.checked;
	}

	c = v.value;

	if (c.charAt(0) == "#") {
		return c.substring(1);
	}
	
	return c;
}

function PropSave()
{
	getObj('propUpdate').disabled = true;
	
	var a = new Array();
	
	for (var i = 0; i < _properties.length; i++){
		a.push(FormatProperty(_properties[i]));
	}
	
	WebAnnotationViewer1.RemoteInvoked = OnAnnoPropertyDialogSaved;
	WebAnnotationViewer1.RemoteInvoke('SaveProps', a); 

	return false;
}

function OnAnnoPropertyDialogSaved()
{
	var ret = WebAnnotationViewer1.getReturnValue();
	if (ret != "") {
		alert(ret);
	}
	
	getObj('propUpdate').disabled = false;
	WebAnnotationViewer1.RemoteInvoked =  function() {};
	
	var anns = WebAnnotationViewer1.getSelectedAnnotations();
	for (var i = 0; i < anns.length; i++){
		anns[i].Update();
	}
	
	WebThumbnailViewer1.UpdateThumb(WebThumbnailViewer1.getSelectedIndex());
}
