	var agt		= navigator.userAgent.toLowerCase();
	var IE 		= (navigator.appName=="Microsoft Internet Explorer") ? true : false;
	var is_ie5	= (IE && (agt.indexOf("msie 5.0")!=-1));
	var is_ie55	= (IE && (agt.search(/msie 5.5/)!=-1));
	var is_ie7plus = false;
	var downloadUrl;

	//versie 1.3

	// Conditional compilation
	/*@cc_on
	var is_ie7plus = (IE && (@_jscript_version >= 5.7));
	@*/
	// @_jscript_version 5.6 is IE6; 5.7 is IE7

	function changeStyle(boxid, hover) {
		var box = document.getElementById(boxid);
		if (hover) {
			if (boxid == "hp_login_box") {box.style.color = "rgb(102,102,102)";box.style.backgroundColor = "rgb(177,204,184)";}
			else {
				if (boxid == "hp_login_box_2") {box.style.color = "rgb(253,27,20)";box.style.backgroundColor = "rgb(177,204,184)";}
					else {
						if (boxid == "hp_login_box_logout") {box.style.color = "rgb(253,27,20)";box.style.backgroundColor = "rgb(177,204,184)";}
						else {box.style.backgroundColor = "rgb(168,179,171)";box.style.color = "#ffffff";}
						}
				}
		}
		else {
			if (boxid == "hp_login_box") {box.style.color = "rgb(253,27,20)";box.style.backgroundColor = "#ffffff"}
			else {
			if (boxid == "hp_login_box_2") {box.style.color = "rgb(102,102,102)";box.style.backgroundColor = "#ffffff"}
				else {
					if (boxid == "hp_login_box_logout") {box.style.color = "rgb(102,102,102)";box.style.backgroundColor = "#ffffff"}
					else {box.style.backgroundColor = "#ffffff";box.style.color = "rgb(102,102,102)";}
					}
				}
			}
	}

	function jumpToPage(jumppage) {

		var form = (document.forms[1]) ? document.forms[1] : document.forms[0];
		if (jumppage.toString().indexOf("-") != "-1") form.page.value = parseInt(form.page.value)-1;
		else if (jumppage.toString().indexOf("+") != "-1")
			form.page.value = parseInt(form.page.value)+1;
		else form.page.value = jumppage;
		if (form.action.indexOf("/search/modelname/alpha") != "-1") form.action = form.action;
		else if (document.forms[1]) {}
	//		else if (form.action.indexOf("/results") == -1) form.action = form.action+"/results";
		form.submit();
	}

	function jumpToSearchPage(jumppage) {
		// replace page number in URL
		var search = location.search.replace(/[&?]pn=\d+/, '');
		search += ('' == search ? '?' : '&') + 'pn=' + escape(jumppage);
		window.location = location.pathname + search;
	}

	function gotoAuthor( author_id )
	{
		var form = document.forms[0];
		form.action = '/search/browse/results/' + author_id + (1 < arguments.length ? arguments[1] : '');
		form.submit();
		return false;
	}

	function editSearch()
	{
		var form = document.forms[0];
		if ('undefined' != typeof(form.elements['depth']) && '1' == form.elements['depth'].value)
			form.action = '/search/model';
		else if ('undefined' != typeof(form.elements['alpha']) && '1' == form.elements['alpha'].value)
		{
			var type = 'model';
			var letter;
			if ( 'undefined' != typeof(form.elements['sauthor']) )
			{
				type = 'author';
				letter = form.elements['sauthor'].value;
			}
			else
				letter = form.elements[''].value;

			form.action = '/search/' + type + '/alpha/' + letter.substring(0, 1).toUpperCase();
		}

		form.elements['edit'].value = 1;
		form.submit();
		return false;
	}

	var end = 0;

	function showPopup(item, enable, height) {
		hideConfirm();
		window.end = height;
		var popupel	= document.getElementById(item+"popup");

		var popupel				= document.getElementById(item+"popup");
		var popupelheight		= popupel.style.height.substring(0,popupel.style.height.length-2);
		if(popupelheight > 0)
			enable = false;

		if (is_ie5) {var popupiframe = document.getElementById(item+"frTest");popupiframe.src = '/html/'+item+'_popup.html';}
		if (IE && !is_ie7plus) {
			var timeout = 25;
			if (enable != false) ShowMenu(item);
		} else var timeout = 1;
		if (enable == false) {
			var start = window.end;
			setHeight(item,start,enable,timeout);
			var els = document.forms[0];
			var ellength = els.length;
			var regexp = new RegExp("^"+item+"_item_([0-9])");
			for (i = 0; i < ellength; ++i) {if (els[i].name.match(regexp)) {if (els[i].readOnly) {els[i].value = "";}els[i].disabled = true;}}
		} else {
			var els = document.forms[0];
			var ellength = els.length;
			var regexp = new RegExp("^"+item+"_item_([0-9])");
			for (i = 0; i < ellength; ++i) {if (els[i].name.match(regexp)) els[i].disabled = false;}
			popupel.style.display = "inline";
			setHeight(item,0,enable,timeout);
		}
	}

	function setHeight(item, i, enable, timeout) {
		var popupel				= document.getElementById(item+"popup");
		if (IE) var popupiframe = document.getElementById(item+"frTest");
		var popupelheight		= i;
		if (IE) var popupiframeheight = i;
		if (enable == false) {
			var popupelsub	= document.getElementById(item+"popupsub");
			popupelsub.style.display = "none";
			if (popupelheight > 0) {
				var newheight = (i-(window.end/10) > 0) ? i-(window.end/10) : 0;
				popupel.style.height		= newheight+"px";
				if (IE) popupiframe.style.height	= newheight+"px";
				setTimeout("setHeight('"+item+"', "+newheight+", false, "+timeout+")",timeout);
			} else {
				popupel.style.display = "none";
				if (IE) popupiframe.style.display = "none";
			}
		} else {
			if (popupelheight < window.end) {
				var newheight = (i+(window.end/10) > 0) ? i+(window.end/10) : 0;
				popupel.style.height		= newheight+"px";
				if (IE) popupiframe.style.height	= newheight+"px";
				setTimeout("setHeight('"+item+"', "+newheight+", true, "+timeout+")",timeout);
			} else {
				if (!is_ie5) {
					var popupelsub	= document.getElementById(item+"popupsub");
					popupelsub.style.display = "block";
				}
			}
		}
	}

	function showImage( model )
	{
		var w = window.open('/' + model + '/image', 'pm_model_image', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150');
		w.focus();
		return false;
	}

	function ShowMenu(item) {
		var frTest = document.getElementById(item+"frTest");
		frTest.style.display = "inline";
		frTest.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
		frTest.style.backgroundColor = "#FFF";
	}

	function addItemToList(list, classname,id) {
		var popupel				= document.getElementById(list+"popup");
		if (IE) var popupiframe	= document.getElementById(list+"frTest");
		var popupelheight		= popupel.style.height.substring(0,popupel.style.height.length-2);
		if (IE) var popupiframeheight	= popupiframe.style.height.substring(0,popupiframe.style.height.length-2);
		var popupelsub			= document.getElementById(list+"popupsub");
		popupelsub.style.display = "none";
		classname = (typeof classname != "undefined") ? classname : false;
		if (popupelheight > 0) {
			var newheight = (popupelheight-(window.end/10) > 0) ? popupelheight-(window.end/10) : 0;
			popupel.style.height		= newheight+"px";
			if (IE) popupiframe.style.height	= newheight+"px";
			setTimeout("addItemToList('"+list+"', "+classname+","+id+")",1);
		} else {
			popupel.style.display = "none";
			if (IE) popupiframe.style.display = "none";
			if (list == "author" || list == "author_reference") {
				if (eval("document.forms[0]."+list+"_item_1.value") != "" && eval("document.forms[0]."+list+"_item_2.value") != "") var newoption = eval("document.forms[0]."+list+"_item_2.value")+", "+eval("document.forms[0]."+list+"_item_1.value");
				else if (eval("document.forms[0]."+list+"_item_2.value") == "") {
					if (eval("document.forms[0]."+list+"_item_4.value") == "") var newoption = eval("document.forms[0]."+list+"_item_3.options[document.forms[0]."+list+"_item_3.selectedIndex].text");
					else var newoption = eval("document.forms[0]."+list+"_item_4.value");
				} else var newoption = eval("document.forms[0]."+list+"_item_2.value");
			} else if (list == "submittor") {
				if (eval("document.forms[0]."+list+"_item_2.value") != "" && eval("document.forms[0]."+list+"_item_3.value") != "") var newoption = eval("document.forms[0]."+list+"_item_3.value")+", "+eval("document.forms[0]."+list+"_item_2.value");
				else if (eval("document.forms[0]."+list+"_item_3.value") == "" && eval("document.forms[0]."+list+"_item_1.selectedIndex") == 0) {
					if (eval("document.forms[0]."+list+"_item_5.value") == "") var newoption = eval("document.forms[0]."+list+"_item_4.options[document.forms[0]."+list+"_item_4.selectedIndex].text");
					else var newoption = eval("document.forms[0]."+list+"_item_5.value");
				} else if (eval("document.forms[0]."+list+"_item_1.selectedIndex") != 0) var newoption = eval("document.forms[0]."+list+"_item_1.options[document.forms[0]."+list+"_item_1.selectedIndex].text");
				else var newoption = eval("document.forms[0]."+list+"_item_3.value");
			} else var newoption = eval("document.forms[0]."+list+"_item_1.value");
			if (list == "topic") {
				var parent_topic1	= eval("document.forms[0]."+list+"_item_4.value");
				var parent_topic2	= eval("document.forms[0]."+list+"_item_5.value");

//				if(parent_topic1 || parent_topic2)
//					var newoption = "&#187; "+ newoption;
			}

			var regexp1		= new RegExp("^"+list);
			var container	= document.getElementById(list+"container");
			if ( container )
			{
				var els			= document.getElementById(list+"container").getElementsByTagName("select");
				var ellength	= els.length;
				var temparray	= new Array;
				var j			= 1;
				for (e = 0; e < ellength; ++e)
					if (els[e].id.match(regexp1)){
						temparray[j] = els[e].selectedIndex;++j;

					}

				if (classname == true) var classname = "_1";
				else var classname = "";
				if (list == "author_reference")
					boxtitle = "author";
				else boxtitle 	= list;
				var container 	= document.getElementById(list+'container');
				var containerid	= list +'container';

				addInputFields(containerid, true);
				var r = document.getElementById(containerid).getElementsByTagName('select');
				var containerid_select = containerid.substring(0,containerid.length-9);

				// add option to each select list AND do sort
				for (i = 0; i < r.length; i++) {
					tl	= r[i].options.length;
					var option = document.createElement('option');
					r[i].appendChild(option);
					option.text  = newoption;
					option.value = id;
					if (i+1 == r.length){r[i].options[tl].selected = true;}
					//sort select list
					sortSelect(r[i], true);
				}

				//empty fields list+'item_'+count
				var els 		= document.forms[0];
				var ellength 	= els.length;
				var regexp 		= new RegExp("^"+list+"_item_([0-9])");
				for (i = 0; i < ellength; ++i) {if (els[i].name.match(regexp)) els[i].value = '';}
			}
		}
	}

	function storeContent(url,validationtype) {

		/* set url to jumpto */
		if (url) { document.forms[0].page.value = url; }

		if(validationtype){
			if(validateInput(validationtype)){
				/* start loading  (old code not working in safari; new code seems compatible with all browsers)
				if (IE) showLoading(); // or else bullets won't work in IE?
				if (IE && !is_ie7plus)setTimeout('document.forms[0].submit()', 500);
				else document.forms[0].submit();
				if (!IE) showLoading(); // or else bullets won't work in FF?
				*/
				showLoading();
				setTimeout('document.forms[0].submit()', 500);
			}
		}else{
			validateInput();
			showLoading();
			setTimeout('document.forms[0].submit()', 500);
		}
	}

	function showLoading() {
		if (IE) var confirmframe	= document.getElementById("confirmFrame");
		if (is_ie5) confirmframe.src = '/html/confirm_popup.html';
		document.getElementById("msg").style.display = "none";
		document.getElementById("msg").innerHTML = '';
		document.getElementById("confirmmodal").innerHTML = '<div id="loading">&nbsp;</div>';
		displayModal();
		return false;
	}


	function downloadAsset(url,user_id,asset_id,model_id) {
		var mailForm = '';
		downloadUrl 	= url;
		mailForm = "<div id='form'>";
		mailForm += '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">';
		mailForm += "<h2 class='donate'>support ProvenModels</h2>";
		mailForm += "<div id='error'></div>";
		mailForm += '	<input type="hidden" name="cmd" value="_s-xclick">';
		mailForm += '	<input type="hidden" name="asset_id" id="asset_id" value="'+asset_id+'">';
		mailForm += '	<input type="hidden" name="user_id" id="user_id" value="'+user_id+'">';
		mailForm += '	<input type="hidden" name="model_id" id="model_id" value="'+model_id+'">';
		mailForm += '	<input type="hidden" name="custom" value="'+url+'">';
//		mailForm += '	<input type="hidden" name="currency_code" value="Euro">';
		mailForm += '	<input type="hidden" name="return" value="http://www.provenmodels.com/'+model_id+'?downloadevent=getdownload&asset_id='+asset_id+'&model_id='+model_id+'&user_id='+user_id+'">';
		mailForm += '	<input type="hidden" name="rm" value="2">';

		mailForm += '	<input type="hidden" name="hosted_button_id" value="10385663">';
		mailForm += '	<img alt="" border="0" src="https://www.paypal.com/nl_NL/i/scr/pixel.gif" width="1" height="1">';
mailForm += "	<div>This model asset comes at no charge.<br >Please donate to help us add more management models and continue this service.</div>";
		mailForm += "	<div style='margin-right: 0px; float: right; margin-top: 17px' class='buttons'>";
		//mailForm += '		<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online." style="border: 0px; margin-left: 17px;" >';
		mailForm += '		<button type="button" onclick=\"saveDonation(downloadUrl); return false;\" style="margin-left: 17px;"  class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">cancel</button>';
		mailForm += "	</div>";
		mailForm += "	<div style='margin-right: 0px; float: right; margin-top: 17px' class='buttons'>";
		mailForm += '		<button type="submit" name="submit" alt="PayPal - The safer, easier way to pay online." class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">donate</button>';
		mailForm += "	</div>";
		mailForm += "</form>";
		mailForm += "</div>";

		document.getElementById("mailmodal").innerHTML = mailForm;
		displayModal("mailmodal");
	}

	function donationThankyou(){

		initModal();
		var mailForm = '';
		var amount = amount;

		mailForm 	 = "<div id='form'>";
		mailForm += "<h2 class='donate'>thank you</h2>";
mailForm += "	<div>Thank you for your donation. We value your support.</div>";
		mailForm += "	<div style='margin-right: 0px; float: right; margin-top: 17px' class='buttons'>";
		mailForm += '		<button type="button" onclick=\"hideConfirm(); return false;\" style="margin-left: 17px;"  class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">close</button>';
		mailForm += "	</div>";
		mailForm += "</div>";

		document.getElementById("mailmodal").innerHTML = mailForm;
		displayModal("mailmodal");
	}

	/**
	 *
	 * @access public
	 * @return void
	 **/
	function saveDonation(url){

		var asset_id		= $("asset_id").value;
		var user_id			= $("user_id").value;
		var model_id		= $("model_id").value;

		updateDownload(url,model_id,asset_id,user_id);
		hideConfirm();
	}

	function updateDownload(url,model_id,asset_id,user_id){


		// prepare post options and fields
		var postValues 		= 'asset_id='+asset_id+'&user_id='+user_id+'&assets_users_donation=0';
		var saveOptions = {
		    method : 	'post',
		    encoding:   'UTF-8',
		    postBody: 	'downloadevent=updatedownload&'+postValues,
			onSuccess:	function(){},
			onFailure:	function(){}
		};

		// do request
		new Ajax.Request('/'+model_id, saveOptions);
		window.open('http://www.provenmodels.com/'+url);
		window.location.reload();
	}


	function showEmailDialog(id,name,subject,context) {
		var mailForm = '';

		mailForm = "<div id='form'>";
		mailForm += "<form action='' method='post' onsubmit='return sendEmail();' >";
		mailForm += "<h2>send email to: "+name+"</h2>";
		mailForm += "<div id='error'></div>";
		mailForm += "<input style='width:300px; text-indent: 0; margin-bottom: 17px' type='text' name='subject' id='subject' value='"+subject+"' /><br />";
		mailForm += "<textarea style='width:297px;' name='message' id='message' rows='5' cols='79'></textarea>";
		mailForm += "<div style='margin-right: 0px; float: right; margin-top: 17px' class='buttons'>";
		mailForm += "	<button id='sendbutton' style='margin-right: 17px;' class='submit_button' type='submit' onmouseover=\"this.className='submit_button_hover';return true;\" onmouseout=\"this.className='submit_button';return true;\">send mail </button>";
		mailForm += '	<button type="button" onclick="hideConfirm();this.className=\'submit_button cancel\';return false;" class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">cancel</button>';
		mailForm += "</div><br />";
		mailForm += "<input type='hidden' name='id' id='id' value='"+id+"' />";
		mailForm += "<input type='hidden' name='context' id='context' value='"+context+"' />";
		mailForm += "<input type='hidden' name='name' id='name' value='"+name+"' />";
		mailForm += "</form>";
		mailForm += "</div>";

		document.getElementById("mailmodal").innerHTML = mailForm;
		displayModal("mailmodal");

		return false;
	}

	function sendEmail(topicid,modelcount,bordercolor,showtitle,modeltype)
	{
		showLoading();
		document.getElementById("mailmodal").style.display = 'none';

		var subject			= $("subject").serialize(true);
		var message			= $("message").serialize(true);
		var id				= $("id").serialize(true);
		var name			= $("name").serialize(true);
		var context			= $("context").serialize(true);
		var postValues 		= subject+'&'+message+'&'+id+'&'+name+'&'+context;

		if(!message)
			$('error').innerHTML = 'Please write a message.';

		var loadOptions = {
		    method : 	'post',
		    encoding:   'UTF-8',
		    postBody: 	postValues,
			onSuccess:	handlerFuncSendEmail,
			onFailure:	errFuncSendEmail
		};

		// do request
		new Ajax.Request('/user/sendemail', loadOptions);

		return false;
	}

	var handlerFuncSendEmail = function(t) {
		document.getElementById("mailmodal").style.display = 'block';
		document.getElementById("confirmmodal").style.display = 'none';
		try {
			var textResponse  	= t.responseText;
		} catch(e) {
			var textResponse	= e.message;
		}

		$('form').innerHTML 			= textResponse + '<br/><br/><button style="float: right;" type="button" onclick="hideConfirm();this.className=\'submit_button cancel\';return false;" class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">close</button>';
		return false;
	}

	var errFuncSendEmail = function(t) {
		displayModal("mailmodal");
		$('form').innerHTML   = '';
		$('error').innerHTML  = 'Unable to send message!  <br/><br/><button style="float: right;" type="button" onclick="hideConfirm();this.className=\'submit_button cancel\';return false;" class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">close</button>';
		document.getElementById("confirmFrame").style.display = 'none';
		document.getElementById("mailmodal").style.display = 'block';
		return false;
	}

	function removeImage() {
		showConfirm("are you sure that you want to remove the model's image?", false, true);
	}

	function removeUserImage() {
		showUserConfirm("are you sure that you want to remove your image?", true);
	}

	function showUserConfirm(question, remove)
	{
		remove = (typeof remove == "undefined") ? false : true;
		if (IE && !is_ie7plus) var confirmframe	= document.getElementById("confirmFrame");

		if(remove){
			var confirmClick 	= "document.forms[0].removeImage.value='true';this.className=\'submit_button\';document.forms[0].submit();return true;";
			var cancelClick 	= "document.forms[0].removeImage.value='';";
		}else{
			var confirmClick 	= "this.className=\'submit_button\';document.forms[0].submit();return true;";
			var cancelClick 	= "document.forms[0].removeImage.value=\'\'; document.getElementById('user_visibility').options[document.getElementById('current_user_visibility').value].selected = true;";
		}


		document.getElementById("msg").innerHTML = question;
		document.getElementById("confirmmodal").innerHTML = '<button id="confirm_submit" type="button" onclick="'+confirmClick+'" class="submit_button" onmouseover="this.className=\'submit_button_hover\';return true;" onmouseout="this.className=\'submit_button\';return true;">yes</button>'+
			'<button type="button" onclick="'+cancelClick+';hideConfirm();this.className=\'submit_button cancel\';return false;" class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">cancel</button>';

		displayModal();

		document.getElementById("remove_image").focus();
		return false;
	}

	/**
	 *
	 * @access public
	 * @return void
	 **/
	function showHelp(help)
	{
		initModal();
		document.getElementById("mailmodal").style.display = 'block';
		document.getElementById("mailmodal").innerHTML = "<div id='form'>"+help+"</div>" + '<button style="float: right;" type="button" onclick="hideConfirm(); this.className=\'submit_button cancel\';return false;" class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">close</button>';
		displayModal("mailmodal");
		return false;
	}

	function confirmProfileVisibility(select,url) {
		if (select.options[select.selectedIndex].value == 'none') {
			showUserConfirm("are you sure that you want to change your profile's visibility?");
		}else if(document.getElementById('current_user_visibility').value == 2){
			document.forms[0].submit();
		}else{
			document.getElementById('current_user_visibility').value = select.selectedIndex;
		}
		return false;
	}


	function confirmSubmit(url) {

		if (validateInput()) {
			if(showConfirm("are you sure that you want to submit this model?"))
				if (url)
					document.forms[0].page.value = url;
		}
		return false;
	}

	function hideConfirm(div, height) {
		if (div) {
			var divel			= document.getElementById(div+"popup");
			if (IE) var diviframe = document.getElementById(div+"frTest");
			var divsub			= document.getElementById(div+"popupsub");
			divsub.style.display = "none";
			if (height > 0) {
				var newheight = (height-(window.end/10) > 0) ? height-(window.end/10) : 0;
				divel.style.height		= newheight+"px";
				if (IE) diviframe.style.height	= newheight+"px";
				setTimeout("hideConfirm('"+div+"', "+newheight+")",1);
			} else {
				divel.style.display = "none";
				if (IE) diviframe.style.display = "none";
				var inputs		= divel.getElementsByTagName("input");
				var selects		= divel.getElementsByTagName("select");
				var textareas	= divel.getElementsByTagName("textarea");
				for (x = 0; x < inputs.length; ++x) {if(!inputs[x].readOnly){inputs[x].value = "";}inputs[x].disabled = true;}
				for (x = 0; x < selects.length; ++x) {selects[x].selectedIndex = 0;selects[x].disabled = true;}
				for (x = 0; x < textareas.length; ++x) {if(!textareas[x].readOnly){textareas[x].value = "";}textareas[x].disabled = true;}
			}
		} else {
			if (document.getElementById('confirm')) document.getElementById('modal').style.display = 'none';
			var divs = document.forms[0].getElementsByTagName("div");
			var els = divs.length;
			for (d = 0; d < els; ++d) {
				if (divs[d].className.match("popup")) {
					var divitem		= divs[d].id.substring(0,divs[d].id.length-5);
					var divheight	= parseInt(divs[d].style.height.substring(0,divs[d].style.height.length-2));
					if (!isNaN(divheight) && divheight > 0) {
						window.end = divheight;
						if (IE) var diviframe		= document.getElementById(divitem+"frTest");
						var divsub			= document.getElementById(divitem+"popupsub");
						divsub.style.display = "none";
						classname = (typeof classname != "undefined") ? classname : false;
						var newheight = (divheight-(window.end/10) > 0) ? divheight-(window.end/10) : 0;
						divs[d].style.height		= newheight+"px";
						if (IE) diviframe.style.height		= newheight+"px";
						setTimeout("hideConfirm('"+divitem+"', "+newheight+")",1);
					}
				}
			}
		}
	}

	function keyPressHandler(e) {
		var kC  = (window.event) ?    // MSIE or Firefox
				event.keyCode : e.keyCode;
		var Esc = (window.event) ?
				27 : e.DOM_VK_ESCAPE; // MSIE : Firefox
		if (kC == Esc) {
			hideConfirm();
			if (document.getElementById('cal')) hideCal();
		}
	}

	function countChars(item) {
		var span = document.getElementById("charCount_"+item.name);
		span.innerHTML = item.value.length;
	}

	function showConfirm(question, publish, remove) {
		remove = (typeof remove == "undefined") ? false : true;

		publish = (typeof publish == "undefined") ? "true" : "";
		if (IE && !is_ie7plus) var confirmframe	= document.getElementById("confirmFrame");
		if (is_ie5) {
			windowparent = "window.parent.";
			confirmframe.src = '/html/confirm_popup.html';
		} else windowparent = "";

		document.getElementById("msg").innerHTML = question;
		document.getElementById("confirmmodal").innerHTML = '<button id="confirm_submit" type="button" onclick="if('+remove+'){if('+windowparent+'document.forms[0].image_title){'+windowparent+'document.forms[0].image_title.value=\'\';}}'+windowparent+'document.forms[0].publish.value=\''+publish+'\';'+windowparent+'storeContent();this.className=\'submit_button\';return true;" class="submit_button" onmouseover="this.className=\'submit_button_hover\';return true;" onmouseout="this.className=\'submit_button\';return true;">yes</button>'+
			'<button type="button" onclick="'+windowparent+'document.forms[0].publish.value=\'\';'+windowparent+'hideConfirm();this.className=\'submit_button cancel\';return false;" class="submit_button cancel" onmouseover="this.className=\'submit_button_hover cancel\';return true;" onmouseout="this.className=\'submit_button cancel\';return false;">cancel</button>';

		displayModal();

		document.getElementById("confirm_submit").focus();
		return false;
	}

	function showAlert(msg, jumpto) {

		if (is_ie5) {
			if (jumpto) clickAction = "window.parent.storeContent(\'"+jumpto+"\','acceptmodal');";
			else clickAction = "window.parent.hideAlert();";
		} else {
			if (jumpto) clickAction = "storeContent(\'"+jumpto+"\','acceptmodal');";
			else clickAction = "hideAlert();";
		}
		if (IE && !is_ie7plus) var confirmframe	= document.getElementById("confirmFrame");
		if (is_ie5) confirmframe.src = '/html/confirm_popup.html';

		document.getElementById("msg").innerHTML = msg;
		document.getElementById("confirmmodal").innerHTML = '<button id="alert" type="button" onclick="'+clickAction+'this.className=\'submit_button\';return false;" class="submit_button" onmouseover="this.className=\'submit_button_hover\';return true;" onmouseout="this.className=\'submit_button\';return true;">ok</button>';

		displayModal();

		if (!is_ie5) document.getElementById("alert").focus();
		return false;
	}

	function displayModal(modalname) {
		if(!modalname)
			modalname	= 'confirm';

		var modal	= document.getElementById("modal");
		
		if(modalname != 'mailmodal'){
			document.getElementById('mailmodal').style.display = 'none';
		}
		modal.style.display	= "block";
		var confirmpopup			= document.getElementById(modalname);
		if (!IE) var confirmback	= document.getElementById("confirmback");
		if (is_ie7plus) var confirmback	= document.getElementById("confirmback");
		if (IE && !is_ie7plus) var confirmframe	= document.getElementById("confirmFrame");
		confirmpopup.style.display = "block";
		if (IE && !is_ie7plus) confirmframe.style.display = "block";

		if (IE && !is_ie7plus) {
			if (location.href.indexOf("search") != -1 || is_ie5 || is_ie55) {
				confirmpopup.style.marginTop	= parseInt(document.body.clientHeight / 2 - (confirmpopup.offsetHeight / 2)) + "px";
				confirmpopup.style.marginLeft	= parseInt(document.body.clientWidth / 2 - (confirmpopup.offsetWidth / 2)) + "px";
				confirmframe.style.marginTop	= parseInt(document.body.clientHeight / 2 - (confirmpopup.offsetHeight / 2) - 1) + "px";
				confirmframe.style.marginLeft	= parseInt(document.body.clientWidth / 2 - (confirmpopup.offsetWidth / 2) - 1) + "px";
				confirmframe.style.width		= parseInt(confirmpopup.offsetWidth)+"px";
				confirmframe.style.height		= parseInt(confirmpopup.offsetHeight)+"px";
			} else {
				if (document.documentElement && document.documentElement.scrollTop)
					scrollTop = document.documentElement.scrollTop;
				else if (document.body)
					scrollTop = document.body.scrollTop;
				confirmpopup.style.marginTop	= parseInt(document.documentElement.clientHeight / 2 - (confirmpopup.offsetHeight / 2)) + "px";
				confirmpopup.style.marginLeft	= parseInt(document.documentElement.clientWidth / 2 - (confirmpopup.offsetWidth / 2)) + "px";
				confirmframe.style.marginTop	= parseInt(document.documentElement.clientHeight / 2 - (confirmpopup.offsetHeight / 2) - 1) + "px";
				confirmframe.style.marginLeft	= parseInt(document.documentElement.clientWidth / 2 - (confirmpopup.offsetWidth / 2) - 1) + "px";
				confirmframe.style.width		= parseInt(confirmpopup.offsetWidth-2)+"px";
				confirmframe.style.height		= parseInt(confirmpopup.offsetHeight)+"px";
			}
		} else {
			confirmpopup.style.marginTop	= parseInt(-(confirmpopup.offsetHeight/2))+"px";
			confirmpopup.style.marginLeft	= parseInt(-(confirmpopup.offsetWidth/2))+"px";
		}
		return false;
	}

	function hideAlert() {
		if (document.getElementById('confirm')) {
			if (!IE) document.getElementById('confirmback').style.display = 'none';
			if (IE && is_ie7plus) document.getElementById('confirmback').style.display = 'none';
			if (IE && !is_ie7plus) document.getElementById('confirmFrame').style.display = 'none';
			document.getElementById('confirm').style.display	= 'none';
			document.getElementById('modal').style.display		= 'none';
			document.getElementById("msg").innerHTML = '';
			document.getElementById("confirmmodal").innerHTML = '';
		}
	}

	function onChangeSetColor( select, normalColor, setColor )
	{
		var elem;
		var i;

		// reset option class
		for ( i = 0; i < select.options.length; ++i )
			select.options[i].style.color = setColor;

		// set supplied color for option
		select.options[select.selectedIndex].style.color = normalColor;

		return true;
	}

	function searchAuthor() {
		if (document.forms[0].elements['sauthor'].value != '') {
			document.forms[0].action='/search/author/results';
			document.forms[0].submit();
		} else {
			if (IE) var confirmframe	= document.getElementById("confirmFrame");
			if (is_ie5) confirmframe.src = '/html/confirm_popup.html';

			var msg	= "some required information was left blank.<br />please read the following:<ul>"+
				"<li>You forgot to enter a <strong>search value</strong> for an author</li>"+
				"</ul>";
			document.getElementById("msg").innerHTML = msg;
			document.getElementById("confirmmodal").innerHTML = '<button id="alert" type="button" onclick="hideAlert();this.className=\'submit_button\';return false;" class="submit_button" onmouseover="this.className=\'submit_button_hover\';return true;" onmouseout="this.className=\'submit_button\';return true;">ok</button>';

			displayModal();

			document.getElementById("alert").focus();
			return false;
		}
	}

	function searchCharacteristic( field, value )
	{
		var i;

		for ( i = 0; i < document.forms['formSearchCharacteristic'].elements.length; ++i )
			if ( 'language' != document.forms['formSearchCharacteristic'].elements[i].name )
				document.forms['formSearchCharacteristic'].elements[i].value = '';

		document.forms['formSearchCharacteristic'].elements[field].value = value;
		document.forms['formSearchCharacteristic'].submit();
		return false;
	}

	function uncheckAll(field) {
		var fields = document.forms[1].getElementsByTagName("input");
		for (f = 0; f < fields.length; ++f)
			if (fields[f].name.match(field) && fields[f].name != field)
				if (eval("document.forms[1]."+field).checked) fields[f].checked = false;
	}

	function uncheck(field) {
		eval("document.forms[1]."+field).checked = false;
	}

	function removeModel(modelid) {
		if (IE && !is_ie7plus) var confirmframe	= document.getElementById("confirmFrame");
		if (is_ie5) {
			windowparent = "window.parent.";
			confirmframe.src = '/html/confirm_popup.html';
		} else windowparent = "";

		document.getElementById("msg").innerHTML = "Please beware that you cannot undo the removal of this model.<br />Are you sure that you want to remove this model?";
		document.getElementById("confirmmodal").innerHTML = '<button id="confirm_submit" type="button" onclick="'+windowparent+'document.forms[0].removemodel.value=true;'+windowparent+'doRemove();this.className=\'submit_button\';return true;" class="submit_button" onmouseover="this.className=\'submit_button_hover\';return true;" onmouseout="this.className=\'submit_button\';return true;">yes</button>'+
			'<button type="button" onclick="'+windowparent+'document.forms[0].removemodel.value=\'\';'+windowparent+'hideConfirm();this.className=\'submit_button\';return true;" class="submit_button" onmouseover="this.className=\'submit_button_hover\';return true;" onmouseout="this.className=\'submit_button\';return true;">cancel</button>';
		displayModal();

		document.getElementById("alert").focus();
		return false;
	}

	function doRemove() {
		document.forms[0].submit();
	}

	if (document.all) document.onkeydown = keyPressHandler;
	else window.onkeypress = keyPressHandler;

	window.onload = initModal;

	function initModal() {
		var temp;
		var msg;

		// needed to load on window load
		simulateDisabled();


		temp   = '<div id="confirm" class="confirm" style="display:none;">';
		temp   += '	<div id="msg"></div>';
		temp   += '	<div id="confirmmodal"></div>';
		temp   += '</div>';
		temp   += '	<div id="mailmodal" ></div>';
		if (IE && is_ie7plus) temp += '<div style="display:none;" id="confirmback" class="confirmback"></div>';
		if (IE && !is_ie7plus) temp   += '<iframe style="display:none;border:1px solid;" id="confirmFrame" class="confirmFrame" frameborder="0" scrolling="no" marginwidth="0" src="" marginheight="0"></iframe>';
		if (!IE) temp  += '<div style="display:none;" id="confirmback" class="confirmback"></div>';

		var modal = document.getElementById("modal");
		modal.innerHTML = temp;
	}

	 // sort function - ascending (case-insensitive)
        function sortFuncAsc(record1, record2) {
            var value1 = record1.optText.toLowerCase();
            var value2 = record2.optText.toLowerCase();
            if (value1 > value2) return(1);
            if (value1 < value2) return(-1);
            return(0);
        }

        // sort function - descending (case-insensitive)
        function sortFuncDesc(record1, record2) {
            var value1 = record1.optText.toLowerCase();
            var value2 = record2.optText.toLowerCase();
            if (value1 > value2) return(-1);
            if (value1 < value2) return(1);
            return(0);
        }

        function sortSelect(selectToSort, ascendingOrder) {
            if (arguments.length == 1) ascendingOrder = true;    // default to ascending sort

			//keep first option
			var firstrecord	= [];
			firstrecord[0]	= {optText:selectToSort.options[0].text, optValue:selectToSort.options[0].value };
            if(selectToSort.options[0].selected == true)
            	var selectedValue = selectToSort.options[0].value;

			// copy options into an array
			var myOptions	= [];
            for (var loop=1; loop<selectToSort.options.length; loop++) {
                myOptions[loop-1] = { optText:selectToSort.options[loop].text, optValue:selectToSort.options[loop].value };
                if(selectToSort.options[loop].selected == true)
                	var selectedValue = selectToSort.options[loop].value;
            }

            // sort array
            if (ascendingOrder) {
                myOptions.sort(sortFuncAsc);
            } else {
                myOptions.sort(sortFuncDesc);
            }

			// recreate list
            selectToSort.options.length = 0;

			//add first record
            var optObj = document.createElement('option');
            optObj.text = firstrecord[0].optText;
            optObj.value = firstrecord[0].optValue;
            if(firstrecord[0].optValue == selectedValue)
            	optObj.selected = true;
            selectToSort.options.add(optObj);

            // copy sorted options from array back to select box
            for (var loop=0; loop<myOptions.length; loop++) {
                var optObj = document.createElement('option');
                optObj.text = myOptions[loop].optText;
                optObj.value = myOptions[loop].optValue;
                if(myOptions[loop].optValue == selectedValue)
                	optObj.selected = true;
                selectToSort.options.add(optObj);
            }
        }

		function trim(value) {
		  value = value.replace(/^\s+/,'');
		  value = value.replace(/\s+$/,'');
		  return value;
		}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

	function simulateDisabled()
	{
		if (document.getElementsByTagName) {
			var s = document.getElementsByTagName("select");
			if (s.length > 0) {
				window.select_current = new Array();
				for (var i=0, select; select = s[i]; i++) {
					if(s[i].id == 'checkdisabled'){
						select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }
						select.onchange = function(){ restore(this); }
						emulate(select);
					}
				}
			}
		}
	}

	function restore(e)
	{
		if (e.options[e.selectedIndex].disabled) {
			e.selectedIndex = window.select_current[e.id];
		}else{
			document.forms[0].submit();
		}
	}

	function emulate(e)
	{
		for (var i=0, option; option = e.options[i]; i++) {
			if (option.disabled) {
				option.style.color = "graytext";
			} else {
				option.style.color = "menutext";
			}
		}
	}

	function clearField(obj)
{
	if(obj.value == 'Please add your profile summary here.'){
		obj.value = '';
	}
}

