﻿var A_TPL = {
		'b_watch': false,
		'n_controlWidth': 410,
		'n_controlHeight': 17,
		'n_sliderWidth': 13,
		'n_sliderHeight': 17,
		'n_pathLeft' : 0,
		'n_pathTop' : 0,
		'n_pathLength' : 400,
		's_imgControl': '../images/gettingstarted_slider_white.jpg',
		's_imageCover': '../images/gettingstarted_slider_redLi.jpg',
		's_imgSlider': '../images/gettingstarted_slider1.gif',
		'n_zIndex': 3
	}
//var countNumber =0;
function slider (a_init, a_tpl) {
	this.f_setValue = f_sliderSetValue;
	this.f_getPos    = f_sliderGetPos;
	
	// register in the global collection	
	if (!window.A_SLIDERS)
		window.A_SLIDERS = [];
	this.n_id = window.A_SLIDERS.length;
	window.A_SLIDERS[this.n_id] = this;

	// save config parameters in the slider object
	var s_key;
	if (a_tpl)
		for (s_key in a_tpl)    
			this[s_key] = a_tpl[s_key];
	for (s_key in a_init)
		this[s_key] = a_init[s_key];

	this.n_pix2value = this.n_pathLength / (this.n_maxValue - this.n_minValue);
	if (this.n_value == null)
		this.n_value = this.n_minValue;

	// generate the control's HTML
	//var temp = window.A_SLIDERS[window.n_activeSliderId];
	/*
	if(this.sections == 4){
	    document.write(
		    '<div style="width:' + this.n_controlWidth + 'px;' + 'border:none;margin:10px 0 30px 0;position:relative;background:url(' + this.s_imgControl + ') repeat-x 0 6px" id="sl' + this.n_id + 'base">' +
		    '<img src="'+this.s_imageCover+'" height="8" border="0" style="position:absolute;top:6px;width:1px;" id="sl' + this.n_id + 'redBG"/>'+
		    '<a href="javascript:void(0);"><img src="' + this.s_imgSlider + '" width="' + this.n_sliderWidth + '" height="' + this.n_sliderHeight + '" border="0" style="position:absolute;left:' + this.n_pathLeft + 'px;top:' + this.n_pathTop + 'px;z-index:' + this.n_zIndex + ';visibility:hidden;" name="sl' + this.n_id + 'slider" id="sl' + this.n_id + 'slider" onmousedown="return f_sliderMouseDown(' + this.n_id + ')"/></a>'+'<br />'+
		    '<ul class="gettingStart_sliderList"><li style="width:130px;">"'+this.textArray[0]+'</li><li style="width:150px;">'+this.textArray[1]+'</li><li style="width:115px;">'+this.textArray[2]+'</li><li>'+this.textArray[3]+'</li></ul>'+
		    '<div class="clear"><img src="../images/spacer.gif" alt="" width="1" height="1" border="0" /></div></div>'
	    );
	}*/
	if(this.sections == 3){
	    document.write(
		    '<div style="width:' + this.n_controlWidth + 'px;' + 'border:none;margin:5px 0 30px 22px;position:relative;background:url(' + this.s_imgControl + ') repeat-x 0 6px" id="sl' + this.n_id + 'base">' +
		    '<img src="../images/gettingstarted_leftEnd.gif" border="0" style="position:absolute;left:-4px;margin-top:6px !important;margin-top:5px;" /><img src="../images/gettingstarted_rightEnd.gif" border="0" style="position:absolute;right:-4px;margin-top:5px !important;margin-top:4px;" />'+
		    '<img src="'+this.s_imageCover+'" height="8" border="0" style="position:absolute;top:6px;left:0;width:1px;" id="sl' + this.n_id + 'redBG"/>'+
		    '<a href="javascript:void(0);"><img src="' + this.s_imgSlider + '" width="' + this.n_sliderWidth + '" height="' + this.n_sliderHeight + '" border="0" style="position:absolute;left:' + this.n_pathLeft + 'px;top:' + this.n_pathTop + 'px;z-index:' + this.n_zIndex + ';visibility:hidden;" name="sl' + this.n_id + 'slider" id="sl' + this.n_id + 'slider" onmousedown="return f_sliderMouseDown(' + this.n_id + ')"/></a><br />'+
		    '<ul class="gettingStart_sliderList"><li style="width:180px;"><a href="javascript:void(0)" onclick="window.A_SLIDERS[' + this.n_id + '].f_setValue(0);return false;" id="linkText'+ this.n_id +'_1" >'+this.textArray[0]+'</a><b id="linkText'+ this.n_id +'_1b" style="display:none;">'+this.textArray[0]+'</b></li><li style="width:200px;"><a href="javascript:void(0)" onclick="window.A_SLIDERS[' + this.n_id + '].f_setValue(50);return false;" id="linkText'+ this.n_id +'_2" style="display:none;">'+this.textArray[1]+'</a><b id="linkText'+ this.n_id +'_2b" style="display:inline;">'+this.textArray[1]+'</b></li><li style="float:right"><a href="javascript:void(0)" onclick="window.A_SLIDERS[' + this.n_id + '].f_setValue(100);return false;" id="linkText'+ this.n_id +'_3">'+this.textArray[2]+'</a><b id="linkText'+ this.n_id +'_3b" style="display:none;">'+this.textArray[2]+'</b></li></ul>'+
		    '<div class="clear"><img src="../images/spacer.gif" alt="" width="1" height="1" border="0" /></div></div>'
	    );
	}
	
	this.e_base   = get_element('sl' + this.n_id + 'base');
	this.e_slider = get_element('sl' + this.n_id + 'slider');
	this.e_redBG = get_element('sl' + this.n_id + 'redBG');
	
	// safely hook document/window events
	if (document.onmousemove != f_sliderMouseMove) {
		window.f_savedMouseMove = document.onmousemove;
		document.onmousemove = f_sliderMouseMove;
	}
	if (document.onmouseup != f_sliderMouseUp) {
		window.f_savedMouseUp = document.onmouseup;
		document.onmouseup = f_sliderMouseUp;
	}
	// preset to the value in the input box if available
	var e_input = this.s_form == null
		? get_element(this.s_name)
		: document.forms[this.s_form]
			? document.forms[this.s_form].elements[this.s_name]
			: null;
	this.f_setValue(e_input && e_input.value != '' ? e_input.value : null, 1);
	this.e_slider.style.visibility = 'visible';
	
}
function switchLinkAppear(_id,_nid){
   for(var i=1;i<4;i++){
    if(i == _id){
        var normalText = get_element("linkText"+_nid+"_"+i+"b");
        var linkText = get_element("linkText"+_nid+"_"+i);
        linkText.style.display = "none";
        normalText.style.display = "inline";
        
    }
    else{
       var normalText = get_element("linkText"+_nid+"_"+i+"b");
        var linkText = get_element("linkText"+_nid+"_"+i);
        linkText.style.display = "inline";
        normalText.style.display = "none";
    }
   }
}
function f_sliderSetValue (n_value, b_noInputCheck) {
	if (n_value == null)
		n_value = this.n_value == null ? this.n_minValue : this.n_value;
	if (isNaN(n_value))
		return false;
	// round to closest multiple if step is specified
	if (this.n_step)
		n_value = Math.round((n_value - this.n_minValue) / this.n_step) * this.n_step + this.n_minValue;
	// smooth out the result
	if (n_value % 1)
		n_value = Math.round(n_value * 1e5) / 1e5;

	if (n_value < this.n_minValue)
		n_value = this.n_minValue;
	if (n_value > this.n_maxValue)
		n_value = this.n_maxValue;

	this.n_value = n_value;

	// move the slider
		this.e_slider.style.left = (this.n_pathLeft + Math.round((n_value - this.n_minValue) * this.n_pix2value)) + 'px';
		this.e_redBG.style.width=(this.n_value*this.n_pix2value)+10+'px';
	// save new value
	var e_input = this.s_form == null
		? get_element(this.s_name)
		: document.forms[this.s_form]
			? document.forms[this.s_form].elements[this.s_name]
			: null;
	e_input.value = n_value;
	
	if(n_value == 0){switchLinkAppear(1,this.n_id);}
	else if(n_value == 50){switchLinkAppear(2,this.n_id);}
	else if(n_value == 100){switchLinkAppear(3,this.n_id);}	
}

// get absolute position of the element in the document
function f_sliderGetPos (b_vertical, b_base) {
	var n_pos = 0,
		s_coord = (b_vertical ? 'Top' : 'Left');
	var o_elem = o_elem2 = b_base ? this.e_base : this.e_slider;
	
	while (o_elem) {
		n_pos += o_elem["offset" + s_coord];
		o_elem = o_elem.offsetParent;
	}
	o_elem = o_elem2;

	var n_offset;
	while (o_elem.tagName != "BODY") {
		n_offset = o_elem["scroll" + s_coord];
		if (n_offset)
			n_pos -= o_elem["scroll" + s_coord];
		o_elem = o_elem.parentNode;
	}
	return n_pos;
}

function f_sliderMouseDown (n_id) {
	window.n_activeSliderId = n_id;

		//var o_slider = window.A_SLIDERS[window.n_activeSliderId];
		
		//o_slider.f_setValue(o_slider.n_minValue + (parseInt(o_slider.e_slider.style.left) - o_slider.n_pathLeft) / o_slider.n_pix2value);
	return false;
}

function f_sliderMouseUp (e_event, b_watching) {
	if (window.n_activeSliderId != null) {
		var o_slider = window.A_SLIDERS[window.n_activeSliderId];
		//document.write(parseInt(o_slider.e_slider.style.left) - o_slider.n_pathLeft));
		var temp_n_value = o_slider.n_minValue + (parseInt(o_slider.e_slider.style.left) - o_slider.n_pathLeft) / o_slider.n_pix2value;
		o_slider.f_setValue(temp_n_value);
		
		if(o_slider.sections == 3){
		    if(temp_n_value>=0 && temp_n_value<=25)o_slider.f_setValue(0);
		    else if(temp_n_value>25 && temp_n_value<=50)o_slider.f_setValue(50);
		    else if(temp_n_value>50 && temp_n_value<=75)o_slider.f_setValue(50);
		    else o_slider.f_setValue(100);
		}
		/*
		if(o_slider.sections == 4){
		    if(temp_n_value>=0 && temp_n_value<=16)o_slider.f_setValue(0);
		    else if(temp_n_value>16 && temp_n_value<=33)o_slider.f_setValue(33);
		    else if(temp_n_value>33 && temp_n_value<=49)o_slider.f_setValue(33);
		    else if(temp_n_value>49 && temp_n_value<=66)o_slider.f_setValue(66);
		    else if(temp_n_value>66 && temp_n_value<=82)o_slider.f_setValue(66);
		    else o_slider.f_setValue(100);
		}*/
		//if (b_watching)	return;
		window.n_activeSliderId = null;
	}
	if (window.f_savedMouseUp)
		return window.f_savedMouseUp(e_event);
		/*		
	    checkAllThrough();
        if(checkHowManyActive()==3)turnOffOthers();
        */
	
}
/*
function checkAllThroughReverse(){   
            if(window.A_SLIDERS[n_activeSliderId].n_value==0)window.countNumber--;  
}

function turnOnOthers(){
     for(var i=0;i<window.A_SLIDERS.length;i++){            
        window.A_SLIDERS[i].e_slider.onmousedown = window.A_SLIDERS[i].tempOnMouseDown;
        setOpacity(get_element("sl"+i+"base"),100);
    }
}

function checkAllThrough(){  
         //if(window.countNumber==3)turnOffOthers();
 
         for(var i=0;i<window.A_SLIDERS.length;i++){
            if(window.A_SLIDERS[i].n_value>0){
               window.A_SLIDERS[i].active = true;
                }
            }          
              
         
        /*if(window.countNumber >= 3){
             if(temp_n_value==0){
                    //checkAllThroughReverse();
                    window.countNumber--;
                    turnOnOthers();
                }
            }
      
}
function checkHowManyActive(){
    for(var i=0;i<window.A_SLIDERS.length;i++){
            if(window.A_SLIDERS[i].active == true){
               countNumber++;
                }            
         }
    return countNumber;   
}
function turnOffOthers(){
    for(var i=0;i<window.A_SLIDERS.length;i++){
        window.A_SLIDERS[i].tempOnMouseDown = window.A_SLIDERS[i].e_slider.onmousedown;
        if(window.A_SLIDERS[i].active==false){            
            window.A_SLIDERS[i].e_slider.onmousedown = null;
            setOpacity(get_element("sl"+i+"base"),50);
        }
    }
}
*/
function f_sliderMouseMove (e_event) {

	if (!e_event && window.event) e_event = window.event;

	// save mouse coordinates
	if (e_event) {
		window.n_mouseX = e_event.clientX + f_scrollLeft();
		window.n_mouseY = e_event.clientY + f_scrollTop();
	}

	// check if in drag mode
	if (window.n_activeSliderId != null) {
		var o_slider = window.A_SLIDERS[window.n_activeSliderId];

		var n_pxOffset;
		
			var n_sliderLeft = window.n_mouseX - o_slider.n_sliderWidth / 2 - o_slider.f_getPos(0, 1) - 3;
			// limit the slider movement
			if (n_sliderLeft < o_slider.n_pathLeft)
				n_sliderLeft = o_slider.n_pathLeft;
			var n_pxMax = o_slider.n_pathLeft + o_slider.n_pathLength;
			if (n_sliderLeft > n_pxMax)
				n_sliderLeft = n_pxMax;
			o_slider.e_slider.style.left = n_sliderLeft + 'px';
			o_slider.e_redBG.style.width=(o_slider.n_minValue+(n_sliderLeft-o_slider.n_pathLeft)/o_slider.n_pix2value)*o_slider.n_pix2value+10+'px';
			n_pxOffset = n_sliderLeft - o_slider.n_pathLeft;
			
		if (o_slider.b_watch)
			 f_sliderMouseUp(e_event, 1);

		return false;
	}
	
	if (window.f_savedMouseMove)
		return window.f_savedMouseMove(e_event);
}

// get the scroller positions of the page
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function checkSelected(){
    var checkFlag = false;   
    for(var i=0;i<A_SLIDERS.length;i++){
        if(A_SLIDERS[i].n_value != 0)checkFlag = true;
    }
    if(checkFlag == false)window.alert("You didn't select anything. We need to understand your investment considerations before we can help you get started.");
    return checkFlag;
}
/*
function setOpacity( elem, level ) {
    if ( elem.filters )
    elem.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + level + ')';
    else
    elem.style.opacity = level / 100;
}*/


