
// OpenSOLAR function. Pops up a window containing the SOLAR application.

// Pops up the SOLAR url, but allows a message to be displayed (3rd param) if 2nd param is false
function openSOLAR(available) {
	var argv = openSOLAR.arguments;  
	var argc = openSOLAR.arguments.length;  
	var message = (argc > 1) ? argv[1] : null;  

	if (available==true) {
		loc = "https://www.invesco-web.com/security/SolarAccessServlet?opusappname=SOLAR&domicile=GB";
		window.open(loc, 'solar', 'location=no, resizable=yes, toolbar=no, top=0, left=0, scrollbars=yes, status=yes, directories=no, menubar=no, width=780, height=570');
	} else {
		alert(message);
	}
}

// Pops up any url, but allows a message to be displayed (3rd param) if 2nd param is false
function popupSOLAR(loc, available) {
	var argv = popupSOLAR.arguments;  
	var argc = popupSOLAR.arguments.length;  
	var message = (argc > 2) ? argv[2] : null;  

	if (available==true || available == 'true') {
		window.open(loc, 'solar', 'location=no, resizable=yes, toolbar=no, top=0, left=0, scrollbars=yes, status=yes, directories=no, menubar=no, width=780, height=570');
	} else {
		alert(message);
	}
}

function popup(url, width, height) {
	if (width == "") width = 640;
	if (height == "") height = 400;
	var win = window.open(url, 'popup', 'width='+width+',height='+height+',status=yes,resizable=yes,toolbar=no,menubar=no,location=no, scrollbars=yes');
}

function popupEmbeddedObject(path, title, width, height) {
	var url= "";
	if (path.indexOf("http") == -1) {
		url = url + location.protocol + "//";
		url = url + location.hostname;
		if (location.port != "") url = url + ":" + location.port;
		url = url + "/" + path;
	} else {
		url = path;
	}
	
	var demoWin = window.open('', 'popup', 'width='+width+',height='+height+',status=yes,resizable=yes,toolbar=no,menubar=no,location=no, scrollbars=yes');
	demoWin.document.write("<html><head><title>"+title+"</title></head><body><embed src='" + url + "' width='100%' height='100%' hspace=0 vspace=0></embed></body>");
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function setCookie (name, value) {  
	var argv = setCookie.arguments;  
	var argc = setCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "; path=/" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}

function deleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = getCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
