// Auto window resizing
function contentResize()
{
	var x,y=0,ty;

	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		ty = self.innerHeight;
		if( ty > y ) y = ty;
	}
	if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		ty = document.documentElement.clientHeight;
		if( ty > y ) y = ty;
	}
	if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		ty = document.body.clientHeight;
		if( ty > y ) y = ty;
	}

	var contentDiv = document.getElementById("contentDiv");
	if( contentDiv != null && y > 200 )
	{
		contentDiv.style.height = (y - 200)+"px";
	}

	var dfc = document.getElementById("dashboardFaqCell");
	if( dfc != null )
	{
		dfc.height= contentDiv.style.height;
		setIframeHeight(document.getElementById('dashboardfaqiframe'));
	}

	var guideDiv = document.getElementById("guideDiv");
	if( guideDiv != null && y > 200 )
	{
		guideDiv.style.height = (y - 200)+"px";
	}

	var svDiv = document.getElementById("svDiv");
	if( svDiv != null )
	{
		svDiv.style.height = (y - 200)+"px";
	}
}


// Iframe resizing, used by contentResize()
function setIframeHeight(ifrm)
{
	var iframeWin = window.frames[ifrm];
	var iframeEl = document.getElementById ? document.getElementById(ifrm): document.all ? document.all[ifrm]: null;
	if ( iframeEl && iframeWin )
	{
		iframeEl.style.height = "auto"; // helps resize (for some browsers) if new doc is shorter than previous
		var docHt = getDocHeight(iframeWin.document);
		if (docHt) iframeEl.style.height = docHt + 30 + "px"; // add to height to be sure it will all show
	}
}


// Cookie handling for customer History
function cookieCreate( name, value, days )
{
	var expires = "";

	if (days)
	{
		var date = new Date();
		date.setTime( date.getTime()+(days*24*60*60*1000) );
		expires = "; expires="+date.toGMTString();
	}

	document.cookie = name+"="+value+expires+"; path=" + contextPath;
}


function cookieRead( name )
{
	var nameEQ = name + "=";
	var ca = document.cookie.split( ';' );
	for( var i = 0; i < ca.length; i++)
	{
		var c = ca[i];
		while( c.charAt(0)==' ' )
			c = c.substring( 1, c.length );

		if( c.indexOf( nameEQ ) == 0 )
			return c.substring( nameEQ.length, c.length );
	}

	return null;
}


function cookieRemove( name )
{
	cookieCreate( name, "", -1 );
}


function cookiesClear()
{
	cookieRemove( "callerNumber" );
	cookieRemove( "callerLanguage" );
	cookieRemove( "callerService" );
	cookieRemove( "customerNumber" );
}



// Fix it below
function startGuide(contextPath, guide, portal, user, section, customer )
{
	var customerid = document.getElementById("customerNumberField").value;

	if( customerid.length == 0 )
	{
	 	// if no customer id, then use callernumber
	 	customerid = document.getElementById("callerNumberField").value
	}

	var guideUrl = contextPath + '/guideManager.do?guide=' + escape(guide) + "\&portal=" + escape(portal);
	if( user.length > 0 ) guideUrl += "\&user=" + user;
	if( customerid.length > 0 ) guideUrl += "\&customerid=" + customerid;
	if( section.length > 0 ) guideUrl += "\&section=" + section;
	guideUrl += "\&return=runguide";

	document.location = guideUrl;
}

// Vodafone
function startGuideVodafone(contextPath, guide, portal, user, section, customer )
{
	var customerid = "no user";

	if( customerid.length == 0 )
	{
	 	// if no customer id, then use callernumber
	 	customerid = document.getElementById("callerNumberField").value
	}

	var guideUrl = contextPath + '/guideManager.do?guide=' + escape(guide) + "\&portal=" + escape(portal);
	if( user.length > 0 ) guideUrl += "\&user=" + user;
	if( customerid.length > 0 ) guideUrl += "\&customerid=" + customerid;
	if( section.length > 0 ) guideUrl += "\&section=" + section;
	guideUrl += "\&return=runguide";
	//guideUrl += "\&language=Icelandic";

	var win = window.open( '', '_feedback');
	win.location = guideUrl;
	if( window.focus )
		win.focus();
}

// Vodafone
function startGuideVodafoneThisWindow(contextPath, guide, portal, user, section, customer )
{
	var customerid = "no user";

	if( customerid.length == 0 )
	{
	 	// if no customer id, then use callernumber
	 	customerid = document.getElementById("callerNumberField").value
	}

	var guideUrl = contextPath + '/guideManager.do?guide=' + escape(guide) + "\&portal=" + escape(portal);
	if( user.length > 0 ) guideUrl += "\&user=" + user;
	if( customerid.length > 0 ) guideUrl += "\&customerid=" + customerid;
	if( section.length > 0 ) guideUrl += "\&section=" + section;
	guideUrl += "\&return=runguide";

	document.location = guideUrl;
}


function startGuideExpert(contextPath, guide, portal, user, section, customer )
{
	var customerid = document.getElementById("customerNumberField").value;

	if( customerid.length == 0 )
	{
	 	// if no customer id, then use callernumber
	 	customerid = document.getElementById("callerNumberField").value
	}

	var guideUrl = contextPath + '/guideManager.do?guide=' + escape(guide) + "\&portal=" + escape(portal);
	if( user.length > 0 ) guideUrl += "\&user=" + user;
	if( customerid.length > 0 ) guideUrl += "\&customerid=" + customerid;
	if( section.length > 0 ) guideUrl += "\&section=" + section;
	guideUrl += "\&return=runguide" + "\&expert=true";

	document.location = guideUrl;
}


function submitPhoneCode( )
{
	var phoneCodeId = document.getElementById("phoneCodeField").value;

	if( phoneCodeId.length == 0 )
	{
		alert("no phone code specified");
	}
	else
	{
		document.guideManagerForm.submit();
	}
}

function submitResumeSession( )
{
	var sessionid = document.getElementById("resumeSessionField").value;

	if( sessionid.length == 0 )
	{
		alert("no sessionId specified");
	}
	else
	{
		document.guideManagerForm.submit();
	}
}



	//  adapt iframe height to content height
	function getDocHeight(doc) {
	  //alert("getDocHeight called!");
	  var docHt = 0, sh, oh;
	  if (doc.height) docHt = doc.height;
	  else if (doc.body) {
	    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
	    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
	    if (sh && oh) docHt = Math.max(sh, oh);
	  }
	  return docHt;
	}




