
function isBetween(value,value_min,value_max,can_match_exactly){if(strict){return(value>value_min&&value<value_max);}else{return(value>=value_min&&value<=value_max);}}
function variableDefined(name){return typeof this[name]!=='undefined';}
function isArray(input){return typeof(input)=='object'&&(input instanceof Array);}
function isObject(mixed_var){if(mixed_var instanceof Array){return false;}else{return(mixed_var!==null)&&(typeof(mixed_var)=='object');}}
$(function(){if($.browser.msie){$('input:radio').click(function(){this.blur();this.focus();});}});function getImageBestFit(width,height,max_width,max_height,allow_stretch,scale_to){if(allow_stretch||width>max_width||height>max_height){width_ratio=max_width/width;height_ratio=max_height/height;if(scale_to){ratio=(scale_to=='width')?width_ratio:height_ratio;width=(scale_to=='width')?max_width:Math.round(ratio*width);height=(scale_to=='width')?Math.round(ratio*height):max_height;}else{ratio=(width_ratio<=height_ratio)?width_ratio:height_ratio;width=Math.round(ratio*width);height=Math.round(ratio*height);}}
return Array(width,height);}
function setImageSize(which,max_with,max_height,allow_stretch,scale_to){image_size=getImageBestFit($(which).width(),$(which).height(),max_width,max_height,allow_stretch,scale_to);$(which).attr('width',image_size[0]);$(which).attr('height',image_size[1]);}
function addQueryStringVar(url,param,value){var re=new RegExp("([?|&])"+param+"=.*?(&|$)","i");if(url.match(re))return url.replace(re,'$1'+param+"="+value+'$2');else return url+'&'+param+"="+value;};function removeQuerysStringVar(url,key){var urlparts=url.split('?');if(urlparts.length>=2){var prefix=encodeURIComponent(key)+'=';var pars=urlparts[1].split(/[&;]/g);for(var i=pars.length;i-->0;)
if(pars[i].lastIndexOf(prefix,0)!==-1)
pars.splice(i,1);url=urlparts[0]+'?'+pars.join('&');}
return url;}
function htmlEntityDecode(str){try{var tarea=document.createElement('textarea');tarea.innerHTML=str;return tarea.value;tarea.parentNode.removeChild(tarea);}catch(e){document.getElementById("htmlconverter").innerHTML='<textarea id="innerConverter">'+str+'</textarea>';var content=document.getElementById("innerConverter").value;document.getElementById("htmlconverter").innerHTML="";return content;}}
function removeHTMLTags(str){str=str.replace(/&(lt|gt);/g,function(strMatch,p1){return(p1=="lt")?"<":">";});var str=str.replace(/<\/?[^>]+(>|$)/g,"");return str;}
function trim(s){var i;var return_string="";for(i=0;i<s.length;i++){var c=s.charAt(i);if(c!=" ")return_string+=c;}
return return_string;}
function stripCharsInBag(s,bag){var i;var return_string="";for(i=0;i<s.length;i++){var c=s.charAt(i);if(bag.indexOf(c)==-1)return_string+=c;}
return return_string;}
function checkPasswordField(obj_field,trigger){var value=($(obj_field).val());if(!validatePassword(value)){var already_errored=isFieldErrored(obj_field)
setLabelsErrored(obj_field,true);if(!(trigger=='keyup'&&already_errored)){var error_str='';error_str+=((in_cms)?js_cms_lang:js_lang).Invalid_format_field_x.replace('%s',js_fields_notify_labels[$(obj_field).attr('id')]);error_str+='<br />'+((in_cms)?js_cms_lang:js_lang).Accepted_characters.replace('%s',((in_cms)?js_cms_lang:js_lang).format_password);customAlert(error_str);}}else{setLabelsErrored(obj_field,false);}
var strength=checkPasswordStrength(value);$(obj_field).removeClass('strength_0').removeClass('strength_1').removeClass('strength_2').removeClass('strength_3').removeClass('strength_4').removeClass('strength_5').addClass('strength_'+strength).attr('title',((in_cms)?js_cms_lang:js_lang).Password_Strength_x.replace('%s',((in_cms)?js_cms_lang:js_lang).password_strength_options[strength]));}
function checkPasswordStrength(password){var strength=0;var count=0;var length=password.length;if(length>15){strength=18;}else if(length>7){strength=12;}else if(length>5){strength=6;}else if(length>0){strength=3;}else{return 0;}
count=password.match(/[a-z]/g)
if(count){strength+=5;count=count.length;if(count>1)strength+=1;if(count>2)strength+=1;}
count=password.match(/[A-Z]/g);if(count){strength+=5;count=count.length;if(count>1)strength+=1;if(count>2)strength+=1;}
count=password.match(/[0-9]/g);if(count){strength+=5;count=count.length;if(count>1)strength+=1;if(count>2)strength+=1;}
count=password.match(/[-,!,@,#,$,%,^,&,*,?,.,+,_]/g);if(count){strength+=5;count=count.length;if(count>1)strength+=1;if(count>2)strength+=1;}
if(strength<16)return 1;else if(strength<25)return 2;else if(strength<35)return 3;else if(strength<45)return 4;else return 5;}
function validateEmail(string){var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,6})$/;return(reg.test(string));}
function validateInteger(string){if(isNaN(string))string=0;return(string>0);}
function validateNumber(string){return(!isNaN(string));}
function validatePassword(string){var reg=/[^-!@#*$%^&?.+_A-Za-z0-9]+/;return(reg.test(string)?false:true);}
function validatePath(string){var reg=/^(\/[\S]+)+$/;return reg.test(string);}
function validatePathURL(string){if(validateURL(string)){return true;}else if(validatePath(string)){return true;}
return false;}
function validatePhoneNumber(strPhone){var phoneNumberDelimiters="()-. extnsio#";var validWorldPhoneChars=phoneNumberDelimiters+"+";var minDigitsInIPhoneNumber=10;var bracket=3;strPhone=trim(strPhone);if(strPhone.indexOf("+")>1)return false;if(strPhone.indexOf("-")!=-1)bracket=bracket+1;var openingBracketPos=strPhone.indexOf("(");var closingBracketPos=strPhone.indexOf(")");if(openingBracketPos!=-1&&openingBracketPos>bracket)return false;if(openingBracketPos!=-1&&closingBracketPos!=openingBracketPos+4)return false;if(openingBracketPos==-1&&closingBracketPos!=-1)return false;s=stripCharsInBag(strPhone,validWorldPhoneChars);return(validateNumber(s)&&s.length>=minDigitsInIPhoneNumber);}
function validateURL(string){var reg=/^((https?|ftp)\:\/\/)?([a-zA-Z0-9+!*(),;?&=$_.-]+(\:[a-zA-Z0-9+!*(),;?&=$_.-]+)?@)?([a-zA-Z0-9-.]*)\.([a-zA-Z]{2,3})(\:[0-9]{2,5})?(\/([a-zA-Z0-9+$_-]\.?)+)*\/?(\?[a-zA-Z+&$_.-][a-zA-Z0-9;:@&%=+\/$_.,-]*)?(#[a-zA-Z_.-][a-zA-Z0-9+$_.-]*)?$/;return reg.test(string);}
function validateFormat(format,data){var is_valid=true;if(!data)return true;switch(format){case'email':case'email_address':is_valid=validateEmail(data);break;case'int':is_valid=validateInteger(data);break;case'number':is_valid=validateNumber(data);break;case'password':is_valid=validatePassword(data);break;case'path':is_valid=validatePath(data);break;case'path_url':is_valid=validatePathURL(data);break;case'phone':case'phone_number':is_valid=validatePhoneNumber(data);break;case'link':case'url':case'website':is_valid=validateURL(data);break;}
return is_valid;}
function inFrame(){return(window.location!=window.parent.location);}
function linkWindow(URL){smallWindow(URL,'generate_link',640,400);}
function smallWindow(URL,id,width,height){eval("page_"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height);");try{if(window.focus){eval("page_"+id).focus()}}catch(err){}}
function minimizeWindow(){window.innerWidth=100;window.innerHeight=100;window.screenX=screen.width;window.screenY=screen.height;alwaysLowered=true;}
function maximizeWindow(){window.innerWidth=screen.width;window.innerHeight=screen.height;window.screenX=0;window.screenY=0;alwaysLowered=false;}
function goToURL(url,target,properties){if(!properties)properties=new Object();switch(target){default:window.location=url;break;case'_blank':window.open(url,properties.name);break;}}
function formatJSAlert(str){return removeHTMLTags(htmlEntityDecode(str.replace('<br />',"\n")));}
function alertTraditional(dialog_text){alert(formatJSAlert(dialog_text));}
function confirmActionTraditional(dialog_text,url){var agree=confirm(formatJSAlert(dialog_text));if(agree){goToURL(url);}else{return false;}}
function customAlert(input){try{if(isObject(input)){dialog_properties=input;}else{dialog_properties=new Object();dialog_properties.text=input;}
switch(dialog_properties.source){default:break;case'error':$('div#error').hide();dialog_properties.type='error';dialog_properties.text=$('div#error').html();break;case'message':$('div#message').hide();dialog_properties.type='alert';dialog_properties.text=$('div#message').html();break;}
if(dialog_properties.modal!=='false'){switch(dialog_properties.type){case'confirm':case'save_prompt':dialog_properties.modal=true;break;}}
if(!dialog_properties.type)dialog_properties.type='error';if(dialog_properties.in_cms||(!dialog_properties.in_frontend&&in_cms)){if(!dialog_properties.width)dialog_properties.width=default_cms_dialog_properties.width;if(!dialog_properties.height)dialog_properties.height=default_cms_dialog_properties.height;temp_js_lang=js_cms_lang;}else{if(!dialog_properties.width)dialog_properties.width=default_dialog_properties.width;if(!dialog_properties.height)dialog_properties.height=default_dialog_properties.height;temp_js_lang=js_lang;}
if(!dialog_properties.text){switch(dialog_properties.type){case'save_prompt':dialog_properties.text=temp_js_lang.Commit_and_Continue;break;}}
if(!dialog_properties.title){switch(dialog_properties.type){default:case'alert':dialog_properties.title=temp_js_lang.Notice;break;case'confirm':case'save_prompt':case'warning':dialog_properties.title=temp_js_lang.Warning;break;case'error':dialog_properties.title=temp_js_lang.Error;break;}}
if(!dialog_properties.buttons){dialog_properties.buttons={};switch(dialog_properties.type){default:case'alert':case'error':dialog_properties.buttons[temp_js_lang.OK]=function(){$(this).dialog('close');};break;case'confirm':dialog_properties.buttons[temp_js_lang.No]=function(){$(this).dialog('close');};dialog_properties.buttons[temp_js_lang.Yes]=function(){$(this).dialog('close');eval(dialog_properties.action);};break;case'save_prompt':dialog_properties.buttons[temp_js_lang.Cancel]=function(){$(this).dialog('close');};if(!dialog_properties.disable_clickthrough)dialog_properties.buttons[temp_js_lang.Discard_Changes]=function(){$(this).dialog('close');goToURL(dialog_properties.url);};dialog_properties.buttons[temp_js_lang.Commit_Changes]=function(){$(this).dialog('close');try{$("input#r").val(dialog_properties.url);}catch(err){}
$("input#next_action_override").val(1);eval(dialog_properties.action);};break;}}
if(!dialog_properties.css_class){switch(dialog_properties.type){case'error':case'php_errors':dialog_properties.css_class='ui-state-error';break;}}
$("div#alert_box").html(dialog_properties.text);$("div#alert_box").dialog({resizable:true,width:dialog_properties.width,height:dialog_properties.height,modal:dialog_properties.modal,title:dialog_properties.title.toUpperCase(),dialogClass:'dialog dialog_'+dialog_properties.type+' '+dialog_properties.css_class,buttons:dialog_properties.buttons});$('div#alert_box').removeClass('hidden');}catch(err){switch(dialog_properties){default:case'alert':case'error':alertTraditional(dialog_properties.text);break;case'confirm':confirmActionTraditional(dialog_properties.text,dialog_properties.url)
break;}}}
function erroredToDialog(){width='600';height='400'
if(in_cms){width=default_cms_dialog_properties.width;height=default_cms_dialog_properties.height;temp_js_lang=js_cms_lang;}else{width=default_dialog_properties.width;height=default_dialog_properties.height;temp_js_lang=js_lang;}
$("div#errored").dialog({resizable:true,width:dialog_properties.width,height:dialog_properties.height,modal:true,title:dialog_properties.title.toUpperCase(),dialogClass:'dialog dialog_error'});}
function confirmAction(dialog_text,url){try{customAlert({"type":"confirm","text":dialog_text,"url":url,"action":"goToURL('"+url+"')"});}catch(err){confirmActionTraditional(dialog_text,url)}}
function jumpbox(baseURL,which){goToURL(baseURL+which[which.selectedIndex].value);}
function toggleDefaultFieldText(object,is_focused){if(is_focused){if($(object).val()==$(object).attr('rel'))$(object).val("");}else if(!$(object).val()){$(object).val($(object).attr("rel"));}}
var stored_values=new Object();function assignStoredValue(target,property,set_value){var target_id='';if(!property)property='val';if(isObject(target)){if(!set_value){switch(property){default:set_value=$(target).attr(property);break;case'val':set_value=$(target).val();break;}}
target_id=$(target).attr("id");}else{target_id=target;}
if(!target_id||!property)return;if(!stored_values[target_id])stored_values[target_id]=new Object();stored_values[target_id][property]=set_value;}
var do_save_prompt=false;function setSavePrompt(value){do_save_prompt=value;}
var tabs_require_save=false;function setTabsRequireSave(value){tabs_require_save=value;}
function saveRedirect(url,properties){if(!properties)properties=new Object();if(url)properties.url=url;properties.action='redirect';if(!properties.form_name)properties.form_name=page_ref;checkAndSubmitForm(properties.form_name,properties);return false;}
function promptSaveRedirect(obj_caller,properties){var force_save_prompt=false;var disable_clickthrough=false;if(properties.trigger_type=='tab_bar'&&tabs_require_save){force_save_prompt=true;disable_clickthrough=true;}
if(do_save_prompt||force_save_prompt){if(!properties.form_name)properties.form_name=page_ref;if(!properties.message)properties.message=((in_cms)?js_cms_lang:js_lang).Commit_and_Continue;if(properties.trigger_type=='link'&&!properties.url)properties.url=$(obj_caller).attr('href');customAlert({"type":"save_prompt","url":properties.url,"action":"checkAndSubmitForm('"+properties.form_name+"')","disable_clickthrough":disable_clickthrough});return false;}else{if(properties.trigger_type=='link')return true;else goToURL(properties.url);}}
function checkAndSubmitForm(form_name,properties){var t_form=$("form[name=form_"+form_name+"]");if(!properties)properties=new Object();if(checkForm(t_form)){if(properties.action=='redirect'&&properties.url){$("input#r").val(properties.url);$("input#next_action_override").val(1);}
t_form.removeAttr('onSubmit');$("textarea.ta_ckeditor").each(function(i){CKEDITOR.instances[$("textarea.ta_ckeditor")[i].id].updateElement();});t_form.submit();}
return false;}
function setBlurCheckFields(obj_form){$(obj_form+":input").each(function(){setBlurCheck(this);});}
function setBlurCheck(obj_field){var t_onblur_functions=$(obj_field).attr('onblur');if(t_onblur_functions){$(obj_field).removeAttr('onblur');assignStoredValue($(obj_field),'onblur',t_onblur_functions);}else{if(stored_values[$(obj_field).attr('id')]){if(stored_values[$(obj_field).attr('id')].onblur){t_onblur_functions=stored_values[$(obj_field).attr('id')].onblur;}}}
$(obj_field).unbind('blur');if(!$(obj_field).hasClass('skip_blur_check')&&($(obj_field).hasClass('mandatory')||$(obj_field).hasClass('validate')||$(obj_field).hasClass('match'))){$(obj_field).bind('blur',function(){validateFieldSingle(this);});}
if(t_onblur_functions)$(obj_field).bind('blur',t_onblur_functions);}
var validated_field_names;function validateForm(obj_form){var error_string='';validated_field_names=new Object();$(obj_form+":input.mandatory,"+obj_form+":input.validate").each(function(){if(!validated_field_names[$(this).attr('name')]){validated_field_names[$(this).attr('name')]=1;var field_error_string=validateField(this);if(field_error_string)error_string+='<br />'+field_error_string;}});return error_string;}
function checkForm(obj_form){$("input#btn_submit").attr("disabled","disabled");$("input#btn_submit").addClass("_disabled");$("li#admin_tools_save").hide();var error_msg=validateForm(obj_form);if(error_msg){$("input#btn_submit").removeAttr("disabled");$("input#btn_submit").removeClass("_disabled");$("li#admin_tools_save").show();$("input#next_action_bypass_save").val("");customAlert(error_msg);return false;}
return true;}
function validateMandatoryField(obj_field){switch($(obj_field).attr('type')){case'password':case'select':case'select-one':case'select-multiple':case'text':case'text_input':case'text_area':case'textarea':return $(obj_field).val();break;case'checkbox':case'radio':var has_selection=false;$('input[name='+$(obj_field).attr('name')+']').each(function(){if($(this).is(':checked')){has_selection=true;}});return has_selection;break;}
return false;}
function validateField(obj_field){if($(obj_field).hasClass('mandatory')){if(!validateMandatoryField(obj_field)){setLabelsErrored(obj_field,true);return((in_cms)?js_cms_lang:js_lang).Field_x_is_mandatory.replace('%s',js_fields_notify_labels[$(obj_field).attr('id')]);}}
if($(obj_field).hasClass('validate')){var validation_array=js_fields_validate[obj_field.id];for(var i in validation_array){if(!validateFormat(validation_array[i],$(obj_field).val())){setLabelsErrored(obj_field,true);return((in_cms)?js_cms_lang:js_lang).Invalid_format_field_x.replace('%s',js_fields_notify_labels[$(obj_field).attr('id')]);}}}
if($(obj_field).hasClass('match')){var matches_array=js_fields_validate[obj_field.id];for(var i in matches_array){if($(obj_field).val()&&$('#'+matches_array[i]).val()&&$(obj_field).val()!==$('#'+matches_array[i]).val()){setLabelsErrored(obj_field,true);return((in_cms)?js_cms_lang:js_lang).Field_x_does_not_match.replace('%s',js_fields_notify_labels[$(obj_field).attr('id')]);}}}
setLabelsErrored(obj_field,false);}
function validateFieldSingle(obj_field){var error_message='';if(error_message=validateField(obj_field)){customAlert(error_message);}}
function setFieldMandatory(obj_field,is_mandatory){$("input[name="+$(obj_field).attr("name")+"], select[name="+$(obj_field).attr("name")+"]").each(function(){if(is_mandatory){$(this).addClass('mandatory');if($('label#label_'+$(this).attr('id')+' span').html().indexOf('* ')!==0){$('label#label_'+$(this).attr('id')+' span').prepend('* ');}}else{$(this).removeClass('mandatory');$('label#label_'+$(this).attr('id')+' span').html($('label#label_'+$(this).attr('id')+' span').html().replace('* ',''));setLabelsErrored($(this),false);}
setBlurCheck(obj_field);})}
function setFieldState(obj_field,state_name,off){var field_name=$(obj_field).attr('name');$("input[name="+field_name+"], select[name="+field_name+"]").each(function(){if(off){$(this).attr(state_name,state_name);$(this).addClass('disabled');}else{$(this).removeAttr(state_name);$(this).removeClass('disabled');}
setBlurCheck(obj_field);});if(off){setLabelsErrored(obj_field,false);$('label[name=label_'+field_name+']').addClass('cursor_default');}else{$('label[name=label_'+field_name+']').removeClass('cursor_default');}}
function setLabelsErrored(obj_field,is_errored){var field_name=$(obj_field).attr('name');$('label[name=label_'+field_name+'] span').attr('class',(is_errored)?'errored':'');}
function isFieldErrored(obj_field){var field_name=$(obj_field).attr('name');var is_errored=false;$('label[name=label_'+field_name+'] span').each(function(){if($(this).hasClass('errored'))is_errored=true;});return is_errored}
