// User Functions:
	function fnSelectImage(id){
		if(document.getElementById){
			var cbx = document.getElementById(id);
			if(!cbx.disabled){
				if(cbx.checked){
					cbx.checked = false;
				}else{
					cbx.checked = true;
				}
			}
		}
	}
	
	function fnViewImage(img_id,img_src,wid,hgt){
		if(parseInt(img_id) > 0){
			var xPos = Math.ceil( (screen.availWidth-parseInt(wid))/2 );
			var yPos = Math.ceil( (screen.availHeight-parseInt(hgt))/2 );
			window.open('jas_image_viewer.php?img_src='+img_src,'jasImageViewer_'+img_id,'HEIGHT='+hgt+',WIDTH='+wid+',screenX='+xPos+',screenY='+yPos+',left='+xPos+',top='+yPos);
		}
	}
	
	function fnAppPreview(event_id, app_key, ref){
		 if(parseInt(event_id) > 0){
			var xScreenWidth = screen.width;
			if(xScreenWidth < 1024 && false){
				alert('Your screen resolution must be set to a minimum of 1024x768 in order to use the application preview.');
				return false;
			} else {
				if(xScreenWidth < 1152){
					var oWid=screen.availWidth;
					var oHgt=screen.availHeight;
					var xPos=0;
					var yPos=0;
				} else {
					var oWid=1152;
					var oHgt=864;
					var xPos = Math.ceil( (screen.availWidth-parseInt(oWid))/2 );
					var yPos = Math.ceil( (screen.availHeight-parseInt(oHgt))/2 );
				}
				if (parseInt(event_id) == 32) {
					window.open("http://duchamp.juriedartservices.com:4777/view_app?app_key=" + app_key);
				} else {
					window.open('jas_app_viewer.php?event_id='+event_id+'&key='+app_key+'&ref='+ref, 'jas_app_viewer', 'HEIGHT='+oHgt+',WIDTH='+oWid+',screenX='+xPos+',screenY='+yPos+',left='+xPos+',top='+yPos);
				}
			}
		}else{
			return false;
		}
	}
	
	function fnDeleteImage(key,ao_name,port_id){
		var cfrm_delete = confirm("Are you sure you wish to delete \"" + ao_name + "\" ?  Clicking OK will permanently remove the image from your portfolio.\n*** WARNING: THIS ACTION CAN NOT BE UNDONE ***");
		if (cfrm_delete){
			document.forms['del_image'].hdn_txt_ao_key.value = key;
			document.forms['del_image'].hdn_int_port_id.value = port_id;
			document.forms['del_image'].x_form_handler.value = 'del_image';
			document.forms['del_image'].submit();
		}
	}
	
	function fnDeletePort(key){
		var cfrm_delete = confirm("Are you sure you wish to remove this portfolio?  Clicking OK will permanently delete this portfolio and all of its associated images.\n*** WARNING: THIS ACTION CAN NOT BE UNDONE ***");
		if (cfrm_delete){
			document.forms['edit_portfolio'].hdn_delete_port.value = key;
			document.forms['edit_portfolio'].x_form_handler.value = 'edit_portfolio';
			document.forms['edit_portfolio'].submit();
		}
	}
	
	function fnReturnPage(url){
		self.document.location = url;
	}
	
	function fnMemberTools(fld,color){
		fld.style.backgroundColor = color;
	}
	
	function fnChangePass(fld){
		if(fld.checked){
			alert('To change password please complete all 3 fields below.');
			oForm.x_old_pass_req.disabled = false;
			oForm.x_new_pass.disabled = false;
			oForm.x_passconfirm.disabled = false;
			oForm.x_old_pass_req.focus();
		}else{
			oForm.x_old_pass_req.disabled = true;
			oForm.x_new_pass.disabled = true;
			oForm.x_passconfirm.disabled = true;
		}
	}
	
	function fnFormatUSPhoneNum(str){
		var telnum = JustNumbers(str);
		var newString = new String('');
		if(telnum != ''){
			if(telnum.length==10){
				newString = '(' + telnum.substr(0,3) +') '+ telnum.substr(3,3)+'-'+telnum.substr(6);
			}else{
				newString = telnum;
			}
		}
		return newString
	}
	
	function fnSetStateField(oFld){
		if(oFld.value == 'US'){
			document.forms[0].sel_txt_state_req.value = '';
			document.forms[0].sel_txt_state_req.disabled = false;
			document.forms[0].txt_ucx_province.disabled = true;
		}else{
			document.forms[0].sel_txt_state_req.value = '';
			document.forms[0].sel_txt_state_req.disabled = true;
			document.forms[0].txt_ucx_province.disabled = false;
		}
	}
	
	function fnChangeRowBGColor(row,bgc){
		row.style.backgroundColor=bgc;
	}

// Application Functions:
	function fnCompleteApp(key){
		document.forms['form1'].hdn_app_complete.value = 1;
		document.forms['form1'].submit();
	}
	
	function fnRemoveImage(key,id,fileName){
		var cfrm_remove = confirm("Are you sure you wish to remove this image from your application?  Clicking OK will remove the image from your application but will not delete the image from your portfolio. ");
		if (cfrm_remove){
			document.forms['form2'].hdn_txt_app_key.value = key;
			document.forms['form2'].hdn_int_ai_id.value = id;
			document.forms['form2'].hdn_txt_file_name.value = fileName;
			document.forms['form2'].x_form_handler.value = 'del_image';
			document.forms['form2'].submit();
		}
	}
	
	function fnDeleteApp(key){
		var cfrm_delete = confirm("Are you sure you wish to delete this application?  Clicking OK will permanently delete this applicaiton.\n*** WARNING: THIS ACTION CAN NOT BE UNDONE ***");
		if (cfrm_delete){
			document.forms['form2'].hdn_txt_app_key.value = key;
			document.forms['form2'].x_form_handler.value = 'edit_application';
			document.forms['form2'].submit();
		}
	}
	
	function fnSubmitAppHistory(fld){
		var answer = true;
		//alert(document.getElementById("previousApp").value);
		
		//reset 
		
		
		if(document.getElementById("samecat").value == "true"){
			//check to see if we have a previous app
			//prompt here
			var answer = confirm("You have already applied in "+ oForm.catname.value +" to this show. Do you wish to continue? Click 'OK' if you wish to apply again. Click 'Cancel' to return to Manage Applications to review your existing application to this show.");
			if(!answer){
				window.location='http://www.juriedartservices.com/index.php?content=view_applications';	
			}
		}
		
		
		if(answer){
			var oForm2 = document.forms['form2'];
			var strAppName = fld.options[fld.selectedIndex].text ;
			var key = fld.value;
			var cnfrm_copy = confirm('Click OK to copy all images and descriptions from ' + strAppName + ' to this event.  After the new application is created you will be able to edit just as you would if creating a new application.');
			if(cnfrm_copy){
				oForm2.hdn_txt_app_key.value = key;
				oForm2.submit();
			}else{
				fld.value = '';
			}
		}
		
	}
	
	function fnReorderImages(pos,fld){
		var oForm = document.forms['form1'];
		var sel_val = parseInt(fld.value);
		var y = false;
		for (var i=0; i < oForm.elements.length; i++){
			var z = false;
			if(y){
				oForm.hdn_reorder_images.value = 'true';
				oForm.submit();
				break;
			}else{
				if(oForm.elements[i].type == 'radio'){
					if(oForm.elements[i].name != fld.name){
						var buttongroup = oForm.elements[oForm.elements[i].name];
						for (var p=0; p < buttongroup.length; p++){
							if(z){
								break;
							}else{
								if(buttongroup[p].checked){
									z = true;
									if(buttongroup[p].value==sel_val){
										y = true;
										buttongroup[pos-1].checked = true;
									}
								}
							}
						}
					}
				}
			}
		}
	}

	function fnCopyPortfolio(fld,n) {
		if(fld.checked){
			var idx=0;
			var strDesc = fld.value;
			var idLen = fld.id.length;
			oForm.txt_non_app_description_req.value = strDesc;
			textCounterSpan(oForm.txt_non_app_description_req,'len_description',1000);
			
			
		}
	}
