/* --------------------------------------------------------------------------------------------------------------------------------*/
/* copyright frame-it- services limited 01767 677888 */
/* --------------------------------------------------------------------------------------------------------------------------------*/

/* --------------------------------------------------------------------------------------------------------------------------------*/
/* Open and centre a new window */
/* --------------------------------------------------------------------------------------------------------------------------------*/
function openWin(url, width, height)
{
	var left = ((screen.width - width) / 2 )-20;
	var top = ((screen.height - height) / 2)-75;
	var windowproperties = "toolbar=0,scrollbars=1,resizable=1,location=0,menubar=0,copyhistory=0," + "width="+ width +",height="+ height +",left="+ left +",top="+ top;
	window.open(url, name, windowproperties);
}

/* --------------------------------------------------------------------------------------------------------------------------------*/
/* Helper function retrieves a parameter, or null, provided in URL to host page */
/* --------------------------------------------------------------------------------------------------------------------------------*/
function getURLParam(strParamName)
{
	var strReturn = "";
	var strHref = window.location.href;
	var bFound=false;
	
	var cmpstring = strParamName + "=";
	var cmplen = cmpstring.length;
	
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")+1);
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
		{
			if (aQueryString[iParam].substr(0,cmplen)==cmpstring)
			{
			  var aParam = aQueryString[iParam].split("=");
			  strReturn = aParam[1];
			  bFound=true;
			  break;
			}
	  }
	}
	
	if (bFound==false) 
		return null;
		
	return strReturn;
}


 

/* --------------------------------------------------------------------------------------------------------------------------------
builds the URL for the iFrame according to the params passed into this page
---------------------------------------------------------------------------------------------------------------------------------*/
function buildURL2(strPath, idIFRAME)
{

	// here
	
	var strSource = strPath + "?na="; /* na param is a hack to ensure we always get a ? in the query string irrespective of parameters sent in */
	//	var strSource = "../ds/v1/design-studio.htm?na="; /* na param is a hack to ensure we always get a ? in the query string irrespective of parameters sent in */
	if (getURLParam("img") ? strSource = strSource + "&img=" + getURLParam("img") : null); /* img src */
	if (getURLParam("mld") ? strSource = strSource + "&mld=" + getURLParam("mld") : null); /* moulding ref */
	if (getURLParam("h") ? strSource = strSource + "&h=" + getURLParam("h") : null); /* height */
	if (getURLParam("w") ? strSource = strSource + "&w=" + getURLParam("w") : null); /* width */
	if (getURLParam("ms") ? strSource = strSource + "&ms=" + getURLParam("ms") : null); /* mount style */
	if (getURLParam("gs") ? strSource = strSource + "&gs=" + getURLParam("gs") : null); /* glazing style */
	if (getURLParam("tmid") ? strSource = strSource + "&tmid=" + getURLParam("tmid") : null); /* top mount id */
	if (getURLParam("bmid") ? strSource = strSource + "&bmid=" + getURLParam("bmid") : null); /* bot mount id */
	if (getURLParam("ap") ? strSource = strSource + "&ap=" + getURLParam("ap") : null); /* accordion panel to open on load  */
	if (getURLParam("tb") ? strSource = strSource + "&tb=" + getURLParam("tb") : null); /* top mount border */
	if (getURLParam("bb") ? strSource = strSource + "&bb=" + getURLParam("bb") : null); /* bottom mount border */
	if (getURLParam("lb") ? strSource = strSource + "&lb=" + getURLParam("lb") : null); /* left mount border */
	if (getURLParam("rb") ? strSource = strSource + "&rb=" + getURLParam("rb") : null); /* right mount border */
	if (getURLParam("do") ? strSource = strSource + "&do=" + getURLParam("do") : null); /* top mount offset (from bottom mount) */
	if (getURLParam("us") ? strSource = strSource + "&us=" + getURLParam("us") : null); /* allow user re-sizing */
	if (getURLParam("pft") ? strSource = strSource + "&pft=" + getURLParam("pft") : null); /* pro-framer mode */
	if (getURLParam("cb") ? strSource = strSource + "&cb=" + getURLParam("cb") : null); /* allow user re-sizing */
	if (getURLParam("up_ref") ? strSource = strSource + "&up_ref=" + getURLParam("up_ref") : null); /* print ref */
	if (getURLParam("up_name") ? strSource = strSource + "&up_name=" + getURLParam("up_name") : null); /* print name or desc */
	if (getURLParam("up_ih") ? strSource = strSource + "&up_ih=" + getURLParam("up_ih") : null); /* image height */
	if (getURLParam("up_iw") ? strSource = strSource + "&up_iw=" + getURLParam("up_iw") : null); /* image width */
	if (getURLParam("up_ph") ? strSource = strSource + "&up_ph=" + getURLParam("up_ph") : null); /* paper height */
	if (getURLParam("up_pw") ? strSource = strSource + "&up_pw=" + getURLParam("up_pw") : null); /* paper width */
	if (getURLParam("up_uom") ? strSource = strSource + "&up_uom=" + getURLParam("up_uom") : null); /* unit of measure */
	if (getURLParam("up_sp") ? strSource = strSource + "&up_sp=" + getURLParam("up_sp") : null); /* selling price of print  */
	if (getURLParam("fby") ? strSource = strSource + "&fby=" + getURLParam("fby") : null); /* fitting by */
	if (getURLParam("pe") ? strSource = strSource + "&pe=" + getURLParam("pe") : null); /* include photo editor  - true or  false */
	if (getURLParam("lk") ? strSource = strSource + "&lk=" + getURLParam("lk") : null); /* your licence key given to you by eframe */
	if (getURLParam("upl") ? strSource = strSource + "&upl=" + getURLParam("upl") : null); /* include upload panel in accordion menu  - true or  false */
	if (getURLParam("showp") ? strSource = strSource + "&showp=" + getURLParam("showp") : null); /* show prices in main pro-framer window  - true or  false */
	if (getURLParam("link") ? strSource = strSource + "&link=" + getURLParam("link") : null); /* shows a button on screen that, when clicked, will give you the URL to the current designed frame assembly */
	if (getURLParam("co") ? strSource = strSource + "&co=" + getURLParam("co") : null); /* by-passes studio to show only the shopping cart */
	if (getURLParam("uid") ? strSource = strSource + "&uid=" + getURLParam("uid") : null); /* by-passes studio to show only the shopping cart */
	strSource = strSource + "&iframehost=" + idIFRAME; /* change to whatever you have called you iframe (id and name must be the same)*/

	/* set the source location on this page's iframe to the design studio with all of it's params set */
	document.getElementById(idIFRAME).src= strSource;
}

/* --------------------------------------------------------------------------------------------------------------------------------
builds the URL for the iFrame according to the params passed into this page
maintained for backward compatibility
---------------------------------------------------------------------------------------------------------------------------------*/
function buildURL(idIFRAME)
{
	buildURL2("../ds/v1/design-studio.htm", idIFRAME);
}

/* helper function */
function loadScript(str)
{
	var strLoc = "https://ds.pro-framer.co.uk/";
	var strScript = "<script type='text/javascript' language='javascript' src='" + strLoc + str +"'><\/script>";
	return strScript; 
}		

/* helper function */
function loadStyleSheet(str)
{
	var strLoc = "https://ds.pro-framer.co.uk/";
	var s = "<link rel='stylesheet' type='text/css' href='" + strLoc + str + "'>";
	return s;
}
