﻿$(document).ready(function() { 
	if ($('#bsmIframePage').length>0) {
		setMainHeight(230,'bsmIframePage','iframe');
		goToIframeUrl();
	} else {
		//setMainHeight(228,'contentContainer','html')
	}
});
$(window).resize(function() {
	if ($('#bsmIframePage').length>0) {
		setMainHeight(230,'bsmIframePage','iframe');
	} else {
		//setMainHeight(228,'contentContainer','html')
	}
});
function setMainHeight(toppContainerHeight,frameToResize,htmlOrIframe) {
	if (document.all) {
		var ie = true;
		if(navigator.appVersion.toUpperCase().match("MSIE 9")) {
			ie = false;
		}
	}
	newHeight = document.documentElement.clientHeight - toppContainerHeight;
	if (!ie) {
		newHeight = newHeight + "px";
	}
	if (htmlOrIframe == 'iframe') {
		document.getElementById(frameToResize).style.height = newHeight;
	} else {
		$('#'+frameToResize).css('height',newHeight);
	}
}
function goToIframeUrl() {
	goToUrl = getQs(0,'1','http://www.brafab.se/brasom/brasom_products.aspx?page=');
	if (goToUrl != undefined) {
		$('#bsmIframePage').attr('src',goToUrl);
	}
}
function getQs(getArr,getValue,startUrl) {
	thisUrl = "" + window.location;
	if (getValue == '') {
		getValue = false;
	} else {
		getValue = true;
	}
	if (thisUrl.indexOf('?') != -1) {
		thisQS = thisUrl.substr(thisUrl.indexOf('?')+1, thisUrl.length);
		thisQS = thisQS.split("&");
		if (getArr == -1) {
			return thisQS;
		} else {
			if (getValue == true) {
				thisQS = thisQS[getArr].split("=");
				if (thisQS[0] == 'page') {
					return startUrl + thisQS[1];
				}
			} else {
				return thisQS[getArr];
			}
		}
	}
}
