moListStyle = "vertical";

var iwmandp, ihmandp, ihbmandp, ihmiddle = 0, iwmiddle = 0, iheight, iwidth, mapSize, iadheight;
var multipleMaps;
try {
	if (typeof (moListStyle) === "undefined" || typeof (moDays) === "undefined" || typeof (moColourScheme) === "undefined" || typeof (moFSSI) === "undefined" || typeof (moDomain) === "undefined" || typeof (moMapDisplay) === "undefined" || typeof (moMapsRequired) === "undefined" || typeof (moTemperatureUnits) === "undefined" || typeof (moSpeedUnits) === "undefined" || typeof (moShowWind) === "undefined") {
		throw ("Parameters missing in loader");
	}
	if (moListStyle !== "horizontal" && moListStyle !== "vertical") {
		throw ("Invalid orientation in loader");
	}
	if (typeof (moDays) !== "number" || Math.floor(moDays) !== moDays || moDays < 1 || moDays > 5) {
		throw ("Invalid days in loader");
	}
	if (moColourScheme !== "default" && moColourScheme !== "green" && moColourScheme !== "blue" && moColourScheme !== "yellow") {
		throw ("Invalid colour scheme in loader");
	}
	if (typeof (moFSSI) !== "number" || Math.floor(moFSSI) !== moFSSI || moFSSI < 1) {
		throw ("Invalid FSSI in loader");
	}
	if (moMapDisplay !== "side" && moMapDisplay !== "bottom" && moMapDisplay !== "none") {
		throw ("Invalid map display position in loader");
	}
	if (typeof (moMapsRequired) !== "string") {
		throw ("Invalid map list in loader");
	}
	if (moTemperatureUnits !== "C" && moTemperatureUnits !== "F") {
		throw ("Invalid temperature units in loader");
	}
	if (moSpeedUnits !== "M" && moSpeedUnits !== "K" && moSpeedUnits !== "N") {
		throw ("Invalid speed units in loader");
	}
	if (moShowWind !== "true" && moShowWind !== "false") {
		throw ("Invalid wind display flag in loader");
	}
	if (typeof (moShowUV) === "undefined") {
		moShowUV = "false";
	}
	if (moShowUV !== "true" && moShowUV !== "false") {
		throw ("Invalid UV display flag in loader");
	}
	if (typeof (moShowFeelsLike) === "undefined") {
		moShowFeelsLike = "false";
	}
	if (moShowFeelsLike !== "true" && moShowFeelsLike !== "false") {
		throw ("Invalid feels-like display flag in loader");
	}
	if (typeof (moAllowUserLocation) === "undefined") {
		moAllowUserLocation = "false";
	}
	if (moAllowUserLocation !== "true" && moAllowUserLocation !== "false") {
		throw ("Invalid user location flag in loader");
	}
	if (typeof (moStartupLanguage) === "undefined") {
		moStartupLanguage = "en";
	}

	if (moStartupLanguage.length > 4) {
		throw ("Invalid language code in loader");
	}
	//Checking to make sure that ifthe height and width values are zero they are set to a numeric value 
	if (typeof (moSpecificHeight) === "undefined" || typeof (moSpecificWidth) === "undefined"){
		moSpecificHeight = 0;
		moSpecificWidth = 0;
	} else if (moSpecificHeight == 0 && moSpecificWidth == 0) {
		moSpecificHeight = 0;
		moSpecificWidth = 0;
	}

	iwmandp = 26;	// margins and padding width
	ihmandp = 13 + 18 + 7 + 22 + 5 + 8 + 5;	// margins, padding, static text on height
	iadheight = 32;
	ihbmandp = (10 + 15 + 10 + 13 + iadheight);	// padding + copyright + more detail + bottom margin and padding + advert
	if (moListStyle === "horizontal") {
	// days stacked next to each other 
		iwmiddle += (moDays * 50);	// amount for n days next to each other
		iwmiddle = (iwmiddle < 159 ? 159 : iwmiddle);	//
		ihmiddle += 130;				// amount for static single height of a block of daily data
	} else {
	// days stacked on top of each other 
		ihmiddle += (moDays * 38);	// amount for n days on top of one other
		iwmiddle += 182;				// amount for a single width of a block of daily data.
	}
	multipleMaps = (moMapsRequired.split(",").length > 1);
	if (moMapDisplay === "side") {
		iwmap = 10 + 150 + ((multipleMaps) ? 19 : 10);	// width allocated for map = spacing + map + 2 x 11px controls (if more than one map)
		ihmap = 150 + 22 + 15 + 20 + 31; // height allocated formap = height of map + title + subtitle + spacing + warning gif;
		iheight = Math.max(ihmandp + ihmiddle - iadheight + 10, ihmap);	// height is then changed to use minimum space possible
		iwidth = iwmandp + iwmiddle + iwmap;			// width is fixed: margins + the weather space + the map space
	} else if (moMapDisplay === "bottom") {
		iwmap = 150 + ((multipleMaps) ? 24 : 0); // width allocated for map = 150 + 2 x 11px controls (if more than one map)
		ihmap = 150 + 22 + 15 + 10; // height of map + title + subtitle + spacing;
		iheight = ihmandp + ihmiddle + ihmap;			// height is fixed: margins, etc. + weather space + map
		iwidth = iwmandp + Math.max(iwmiddle, iwmap);	// width is changed to use minimum space possible.  
	} else {
		// if no maps shown, height and width are both = margins, borders + the space allocated to weather.   
		iheight = ihmandp + ihmiddle;
		iwidth = iwmandp + iwmiddle;
	}
	iheight += ihbmandp;	// always need to add the bottom margin and border space.   
	iwidth += ((moShowUV === "true") ? 36 : 0);
	iwidth += ((moShowFeelsLike === "true") ? 48 : 0);
	
	if (typeof moSpecificHeight !== 'undefined' && typeof moSpecificWidth !== 'undefined'){
		if (moSpecificHeight !== 0 && moSpecificWidth !== 0){
			iheight = moSpecificHeight;
			iwidth = moSpecificWidth;
		}
	}
	
	// //override width and height measurements if user has chosen a specific size
		// if (moSpecificHeight !== 0 && moSpecificWidth !== 0){
			// iheight = moSpecificHeight;
			// iwidth = moSpecificWidth;
		// }
		
	var cp;
	if (typeof moCP === 'string') {
		cp  = moCP;
	} else {
		cp = top.document.location.href || "iframe"; //If in an Iframe, user should set moCP as we can't access "top.document."
	}
	
	var iframeURL = "http://" + moDomain + "/public/pws/components/yoursite/component.html?cp=" + escape(cp) + "&moListStyle=" + moListStyle + "&moDays=" + moDays + "&moColourScheme=" + moColourScheme + "&moFSSI=" + moFSSI + "&moDomain=" + moDomain + "&h=" + iheight + "&w=" + iwidth + "&moMapDisplay=" + moMapDisplay + "&moMapsRequired=" + moMapsRequired + "&moTemperatureUnits=" + moTemperatureUnits + "&moSpeedUnits=" + moSpeedUnits + "&moShowWind=" + moShowWind + "&moStartupLanguage=" + moStartupLanguage + "&moShowUV=" + moShowUV + "&moShowFeelsLike=" + moShowFeelsLike + "&moAllowUserLocation=" + moAllowUserLocation;
} catch (error) {
	var iheight = 300;
	var iwidth = 250;
	var cp;
	if (typeof moCP === 'string') {
		cp  = moCP;
	} else {
		cp = top.document.location.href || "iframe"; //If in an Iframe, user should set moCP as we can't access "top.document."
	}
	var iframeURL = "http://" + moDomain + "/public/pws/components/yoursite/error.html?cp=" + escape(cp) + "&h=" + iheight + "&w=" + iwidth;
}

var iframe = "<ins style=\"border: medium none ; margin: 0pt; padding: 0pt; display: inline-table; height: " + iheight + "px; position: relative; visibility: visible; width: " + iwidth + "px;\">" +
	"<ins style=\"border: medium none ; margin: 0pt; padding: 0pt; display: block; height: " + iheight + "px; position: relative; visibility: visible; width: " + iwidth + "px;\">" +
	"<iframe id=\"mowxpane\" scrolling=\"no\" height=\"" + iheight + "\" frameborder=\"0\" width=\"" + iwidth + "\" vspace=\"0\" style=\"left: 0pt; position: absolute; top: 0pt;\" src=\"" + iframeURL + "\" name=\"mowxpane\" marginwidth=\"0\" marginheight=\"0\" hspace=\"0\" allowtransparency=\"true\">" +
	"</iframe>" +
	"</ins>" +
	"</ins>";
if (typeof (moNoScript) === "undefined") {
	document.write(iframe);
}

