﻿// JScript File

addOnLoad(function() {OnLoad();});



function OnLoad()
{       
    /* Hide this items for now */	    
	$('li2', 'li18', 'li25', 'li27').invoke('hide');		
	
	var iTab = new Number($('ctl00_Main_Tab').value);		
	//var iTab = new Number(objData.value);
	
	//alert(iTab);
	
	if(iTab == 0)
    {
        activetab(1);
        return;
    }
	
	if(iTab != 0)
	{
	    activetab(iTab);
	}
	
}


function activetab(tab)
{

    tab = parseInt(tab);
    //alert('[' + tab + ']');
    switch (tab)
    {
        case 1:            
            tabState("hrefstep1", 'on');                                                
            tabState("hrefstep2", 'off');            
            tabState("hrefstep3", 'off');            
            divState(1);
            break;
        
        case '1':            
            tabState("hrefstep1", 'on');                                                
            tabState("hrefstep2", 'off');            
            tabState("hrefstep3", 'off');            
            divState(1);
            break;
        
        case 2:
            tabState("hrefstep1", 'off');
            tabState("hrefstep2", 'on');
            tabState("hrefstep3", 'off');  
            divState(2);
            break;
            
        case '2':
            tabState("hrefstep1", 'off');
            tabState("hrefstep2", 'on');
            tabState("hrefstep3", 'off');  
            divState(2);
            break;
        
        case 3:
            tabState("hrefstep1", 'off');
            tabState("hrefstep2", 'off');
            tabState("hrefstep3", 'on');  
            divState(3);
            break;
            
        case '3':
            tabState("hrefstep1", 'off');
            tabState("hrefstep2", 'off');
            tabState("hrefstep3", 'on');  
            divState(3);
            break;
        
        default:
            tabState("hrefstep1", 'off');
            tabState("hrefstep2", 'off');
            tabState("hrefstep3", 'on');
            divState(3);  
            break;        
}
    

}

function tabState(tab, state)
{
    var currentTab = document.getElementById(tab);
    /*var currentSpan = document.getElementById('step1');*/
        
    
	if(state == 'on')
	{	
	    /*currentSpan.fontweight = "bold";    */
	    currentTab.style.backgroundImage = "";
	    currentTab.style.color = "#006666";
	    currentTab.style.fontweight = "bold";
	    currentTab.style.background = "url( /images/backgrounds/stocksscreeneroptionstab.gif ) top left no-repeat";
    }
	
	if(state == 'off')
	{
	    /*currentSpan.fontweight = "normal";*/
	    currentTab.style.backgroundImage = "";
	    currentTab.style.color = "#006666";
	    currentTab.style.fontweight = "normal";
	    currentTab.style.background = "url( /images/backgrounds/stocksscreeneroptionstab.gif ) 0 -50px no-repeat";
	}
}
	

function divState(div)
{
    
    switch (div)
    {
        case 1:    
            document.getElementById("divStep1").style.display = "block";
            document.getElementById("divStep2").style.display = "none";
            document.getElementById("divStep3").style.display = "none";
            $('screenermenu').style.height = "280px";            
            $('hrefstep1').style.fontWeight = "bold";
            $('hrefstep2').style.fontWeight = "normal";
            $('hrefstep3').style.fontWeight = "normal";
            break;
            
        case '1':    
            document.getElementById("divStep1").style.display = "block";
            document.getElementById("divStep2").style.display = "none";
            document.getElementById("divStep3").style.display = "none";
            $('screenermenu').style.height = "280px";            
            $('hrefstep1').style.fontWeight = "bold";
            $('hrefstep2').style.fontWeight = "normal";
            $('hrefstep3').style.fontWeight = "normal";
            break;    
        
        case 2:
            document.getElementById("divStep1").style.display = "none";
            document.getElementById("divStep2").style.display = "block";
            document.getElementById("divStep3").style.display = "none";
            $('screenermenu').style.height = "350px";
            $('hrefstep1').style.fontWeight = "normal";
            $('hrefstep2').style.fontWeight = "bold";
            $('hrefstep3').style.fontWeight = "normal";
            break;
            
        case '2':
            document.getElementById("divStep1").style.display = "none";
            document.getElementById("divStep2").style.display = "block";
            document.getElementById("divStep3").style.display = "none";
            $('screenermenu').style.height = "350px";
            $('hrefstep1').style.fontWeight = "normal";
            $('hrefstep2').style.fontWeight = "bold";
            $('hrefstep3').style.fontWeight = "normal";
            break;    
        
        case 3:
            document.getElementById("divStep1").style.display = "none";
            document.getElementById("divStep2").style.display = "none";
            document.getElementById("divStep3").style.display = "block";
            $('screenermenu').style.height = "350px";
            $('hrefstep1').style.fontWeight = "normal";
            $('hrefstep2').style.fontWeight = "normal";
            $('hrefstep3').style.fontWeight = "bold";            
            break;
        
        case '3':
            document.getElementById("divStep1").style.display = "none";
            document.getElementById("divStep2").style.display = "none";
            document.getElementById("divStep3").style.display = "block";
            $('screenermenu').style.height = "350px";
            $('hrefstep1').style.fontWeight = "normal";
            $('hrefstep2').style.fontWeight = "normal";
            $('hrefstep3').style.fontWeight = "bold";            
            break;
    
    }
    /*$('myheight').innerHTML = $('screenermenu').style.height;*/
    /*$('myheight').innerHTML = $('screenermenu').style.width;*/
    
}



function checkNone()
{
    

    var boxes = $('step3').getElementsByTagName("input");
    for (var i = 0; i < boxes.length; i++) 
    {
        myType = boxes[i].getAttribute("type");
        if ( myType == "checkbox") 
        {
            boxes[i].checked=0;
        }
    }
}



function berniespicks(type)
{



    var radioGrp = document.aspnetForm.ctl00$Main$bias;
    for(i=0; i < radioGrp.length; i++)
    {
        radioGrp[i].checked = false;
    }


    /*
        uncheck all of the checkboxes
    */
    checkNone();   
   
   
   //Make the default selections for bernie's picks
   
   //closing price
    $('ctl00_Main_cbCols1').checked = true;
    
    //Short-Interest Ration
    $('ctl00_Main_cbCols3').checked = true;
    
    //Short Interest/Float
    $('ctl00_Main_cbCols6').checked = true;
    
    //Schaeffer's Put/Call Ration (SOIR)
    $('ctl00_Main_cbCols8').checked = true;
    
    //Analyst Ratings - % Buy
    $('ctl00_Main_cbCols9').checked = true;
    
    //SOIR Percentile Rank
    $('ctl00_Main_cbCols11').checked = true;
    
    //Call Open Interest
    $('ctl00_Main_cbCols14').checked = true;
    
    //Put Open Interest
    $('ctl00_Main_cbCols17').checked = true;    
    
    //Stocks near an annual High/Low
    $('ctl00_Main_cbFilter5').checked = false;
    //$('ctl00_Main_ddlFilter5a').selectedindex = 0; 
    document.aspnetForm.ctl00$Main$ddlFilter5a.selectedIndex = 0; 
    
    //Overbought/Oversold historical volatility
    $('ctl00_Main_cbFilter7').checked = false;
    //$('ctl00_Main_ddlFilter7a').selectedindex = 0;
    document.aspnetForm.ctl00$Main$ddlFilter7a.selectedIndex = 0; 
    
    //High/Low historical volatility
    $('ctl00_Main_cbFilter8').checked = false;
    //$('ctl00_Main_ddlFilter8a').selectedindex = 0;
    document.aspnetForm.ctl00$Main$ddlFilter8a.selectedIndex = 0; 
    
     //Beta less/greater
    $('ctl00_Main_cbFilter10').checked = false;
    //$('ctl00_Main_ddlFilter10a').selectedindex = 0;
    document.aspnetForm.ctl00$Main$ddlFilter10a.selectedIndex = 0; 
    
     //Market Cap small/mid/large
    $('ctl00_Main_cbFilter11').checked = false;
    //$('ctl00_Main_ddlFilter11a').selectedindex = 0;
    document.aspnetForm.ctl00$Main$ddlFilter11a.selectedIndex = 0; 
   
   /*
    Pick the bullish or bearish picks
   */
   
    switch(type)
    {
    case 'bullish':
        // make selections
        
        // Stocks showing heavy all-around skepticism
        $('ctl00_Main_cbBias3').checked = true;
        
        // Minimum stock price
        $('ctl00_Main_cbFilter1').checked = true;
        $('ctl00_Main_tbFilter1').value = '10';
        
        //Minimum average daily stock volume
        $('ctl00_Main_cbFilter2').checked = true;
        $('ctl00_Main_tbFilter2').value = '1000';
        
        //Minimum put & call open interest
        $('ctl00_Main_cbFilter3').checked = false;
        $('ctl00_Main_tbFilter3').text = '';
        
        //Stock price above/below 20/50/200 day moving average
        $('ctl00_Main_cbFilter4').checked = true;
        document.aspnetForm.ctl00$Main$ddlFilter4a.selectedIndex = 1;        
        //$('ctl00_Main_ddlFilter4a').selectedIndex = 1;
        
        //$('ctl00_Main_ddlFilter4b').selectedIndex = 3;
        document.aspnetForm.ctl00$Main$ddlFilter4b.selectedIndex = 3;
        
         //Total analyst rankings
        $('ctl00_Main_cbFilter12').checked = true;
        //$('ctl00_Main_ddlFilter12a').selectedIndex = 3;
        document.aspnetForm.ctl00$Main$ddlFilter12a.selectedIndex = 3;
        
        break;
    
    case 'bearish':
        // make selections
        
        // Stocks showing heavy all-around skepticism
        $('ctl00_Main_cbBias7').checked = true;
        
        // Minimum stock price
        $('ctl00_Main_cbFilter1').checked = true;
        $('ctl00_Main_tbFilter1').value = '10';
        
        //Minimum average daily stock volume
        $('ctl00_Main_cbFilter2').checked = true;
        $('ctl00_Main_tbFilter2').value = '1000';
        
        //Minimum put & call open interest
        $('ctl00_Main_cbFilter3').checked = false;
        $('ctl00_Main_tbFilter3').text = '';
        
        //Stock price above/below 20/50/200 day moving average
        $('ctl00_Main_cbFilter4').checked = true;        
        //$('ctl00_Main_ddlFilter4a').options[selectedIndex] = 3;
        document.aspnetForm.ctl00$Main$ddlFilter4a.selectedIndex = 2;
        //$('ctl00_Main_ddlFilter4b').options[selectedIndex] = 3;
        document.aspnetForm.ctl00$Main$ddlFilter4b.selectedIndex = 3;
                
         //Total analyst rankings
        $('ctl00_Main_cbFilter12').checked = true;
        //$('ctl00_Main_ddlFilter12a').options[selectedIndex] = 3;
        document.aspnetForm.ctl00$Main$ddlFilter12a.selectedIndex = 3;
        
        break;
    }
    
    /*
        submit the form
    */    
    
    
    //BtnClick("");
    
  
}


function pg(a)
{


//    if(a==5)
//    {
//        $('step1', 'step2', 'step3').invoke('hide');
//        $('l1').setStyle({  fontWeight: 'normal'});
//        $('step5').show(); 
//               
//    }

//	if (a==1)
//	{    
//	    	    	    
//	    $('step1').show();
//	    $('step2', 'step3', 'step5').invoke('hide');
//	    $('l1').setStyle({ fontWeight: 'bold' });
//	    $('l2', 'l3').invoke('setStyle', { fontWeight: 'normal' });
//	    
//	}
//	if (a==2)
//	{
//	    
//	    $('step2').show();
//	    $('step1', 'step3', 'step5').invoke('hide');
//	    $('l2').setStyle({ fontWeight: 'bold' });
//	    $('l1', 'l3').invoke('setStyle', { fontWeight: 'normal' });
//	    
//	}
//	if (a==3)
//	{
//	
//	    $('step3').show();
//	    $('step1', 'step2', 'step5').invoke('hide');
//	    $('l3').setStyle({ fontWeight: 'bold' });
//	    $('l1', 'l2').invoke('setStyle', { fontWeight: 'normal' });
//	    
//	}
//	if (a==4)
//	{
//		document.getElementById('step4').style.display='block';
//	}
}

function BtnClick(sType)
{
    /*debugger*/
	var objData = $('ctl00_Main_BtnAction');	
	objData.value = sType;
	FormSubmit();	
}	

function FormSubmit()
{
    /*debugger*/

	/*
	try
	{
	
	*/
	
		//get the checkboxes
		var iIndex = 0;
		var lcChecks = 0;
		var sPre = "ctl00_Main_cbCols";
		var sID = "";
		var sIDs = "";
		var objDDL;
		var tmpDDLName;
		var objTB;
		var objCB = null;
		var objData = $('ctl00_Main_DataColumns');
		var objCBs;
		var objDataAlerts;
		var objDataWatchList;
		
		var formAction = $('ctl00_Main_BtnAction');
		
		if(formAction != null)
	    {
	        
	        if(formAction.value == 'Alerts' || formAction.value == 'Watchlist')
	        {	        
	            //get all the checked CBs for alerts/watchlist
		        var objDataAlerts = $("ctl00_Main_DataAlerts");
		        var objDataWatchList = $("ctl00_Main_DataWatchList");
		        var sMsg = "";
		        objDataAlerts.value = "";
		        objDataWatchList.value = "";
		        objCBs = document.getElementsByTagName("INPUT");
		        for(iIndex = 0;iIndex < objCBs.length;iIndex++)
		        {
			        objCB = objCBs[iIndex];
			        if(objCB.getAttribute("type") == "checkbox")
			        {
				        if(objCB.checked == true)
				        {
					        sIDs = new String(objCB.id);
					        sMsg += sIDs + " ";
					        sID = sIDs.substr(sIDs.indexOf("-")+1, sIDs.length-sIDs.indexOf("-"));
					        if(sIDs.indexOf("ALERT") != -1)
					        {
						        objDataAlerts.value += sID + "~";				
					        }
					        else
					        if(sIDs.indexOf("WATCHLIST") != -1)
					        {
						        objDataWatchList.value += sID + "~";	
					        }
				        }
			        }
		        }
		        
		        //are there any checked items for alerts? if not return false;
		        if(formAction.value == 'Alerts')
		        {
		            if(objDataAlerts.value == "")
		            {
		                //$('ctl00_Main_BtnAction').value = "";
		                $('ctl00_Main_BtnAction').value = "ReloadData";
		                //return false;
		            }
		        }
		        
		        //are there any checked items for watchlist? if not return false;
		        if(formAction.value == 'Watchlist')
		        {
		            if(objDataWatchList.value == "")
		            {
		                //$('ctl00_Main_BtnAction').value = "";
		                $('ctl00_Main_BtnAction').value = "ReloadData";
		                //return false;
		            }
		        }
		    }
		    
	        
	    }
		
		
		
		//columns tab 3
		
		objData.value = "";
		
		
		
		for(iIndex = 1;iIndex <= 27;iIndex++)
		{
			sID = sPre + new String(iIndex);
			objCB = $(sID);
			if(objCB.checked == true)
			{
				objData.value += new String(iIndex) + "~";
				lcChecks += 1;		
			}
			if(lcChecks >8)
			{
				alert("Step 3:  Please make up to 8 Selections. Currently there are more than 9 Options checked.");
				objData.value = "";
				activetab(3);				
				return false;
			}
		}
		if(lcChecks == 0)
		{
			alert("Step 3: Please make at least one Selections. Currently there are no asp:ListItems checked.");
			return false;
		}



        


		//filters step 2
		objData = $("ctl00_Main_DataFilters");
		if(objData != null)
		{
			objData.value = "";
		}
		else
		{
			alert("no hidden field");
		}
		//cbFilters1-3
		objCB = $("ctl00_Main_cbFilter" + new String(1));
		if(objCB.checked == true)
		{
			objTB =  $("ctl00_Main_tbFilter" + new String(1));
			if(objTB.value.length == 0)
			{
				alert("Step 2: Please enter a value for Minimum stock price");
				return false;
			}
			else
			{
				objData.value += "1!true!" + objTB.value + "!~";
			}
		}
		else
		{
			objData.value += "1!false!!~";	
		}
		objCB = $("ctl00_Main_cbFilter" + new String(2));
		if(objCB.checked == true)
		{
			objTB =  $("ctl00_Main_tbFilter" + new String(2));
			if(objTB.value.length == 0)
			{
				alert("Step 2: Please enter a value for Minimum put & call open interest");
				return false;
			}
			else
			{
				objData.value += "2!true!" + objTB.value + "!~";
			}
		}
		else
		{
			objData.value += "2!false!!~";	
		}
		objCB = $("ctl00_Main_cbFilter" + new String(3));
		if(objCB.checked == true)
		{
			objTB =  $("ctl00_Main_tbFilter" + new String(3));
			if(objTB.value.length == 0)
			{
				alert("Step 2: Please enter a value for Minimum average daily stock volume");
				return false;
			}
			else
			{
				objData.value += "3!true!" + objTB.value + "!~";
			}
		}
		else
		{
			objData.value += "3!false!!~";	
		}
		//cbFilters4-12
		for(iIndex = 4; iIndex <= 12; iIndex++)
		{
			objCB = $("ctl00_Main_cbFilter" + new String(iIndex));
			if(objCB.checked == true)
			{
			    tmpDDLName = "ctl00$Main$ddlFilter" + new String(iIndex) + "a";
				objDDL =  document.aspnetForm.tmpDDLName;
				if(objDDL != null)
				{
					if(objDDL.options(objDDL.selectedIndex).value.length == 0)
					{
						alert("Step 2: Please select the appropriate values in the Additional Filters section");
						return false;
					}
					else
					{
						objData.value += new String(iIndex) + "!true!" + objDDL.options(objDDL.selectedIndex).value + "!";
					}
				}
				
				tmpDDLName = "ctl00$Main$ddlFilter" + new String(iIndex) + "b";
				objDDL =  document.aspnetForm.tmpDDLName;
				if(objDDL != null)
				{
					if(objDDL.options(objDDL.selectedIndex).value.length == 0)
					{
						alert("Step 2: Please select the appropriate values in the Additional Filters section");
						return false;
					}
					else
					{
						objData.value += objDDL.options(objDDL.selectedIndex).value + "!~";
					}
				}
				else
				{
					objData.value += "~";
				}
			}
			else
			{
				objData.value += new String(iIndex) + "!false!~";	
			}	
		}

		//step 1 only one choice
		var objData = $("ctl00_Main_DataBias");
		objCB = window.document.getElementsByName("ctl00$Main$bias");
		for(iIndex = 0;iIndex < objCB.length;iIndex++)
		{
			if(objCB[iIndex].checked == true)
			{
				objData.value = iIndex;
				break;
			}
		}
		
		
		

		
	/*
	}
	catch(e)
	{
		alert("Form validation: Error occurred. Description: " + e.description + " " + iIndex);
		return false;
	}
	*/
	
	activetab(3);
	return true;
}



function HideShow()
{
	if(window.event.srcElement.innerText == "Show")
	{
		window.event.srcElement.innerText = "Hide";
		document.getElementById('step1').style.display='block';
		document.getElementById('step2').style.display='none';
		document.getElementById('step3').style.display='none';		
	}
	else
	{
		document.getElementById('step1').style.display='none';
		document.getElementById('step2').style.display='none';
		document.getElementById('step3').style.display='none';

		window.event.srcElement.innerText = "Show";
	}
}









