﻿
if(Monarch==null||typeof(Monarch)!="object")var Monarch=new Object();if(Monarch.Common==null||typeof(Monarch.Common)!="object")Monarch.Common=new Object();Monarch.Common.checkDate=function(year,month,day){var d=Monarch.Common.getDate(year,month,day);if(d.getDate()==day&&(d.getMonth()+1)==month&&d.getFullYear()==year){return true;}
return false;}
Monarch.Common.convertDecimalToDisplayPrice=function(num,includeCommas,groupSymbol,decimalSymbol){if(typeof(num)=='undefined'||(typeof(num)=="string"&&!num.isInitialised()))return;if(typeof(groupSymbol)=='undefined'||!groupSymbol.isInitialised())groupSymbol=",";if(typeof(decimalSymbol)=='undefined'||!decimalSymbol.isInitialised())decimalSymbol=".";num=Math.round(num*100)/100;var str=num+'';var strArr=str.split(".");if(strArr.length==1){str+=(decimalSymbol+"00");}
else if(strArr[1].length==1){str+="0";}
if(includeCommas){var re=new RegExp(/.\d+$/);var m=re.exec(str);if(m!=null){var strPence=m[m.length-1];str=str.replace(re,"");for(var i=0;i<Math.floor((str.length-(1+i))/3);i++)
str=str.substring(0,str.length-(4*i+3))+groupSymbol+str.substring(str.length-(4*i+3))
str+=strPence.replace(/\./g,decimalSymbol);}}
return str;}
Monarch.Common.cleanNumber=function(num,groupSymbol,decimalSymbol){if(typeof(num)=='undefined'||(typeof(num)=="string"&&!num.isInitialised()))return;if(typeof(groupSymbol)=='undefined'||!groupSymbol.isInitialised())groupSymbol=",";if(typeof(decimalSymbol)=='undefined'||!decimalSymbol.isInitialised())decimalSymbol=".";var re=new RegExp('\\'+groupSymbol,'g');num=num.toString().replace(re,'')
if(decimalSymbol!="."){re=new RegExp('\\'+decimalSymbol,'g');num=num.toString().replace(re,'.');}
return num*1;}
Monarch.Common.encodeUrl=function(url){{encodedParams="?";parts=url.split("?");params=parts[1].split("&");for(i=0;i<params.length;i++){if(i>0){encodedParams+="&";}
if(params[i].indexOf("=")>0)
{p=params[i].split("=");encodedParams+=(p[0]+"="+escape(encodeURI(p[1])));}
else{encodedParams+=params[i];}}
url=parts[0]+encodedParams;}
return url;}
Monarch.Common.fancyboxPopUp=function(jAnchors,jsonFeatures){var FANCYBOX_DEFAULT_FEATURES={'hideOnContentClick':true,'zoomSpeedIn':0,'zoomSpeedOut':0,'overlayShow':true};if(!Monarch.Common.isDefined(jsonFeatures)){jsonFeatures=FANCYBOX_DEFAULT_FEATURES;}
$(document).ready(function(){$(jAnchors).fancybox(jsonFeatures)});}
Monarch.Common.getDate=function(year,month,day){return new Date(year,month-1,day);}
Monarch.Common.getObjectLength=function(obj){var count=0,key;for(key in obj)
count++;return count;}
Monarch.Common.isDefined=function(o){if(typeof(o)=='undefined'){return false;}
return(o!=null);}
Monarch.Common.padIntToString=function(input,character,lengthRequired,leftRight){var str=input+'';while(str.length<lengthRequired){if(leftRight.toUpperCase().substring(0,1)=="L"){str=character+str;}else if(leftRight.toUpperCase().substring(0,1)=="R"){str+=character;}else{break;}}
return str;}
Monarch.Common.parseBool=function(arg){var argType=typeof(arg);var rtnVal=false;if(arg!=null){switch(argType){case"number":if(arg==1)rtnVal=true;break;case"string":if(arg.toLowerCase()=="true")rtnVal=true;break;}}
return rtnVal;}
Monarch.Common.showPopUp=function(jAnchors){var allowFancyBox=true;if(allowFancyBox){Monarch.Common.fancyboxPopUp(jAnchors,undefined);}else{Monarch.Common.windowPopUp(jAnchors,undefined);}}
Monarch.Common.windowPopUp=function(jAnchors,features){var WINDOW_DEFAULT_FEATURES="location=0,statusbar=0,menubar=0,width=400,height=300";if(!Monarch.Common.isDefined(features)){features=WINDOW_DEFAULT_FEATURES;}
$(document).ready(function(){$(jAnchors).each(function(){var url=$(this).attr("href");var target=$(this).attr("target")==""?"_blank":$(this).attr("target");$(this).click(function(){window.open(url,target,features);return false;});});});}
String.prototype.trim=function(){return this.replace(/^\s+/,'').replace(/\s+$/,'');}
String.prototype.isInitialised=function(){return(this!="");}
Date.prototype.currentAge=function(){var now=new Date();var value=new Date(this.getTime());var age=now.getFullYear()-value.getFullYear();value=value.setFullYear(now.getFullYear());if(now<value)--age;return age;};Date.isValid=function(day,month,year){if(/^(0?[1-9]|[12][0-9]|3[01])$/.test(day)&&/^(0?[1-9]|1[012])$/.test(month)&&/^(19|20)?[0-9]{2}$/.test(year)){var d=new Date(Date.parse(month+"/"+day+"/"+year));return(d.getDate()==day&&(d.getMonth()+1)==month&&d.getFullYear()==year);}
return false;}
Monarch.Common.dateDiff=function(dp,dt1,dt2){if(typeof(dt1)=='undefined'||typeof(dt2)=='undefined'||dt1==null||dt2==null)
return null;var iDiffMS=dt2.valueOf()-dt1.valueOf();var dtDiff=new Date(iDiffMS);var nYears=dt2.getUTCFullYear()-dt1.getUTCFullYear();var nMonths=dt2.getUTCMonth()-dt1.getUTCMonth()+(nYears!==0?nYears*12:0);var nQuarters=nMonths/3;var nMilliseconds=iDiffMS;var nSeconds=iDiffMS/1000;var nMinutes=nSeconds/60;var nHours=nMinutes/60;var nDays=Math.round(nHours/24);var nWeeks=nDays/7;var iDiff=0;switch(dp.toLowerCase()){case"yyyy":return nYears;case"q":return nQuarters;case"m":return nMonths;case"y":return nDays;case"d":return nDays;case"w":return nDays;case"ww":return nWeeks;case"h":return nHours;case"n":return nMinutes;case"s":return nSeconds;case"ms":return nMilliseconds;default:return null;}}
Monarch.Common.datePlusNights=function(dt,nts){if(typeof(dt)=='undefined'||typeof(nts)=='undefined'||dt==null||nts==null)
return null;var dateInMS=dt.valueOf();return new Date(dateInMS+(86400000*nts));}