var hostname, collateral_hostname;

// Need to figure out what is the hostname we are at.
// For live Trigo site, we use the live collateral site
// For preview Trigo site, we use the preview collateral site
if ( location.hostname == 'www.Neterion.com' ) 
{
	collateral_hostname = 'www.Neterion.com';
} else {
	collateral_hostname = 'Neterion.boldfocus.com';
}

function viewCollateral(doc) {
	detectProfile(doc);
}

function detectProfile(doc) {
	var cookie_value, url;

	// Read the cookie from the user's browser
	cookie_value = GetCookie('Collateral');
		
	// If the cookie by the name of 'Collateral' is NOT null, we assume this user is registered
	// View the document in a separate browser window
	if ( cookie_value != null ) {
		// + '&ref=' + window.opener.location.href
		//url = 'http://' + collateral_hostname + '/collateral/viewCollateral.asp?doc=' + doc + '&ref=' + location.href;
		url = '/collateral/viewCollateral.asp?doc=' + doc + '&ref=' + location.href;
		openCollateralWindow(url);
	}
	// Otherwise, present the registration form is a pop up browser window
	// After the user signs up and submits this form, the requested document will be presented
	// in a separate browser window
	else {
		//url = 'http://' + collateral_hostname + '/collateral/registerform.asp?doc=' + doc + '&ref=' + location.href;
		url = 'registerform.asp?doc=' + doc + '&ref=' + location.href;
		openCollateralForm(url);
	}
	return false;
}

//function openCollateralForm(url) {
//	var newwin;
//	newwin = window.open(url,'CollateralForm','toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=650,height=700,left=150,top=20');
//	newwin.focus();
//}

function openCollateralForm(url) {
	var newwin, x, y, w, h;
	w = 520;
	h = 700;
	x = (screen.width - w) / 2;
	y = (screen.height - h) / 2;
	newwin = window.open(url,'CollateralForm','toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h+',left='+x+',top='+y);
	newwin.focus();
}

//function openCollateralWindow(url) {
//	var newwin;
//	newwin = window.open(url,'CollateralWindow','toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=650,left=150,top=20');
//	newwin.focus();
//}

function openCollateralWindow(url) {
	var newwin, x, y, w, h;
	w = 800;
	h = 800;
	x = (screen.width - w) / 2;
	y = (screen.height - h) / 2;
	
	newwin = window.open(url,'CollateralWindow','toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h+',left='+x+',top='+y);
	newwin.focus();
}
function openPop(url) {
	aPopUp=
window.open(url,'card','toolbar=yes,menubar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=650,left=150,top=20')
   self.acardWin = aPopUp

}
