function InsertPortfolio() {
	// Check if user already inside of the portfolio
	var userID = GetCookie("InvestCookie","UserID")		
	var inside = GetCookie("INSIDE","")
	// If user is not exist in portfolio then display input for entering userID and password
	if ((userID == "") || (userID == null) || (inside == "") || (inside == null)) {
	//	window.open('/Finance/Portfolio/Login.htm?win=.parent','Login','width=320,height=300,left=' + (screen.width-320)/2 + ',top=' + (screen.height-300)/2)
		window.open('/globessites/globes/Portfolio/Portfolio/portfolio.aspx','Login','width=320,height=300,left=' + (screen.width-320)/2 + ',top=' + (screen.height-300)/2)
	}
	// If user inside then check what default portfolio and redirect accordingly
	else {
		parent.window.location.href = "/globessites/globes/Portfolio/Portfolio/portfolio.aspx"
	}
}
function GetCookie(sCookie,sSubCookie) {
	var startIndex, endIndex, valueCookie;	
	startIndex = document.cookie.indexOf(sCookie);
	if (startIndex != -1) {
		startIndex += sCookie.length + 1;
		endIndex = document.cookie.indexOf(";",startIndex);
		if (endIndex == -1)
			endIndex = document.cookie.length;
		valueCookie = document.cookie.substring(startIndex,endIndex);
		if (sSubCookie != "") {
			startIndex = valueCookie.indexOf(sSubCookie);
			if (startIndex != -1) {
				startIndex += sSubCookie.length + 1;
				endIndex = valueCookie.indexOf("&",startIndex);
				if (endIndex == -1)
					endIndex = valueCookie.length;
				valueCookie = valueCookie.substring(startIndex,endIndex);
				return(valueCookie);
			}
			else return null;
		}
		else return(valueCookie);	
	}
	else return null;
}

function ViewPage(page, width, height, resizable) {
	PopUp = window.open(page, 'PopUp', 'location=no,toolbar=no,menubar=no,status=no,width=' + width + ',height=' + height +',scrollbars=no,resizable=' + resizable + ',left=' + (screen.width-width)/2 + ',top=' + (screen.height-height)/2);
}

function addInstrument_old(instrumentID, name, symbol, feeder, portfolioID) {
	var iPortfolioID = (""+portfolioID != "undefined") ? portfolioID : "";
	var sURL = 'http://www.globes.co.il/Finance/Portfolio/AddInstrumentOutside.asp?InstrumentID=' + instrumentID + 
			'&name=' + name + '&ticker=' + symbol + '&feeder=' + feeder + 
			'&portfolioID=' + iPortfolioID
	var sParams = 'toolbar=no, width=350, height=220, status=no, scrollbars=yes, resizable=yes, left=' + 
			  	(screen.width-350)/2 + ',top=' + (screen.height-220)/2
	var win = window.open(sURL, 'addInstrument', sParams);
}	

function addInstrument(instrumentID, name, symbol, feeder, portfolioID) {
	var url = "/globessites/globes/portfolio/Portfolio/ContentManager.aspx?"
	window.open( url
			+ "&Instrument_ID=" + instrumentID 
			+ "&popup_id=buysale" 
			+ "&feeder="+ feeder
			+ "&nameheb=" + name,"",
			"location=no,toolbar=no,menubar=no,status=yes,scrollbar=no, resizable=no , width=475,height=420")		
}

//allowed sending instrumentid different then current instrument
function handlePortfolioAddInstrument(instrumentid, feeder) {
    if (arguments.length < 2) {
        feeder = getQSParam("feeder")
        feeder = (feeder == "") ? "0" : feeder;
    }
    if (arguments.length < 1) { instrumentid = ""; }
    if (user_id != 'undefined' && user_id > 0) { 
           addPortfolioInstrumentByWizard(instrumentid, feeder);
    }
    else {
        loginAndAddInstrumentByWizard(instrumentid, feeder);
    }    
}

function addPortfolioInstrumentByWizard(instrumentID, feeder) {
    var url = "/globessites/globes/portfolio/portfolio/contentmanager.aspx?"
        	+ "Instrument_ID=" + instrumentID
			+ "&popup_id=buysale"
			+ "&feeder=" + feeder + "&mode=wizard";
    SignWizard_Show( url , 'wizard', 'get')
}

function loginAndAddInstrumentByWizard(instrumentID, feeder) {
    var url = "/globessites/globes/portfolio/portfolio/contentmanager.aspx?"
        	+ "Instrument_ID=" + instrumentID
			+ "&popup_id=buysale"
			+ "&feeder=" + feeder + "&t=" + (new Date()).getTime() + "&mode=wizard";
    SignWizard_Show('/pay/login.asp?mode=wizard&p_backTo=' + escape(url), 'wizard', 'get')

}

				
