// Utility scipts for the support center
// Changelog
// mharen - 3/6/09 - removed absolute links for product pages in the data section
// mharen - 3/6/09 - added cheesy browser detection script to block chanined selects from setting cookies which were cratering safari 3.2.1 over Akamai. Bad browser. No soup for you.
// breece - 3/9/09 - added SRX 3400/3600
// breece - 04/20/09 - added EX2500.  Mmmm, soup.
// breece - 5/28/09 - added SRX210

// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

var _disable_empty_list=false;
var _hide_empty_list=false;

// ------



// Drop-in content box- By Dynamic Drive
// For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
// This credit MUST stay intact for use

//Specify rate of display (1/freq)
var freq=1 /*frequency of dropin*/
var heightFromTop=20  /*height from top of window*/

//var random_num=Math.floor(Math.random()*freq)
//if (random_num==0)
//initbox();
var ie=document.all
var dom=document.getElementById
var ns4=document.layers
var calunits=document.layers? "" : "px"


var bouncelimit=16 //(must be divisible by 8)
var direction="up"

function initbox(){
            if('N' == 'Y'){
                        if (!dom&&!ie&&!ns4)
                        return
                        crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
                        scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
                        crossobj.top=scroll_top-250+calunits
                        crossobj.visibility=(dom||ie)? "visible" : "show"
                        dropstart=setInterval("dropin()",50)
            }
}

function dropin(){
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
if (parseInt(crossobj.top)<heightFromTop+scroll_top)  
crossobj.top=parseInt(crossobj.top)+40+calunits
else{
clearInterval(dropstart)
bouncestart=setInterval("bouncein()",50)
}
}

function bouncein(){
crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
if (bouncelimit<0)
bouncelimit+=8
bouncelimit=bouncelimit*-1
if (bouncelimit==0){
clearInterval(bouncestart)
}
}

function dismissbox(){
if (window.bouncestart) clearInterval(bouncestart)
crossobj.visibility="hidden"
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}




function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}

function surveyCheck(){
            if(queryString('surveyrequest') != null){
                        if(queryString('surveyrequest') == 'Y'){
                                    return 'Y';
                        }else{
                                    return 'N';
                        }
            }else{
                        return 'N';
            }
}

function submitSurveyRequest(form, answer){
            form.surveyanswer.value = answer;
            form.submit();
}

// KB submission box
// 031309 - MH - removed from Product pages and added to this script


var qna_submitOK       = true;
//var qna_browser        = new Browser();

function escapeVal(textarea,replaceWith){
textarea.value=escape(textarea.value)
for(i=0; i<textarea.value.length; i++){
 	if(textarea.value.indexOf("%0D%0A") > -1){
	textarea.value=textarea.value.replace("%0D%0A",replaceWith)
	}
	else if(textarea.value.indexOf("%0A") > -1){
	textarea.value=textarea.value.replace("%0A",replaceWith)
	}
	else if(textarea.value.indexOf("%0D") > -1){
	textarea.value=textarea.value.replace("%0D",replaceWith)
	}
}
textarea.value=unescape(textarea.value)
}


function submitQuestion()
{
    // Submit the question
if (!isSubmitOK())
    {
        return false;
    }
  
  disableSubmit();
    document.question_form.submit();

    // Wait 10 seconds before submit available
    setTimeout("enableSubmit();", 10000);
   
 return false;

}

function isSubmitOK()
{
    var form= top.document.question_form;
    var searchstrng=form.facet.value;
    var question = form.question_box.value;
   
  if (!qna_submitOK)
        return false;
    // Trim any whitespace from question
    question = question.replace(/^\s+/,'');
    question = question.replace(/\s+$/,'');
    // Don't submit a blank query
    if (question == "")
    {
        document.question_form.question_box.value = "";
        document.question_form.question_box.focus();

        return false;
    }
 escapeVal(document.question_form.question_box,"");   
form.action= 'http://kb.juniper.net/?ui_mode=question&question_box='+question+'&facet='+searchstrng;

    return true;
}
  
function disableSubmit()
{
    qna_submitOK = false;
    document.question_form.Ask.disabled = true;

}

function enableSubmit()
{
    qna_submitOK = true;
    document.question_form.Ask.disabled = false;

}
if (window.onload == null)
    window.onload = handleOnLoad;
	
	
	
	
// new  script for cascading dropdowns - mth 09/16/09	
	
	
function applyCascadingDropdown(sourceId, targetId) {
var source = document.getElementById(sourceId);
var target = document.getElementById(targetId);
	if (source && target) {
// if cookie exists
// {
// read cookie and load values into variables
// displayOptionItemsByClass(target, source.value);
// } else { 		
		source.onchange = function() {
		target.disabled=false;
		displayOptionItemsByClass(target, source.value);
		}
//	not needed but in original script:	displayOptionItemsByClass(target, source.value);
//	not needed but in original script:	target.disabled=false;
//    } end else
	}
}

function displayOptionItemsByClass(selectElement, className) {
	if (!selectElement.backup) {
		selectElement.backup = selectElement.cloneNode(true);
	}
	var options = selectElement.getElementsByTagName("option");
	for(var i=0, length=options.length; i<length; i++) {
		selectElement.removeChild(options[0]);
	}
	var options = selectElement.backup.getElementsByTagName("option");
	for(var i=0, length=options.length; i<length; i++) {
		if (options[i].className==className)
			selectElement.appendChild(options[i].cloneNode(true));
	}
}

function applyCascadingDropdowns() {
	applyCascadingDropdown("series", "product");
}

window.onload=applyCascadingDropdowns;	

function openLink() {
  if (document.forms['sbp'].elements['product'].value != "") {
// set the cookie here  
    location.href = document.forms['sbp'].elements['product'].value;
  }
  else {
    alert("Select a series first, then a product, before clicking on OPEN");
  }
}

	
	
	
	
