function checkAdmin()
{
    //window.open("http://owners.pub.promodc.net/admin_new/admin.aspx");
    window.open("http://www.argusvickers.com/admin_new/admin.aspx");
}

function checkNominee(thisUser,UID,SID)
{
    if (thisUser == "1" || thisUser == "2")
	{
	  //window.location = "http://owners.pub.promodc.net/nomineebook/nominee.aspx?memberType=" + thisUser + "&uid=" + UID + "&sid=" + SID;
	  window.location = "http://www.argusvickers.com/nomineebook/nominee.aspx?memberType=" + thisUser + "&uid=" + UID + "&sid=" + SID;
	}
	else if (thisUser == "0" || thisUser == "3")
	{
	  alert("You do not have permission to access to this web application.\r\nPlease contact us at +44(0) 207 256 8383.");
	}
	else
	{
	  window.location="login_tz.asp";
	}
}

// Owners: 0, Owners and Nominee: 1, Owners and Portfolio: 3
function checkOwners(thisUser,myURL)
{
    if (thisUser =="0" || thisUser =="1" || thisUser =="3")
	{
	  window.location = myURL;
	}
	else if (thisUser == "2")
	{
	  alert("You do not have permission to access to this web application.\r\nPlease contact us at +44(0) 207 256 8383.");
	}
	else
	{
	  window.location="login_tz.asp";
	}
}

function setfocus()
{
    //do nothing
}

var timer;
function searchSubmit()
{
	document.forms[0].action=location.href;
    selectAllOptions(document.forms[0].peers);
	setTimeout("document.forms[0].submit();", 500);
	timer = -1;
}

function searchSubmit2()
{
	document.forms[0].action=location.href;
	selectAllOptions(document.forms[0].peers);
	//alert('selectall');
    setTimeout("document.forms[0].submit();", 500);
}

function searchSubmit3()
{
	document.forms[0].action=location.href;
    selectAllOptions(document.forms[0].sector);
	setTimeout("document.forms[0].submit();", 500);
	timer = -1;
}

function search()
{	
	if (timer != -1) 
	{
		clearTimeout(timer);
	}	
	timer = setTimeout("searchSubmit();", 3000);
}

function search2()
{	
	if (timer != -1) 
	{
		clearTimeout(timer);
	}	
	timer = setTimeout("searchSubmit3();", 3000);
}


function formSubmit()
{
    if (document.forms[0].peers.length < 1) 
    {
        alert("You did not make a selection.");
        //return false;
    } 
    else 
    {
	selectAllOptions(document.forms[0].peers);
	
    	if(document.forms[0].common.checked)
    	{
        	document.forms[0].action="common" + document.forms[0].action;
	}
	
	document.forms[0].submit();
    }  
}

function formSubmit2()
{
    selectAllOptions(document.forms[0].sector);
    document.forms[0].done.value = "1";
    document.forms[0].submit();
}

function industry()
{
    selectAllOptions(document.forms[0].sector);
    selectAllOptions(document.forms[0].peers);
    document.forms[0].action="industry2_tz.asp";
    document.forms[0].submit();
}

function isInOption(item, obj)
{
	var bool = false;
	for (var i=0; i<obj.options.length; i++) 
	{
		if (item.value+'*'+item.text == obj.options[i].value)
		{
			bool = true;				
		}
		
		if (item.text == obj.options[i].text)
		{
			bool = true;				
		}
		
	}
	return bool;
}

function reorderSelectedOptions(list,direction) 
{
	var index = 0;
	
	if (list.size == 4) index = 1;
	
	if(list.options.length > 1) 
	{
		if(direction == "up")
		{
			for(var i= index; i < list.options.length; i++) 
			{
				var o = list.options[i];
				if(o.selected) 
				{
					if(i > index) 
					{
						var temp = list.options[i-1];
						list.options[i-1] = new Option( o.text, o.value, false, true);
						list.options[i] = new Option( temp.text, temp.value, false, false);
					}
				}
			}
		}
		else if(direction == "down")
		{
			for(var i = list.options.length-1; i >= index; i--) 
			{
				var o = list.options[i];
				if(o.selected) 
				{
					if(i < list.options.length-1) 
					{
						var temp = list.options[i+1];
						list.options[i+1] = new Option( o.text, o.value, false, true);
						list.options[i] = new Option( temp.text, temp.value, false, false);
					}
				}
			}
		}
	}
}

function moveSelectedOptions(from,to) 
{	
	var maxStocks = 0;
	var defaultStock;
	var foundIt = 1;
	
	if (from.size == 10 && to.size == 4 && to.options[0].value !='') defaultStock = to.options[0].text;
	if (from.size == 4 && to.size == 10 && from.options[0].value !='') defaultStock = from.options[0].text;

	//alert(defaultStock);
	
	// Move them over
	for (var i=0; i<from.options.length; i++) 
	{
		var o = from.options[i];
		
	        if (o.selected )
		{
		    if (!isInOption(o, to))
		    {    
		        foundIt = 0;
			if (from.size == 10 && to.size == 4) 			
			{	
			   
			   if (to.length ==4)
			   {
			   	maxStocks = 1;
				alert("You can only view 3 stocks from other companies!");  
				break;
			   }
			}
		
			if (o.value.indexOf("*") >= 0) 
			{
				to.options[to.options.length] = new Option( o.text, o.value.substring(0, o.value.indexOf("*")), false, false);
		        } 
		        else
		        {
				to.options[to.options.length] = new Option( o.text, o.value+'*'+o.text, false, false);
			}
		    }	
		}
	}
	
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) 
	{
	    var o = from.options[i];
		
		if (o.selected) 
		{
		  //alert("foundIt: " + foundIt + " this stock: " + o.text + " || default stock: " + defaultStock);
		  if (maxStocks || foundIt)
		  { 
		     from.options[i] = o;
		  } 
		  else if (o.text == defaultStock) 
		  {
		     alert("You can not move your company stock!");
		     from.options[i] = o;
	          } 
	          else 
	          {
	             from.options[i] = null;
	          }
	          
	     }
	}
	//sortSelect(to)
	
	/*if (arguments[2]=="true")
             sortSelect(from);
          else
	     sortSelect(to);
	*/
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}

/*function copySelectedOptionsOld(from,to) 
{
	for (var i=0; i<from.options.length; i++) 
	{
		var o = from.options[i];
        if (o.value != '') 
        {
            if (o.selected) 
            {
				if (!isInOption(o, to)){
	                if ((o.value % 10) == 0 && (o.value.length < 3)) 
	                {
	                     do 
	                     {
	                        if (o.value.indexOf("*") >= 0)
	                            to.options[to.options.length] = new Option( o.text, o.value.substring(0, o.value.indexOf("*")), false, false);
	                        else
	    			            to.options[to.options.length] = new Option( o.text, o.value+'*'+o.text, false, false);
	                        i++;
	                        o = from.options[i];
	                        
	                        if (o == null) 
	                        { 
	                            break;
	                        }
	                    } while ((o.value % 10 != 0) || (o.value.length > 2))
	                }
	                else if (((o.value % 10) != 0) && (o.value.length < 3)) 
	                {
	                    do 
	                    {
	                        if (o.value.indexOf("*") >= 0)
	                            to.options[to.options.length] = new Option( o.text, o.value.substring(0, o.value.indexOf("*")), false, false);
	                        else
	    			            to.options[to.options.length] = new Option( o.text, o.value+'*'+o.text, false, false);
	                        i++;
	                        o = from.option
	                        s[i];
	                        if (o == null) 
	                        { 
	                            break;
	                        }
	                    } while (o.value.length > 2)
	                } 
	                else 
	                {
	                    if (o.value.indexOf("*") >= 0)
	                        to.options[to.options.length] = new Option( o.text, o.value.substring(0, o.value.indexOf("*")), false, false);
	                    else
	        			    to.options[to.options.length] = new Option( o.text, o.value+'*'+o.text, false, false);
	                }
	         	}
    		}
        }
	}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}*/

function copySelectedOptions(from,to) 
{
	for (var i=0; i<from.options.length; i++) 
	{
		var o = from.options[i];
        if (o.value != '') 
        {
            if (o.selected) 
            {
				if (!isInOption(o, to))
				{
	                if ((o.value % 10) == 0 && (o.value.length < 3)) 
	                {
	                     do 
	                     {
							if (!isInOption(o, to))
							{
								if (o.value.indexOf("*") >= 0)
									to.options[to.options.length] = new Option( o.text, o.value.substring(0, o.value.indexOf("*")), false, false);
								else
	    							to.options[to.options.length] = new Option( o.text, o.value+'*'+o.text, false, false);
	    					}
	    					i++;
							o = from.options[i];
							if (o == null) 
							{ 
								break;
							}
	                    } while ((o.value % 10 != 0) || (o.value.length > 2))
	                }
	                else if (((o.value % 10) != 0) && (o.value.length < 3)) 
	                {
	                    do 
	                    {
							if (!isInOption(o, to))
							{
								if (o.value.indexOf("*") >= 0)
									to.options[to.options.length] = new Option( o.text, o.value.substring(0, o.value.indexOf("*")), false, false);
								else
	    							to.options[to.options.length] = new Option( o.text, o.value+'*'+o.text, false, false);
	    					}
							i++;
							o = from.options[i];
							if (o == null ) 
							{ 
								break;
							}
	                    } while (o.value.length > 2)
	                } 
	                else 
	                {
	                    if (o.value.indexOf("*") >= 0)
	                        to.options[to.options.length] = new Option( o.text, o.value.substring(0, o.value.indexOf("*")), false, false);
	                    else
	        			    to.options[to.options.length] = new Option( o.text, o.value+'*'+o.text, false, false);
	                }
	         	}
    		}
        }
	}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}

function removeOptions(from) 
{
	for (var i=(from.options.length-1); i>=0; i--) 
	{
		from.options[i] = null;
	}
	from.selectedIndex = -1;
}

function clear(from) 
{
	for (var i=(from.options.length-1); i>=0; i--) 
	{
		from.options[i] = null;
	}    
	from.selectedIndex = -1;
}

function unselectOptions(from) 
{
	// Delete 
	for (var i=(from.options.length-1); i>=0; i--) 
	{
		var o = from.options[i];
		if (o.selected) 
		{
			from.options[i].selected = false;
		}
	}
	from.selectedIndex = -1;
}


// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) 
{
	var o = new Array();
	for (var i=0; i<obj.options.length; i++) 
	{
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
	}
	o = o.sort( 
		function(a,b) 
		{ 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
		} 
	);
	for (var i=0; i<o.length; i++) 
	{
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	}
}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) 
{
	for (var i=0; i<obj.options.length; i++) 
	{
		obj.options[i].selected = true;
	}
}