﻿  var params = "";

  IipUp_stockSearch = new ssDropDown();
  IipUp_stockSearch.searchStringID = "Symbol";
  IipUp_stockSearch.dropDownID = "ssStockSearch";
  IipUp_stockSearch.typeID = 5;
  IipUp_stockSearch.autoHide = true;
  IipUp_stockSearch.autoHideTime = 3000;
  IipUp_stockSearch.showNameOnSelect = false;
  IipUp_stockSearch.onItemSelected = IipUp_StockSearchRenderItem;



function IipUp_SearchStock(e) {
	
  if (e && e.keyCode != 13) {
  	IipUp_stockSearch.OnKeyDown(e);
  }
}

function IipUp_StockSearchRenderItem(type, search, name) {
	document.getElementById(IipUp_stockSearch.searchStringID).value = unescape(search);
}

function clearDescriptionDefaultMessage(elem){
	if(elem.value=='in 1,000 characters or less, provide the methodology of the index or explain how the index was created. Provide the sources of the research for it and, if applicable, a link to the full research report.')
		elem.value=''
}
function clearCreatorOverviewDefaultMessage(elem){
    if (elem.value == 'In 500 characters or less, provide an overview of the index creator, including company background or personal experience, as related to the index.')
		elem.value=''
}

function IipUpDetailsSave(pid) {
	clearDescriptionDefaultMessage(document.getElementById("PortfolioDescription"));
	TabsUpdateCurrent("PortfolioID=" + pid+"&"+ GetControlParameters("IndexProfileEditTable", "SAVE"), true);
}

function IipUpDetailsSaveAuthor(pid) {
    clearCreatorOverviewDefaultMessage(document.getElementById("CreatorExperience"));
    TabsUpdateCurrent("PortfolioID=" + pid + "&" + GetControlParameters("AuthorEditTable", "SAVEAUTHOR"), true);
}

function IipUpDetailsUploadSearch(searchTypeID, replace) {
	jQuery("#ListBuffer").val(jQuery("#Symbol").val());
	return IipUpDetailsUpload(searchTypeID,false,replace);
}


function IipUpDetailsUpload(searchTypeID, isBuffer, replace) {
  if (cDialog!=undefined) {
    cDialog.hide();
  }
  if (isBuffer) jQuery("#ListBuffer").val(window.clipboardData.getData("Text"));

  var value = '';

  if (searchTypeID == 1) //Stocks
      value = document.getElementById("Symbol").value;
  if (searchTypeID == 2) //Buffer
     value = document.getElementById("ListBuffer").value;
  if (searchTypeID == 3) //TextArea
      value = document.getElementById("List").value;
   
  if (Trim(value) == '')  {
    alert('No Data.');
    return false;
  }

  IipYouUPScrollPageToTop();
	TabsActivateTab('IipProfilePortfolioUpload', '&Replace=' + (replace ? "Y" : "N") + '&' + GetControlParameters("TabControlLevel1", "UPLOAD"));
	return true;
}

function IipUpDetailsStocksDelete() {
    var checkedStocks = IipUpGetCheckedRows();
    if (checkedStocks.length == 0)
        alert("Please select stocks to delete");
	else {
	
	IipYouJQueryConfirm('Do you really want to delete selected stocks?','Delete',function(){
			TabsUpdateCurrent(GetControlParameters("TabControlLevel1", "DELETE"));
		}));
	}
	    
}

function IipUpdateCategories() {
        var iGroupID = document.getElementById("GroupID");

	params = "GroupID=" + escape(iGroupID.options[iGroupID.selectedIndex].value);
		
	UpdateControlEx('iip_user_portfolio_categories','iip_user_portfolio_categories',params,null,null,null);		
	return false;
}

function IipUpDetailsCheckCommission(){
	var commission = document.getElementById("Commission");
	if(commission.value=="")
		commission.value =0;

	if(!IsNumeric(commission.value) || commission.value <0 || commission.value > 100)
	{
		alert("Commission Value must be between 0 and 100");
		return false;
	}
}

function IipUpDetailsStockSearch(action){
	if (action)
		params = "Action="+ action + "&SaveParams=0&" + GetControlParameters('iip_user_portfolio_stock_search');
	else
		params = "SaveParams=0&" + GetControlParameters('iip_user_portfolio_stock_search');

	UpdateControlEx('iip_user_portfolio_stock_search','iip_user_portfolio_stock_search',params,null,null,null);		
}



function IipUpDetailsRequestStock(action){
	var sUserName = document.getElementById("tbUserName");
	var sUserPhone = document.getElementById("tbUserPhone");
	var sUserEmail = document.getElementById("tbUserEmail");

	var sTicker = document.getElementById("tbSymbol");
	var sRic = document.getElementById("tbRic");
	var sBloombergCode = document.getElementById("tbBloombergCode");
	var sSedol = document.getElementById("tbSedol");
	var sCusip = document.getElementById("tbCusip");
	var sIsin = document.getElementById("tbIsin");

		
	if(sTicker.value == "" && sRic.value == "" &&  sBloombergCode.value == "" &&  sSedol.value == "" &&  sCusip.value == "" && sIsin.value == "")
	{
		alert('Please specify at least one of `Ticker, or RIC, or Bloomberg Code, or SEDOL, or CUSIP, or ISIN` value');
		return false;
	}


	if (!validate_required(sUserName, 'Please enter Your Name'))
	{
		return false;
	}


	if(!validate_required(sUserEmail, 'Please enter Email'))
	{
		return false;
	}

	if(sUserEmail.value != "")
	{	
		if (!IsEmail(sUserEmail.value))
		{
			alert('Please specify Email value');
			return false;
		}	
	}


	if (action)
		params = "Action="+ action + "&SaveParams=0&" + GetControlParameters('iip_user_portfolio_stocks_requests');
	else
		params = "SaveParams=0&" + GetControlParameters('iip_user_portfolio_stocks_requests');

	UpdateControlEx('iip_user_portfolio_stocks_requests','iip_user_portfolio_stocks_requests',params,Iip_UpRequestStockHideDialog,null,null);		
}

function Iip_UpStockSearchHideDialog()
	{
		Dialog.hide();
		UpdateControlEx('iip_user_portfolio_details','iip_user_portfolio_details','',null,null,null);		
	}



function Iip_UpRequestStockHideDialog()
	{
		Dialog.hide();
		UpdateControlEx('iip_user_portfolio_details','iip_user_portfolio_details','',null,null,null);		
	}


function validate_required(field,alerttxt)
	{
		with (field)
		{
		  if (value==null||value=="")
		  {
			alert(alerttxt);
			return false;
		  }
		  else
		  {
			return true;
		  }
		}
	}


var iipDetailsChange = 0 ; 

function iipDetailsSetChangeOn() {
    iipDetailsChange = 1;
}

function iipDetailsSetChangeOff() {
    iipDetailsChange = 0;
}

function iipDetailsDoVirtualSubmit(){
    if  (iipDetailsChange == 1) {
        var i = confirm("Do you realy want continue? Some data was changed, unsaved data will be lost.")==0;
        if (!i) {
           iipDetailsSetChangeOff();
        }
        return  i;
    } else {
        return false;
    }
}

function iipDetailsVirtualSubmit() {
    return true;
}

function iipDetailsGetChange() {
    
}

function iipDetailsStartUp() {
  var a = document.getElementById('GroupID');
  eval('var v = function(){iipDetailsSetChangeOn(); IipUpdateCategories();};');
  a.setAttribute("onchange", v); 
}


function iipPortfolioIdIsMinusOne(){
    var a = document.getElementById('PortfolioID');
    return (a.value==-1) ;
}


function iipDetailsAlertSavePortfolio(){
    alert('Portfolio was not saved, please first save portfolio!');
}

function iipDetailsCheckUploadedFile(){
	var fileinput = document.getElementById("logoFileUpload").value;
	var l = fileinput.lastIndexOf(".");
	if (l==-1){
		return iipDetailsCheckUploadedFileAlert(fileinput);
	}
	var extension =fileinput.substr(l+1, fileinput.length - l).toUpperCase();
	switch (extension) {
                case "JPG": return true;
                case "JPEG": return true;
                case "PNG": return true;
                case "GIF": return true;
            }
	return iipDetailsCheckUploadedFileAlert(fileinput);
}
function iipDetailsCheckUploadedFileAlert(filename){
  alert("this file is not supported ("+filename+") only [JPG,PNG,GIF,MP3,FLV]");
  return false;
}

function iipDetailsDeleteSelectedAttacments(){
	var mdiv = document.getElementById("iip_user_portfolio_media");
 	var elems = mdiv.getElementsByTagName("INPUT");
	var params = "MediaAction=DELETE"
	var fordelete = "";
	for (var i = 0 ; i<elems.length; i++){  
		var elem =  elems[i];
		if (elem.type=="checkbox" && elem.checked ){
			fordelete = fordelete + "," + elem.id;
		}
	}
	if (fordelete!="") {
		params = params + "&items="+fordelete;
	}
	UpdateControlEx('iip_user_portfolio_media','iip_user_portfolio_media',params,null,null,null);			
}











