function checkEnter(e, caller) //e is event object passed from function invocation
{
    var characterCode //literal character code will be stored in this variable

    if (e && e.which || e.which == 0) { //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
    {
		if(caller == 'imgRightSearch'){
			 SubmitSearchRight(document.getElementById('qRight').value,'Enter your search here','^([a-zA-Z0-9 \?!-]+)');	
		}
		else{
			SubmitSearch(document.getElementById('q').value, 'Enter your search here', '^([a-zA-Z0-9 \?!-]+)');	
		}		
        return false;
    }
    else {
        return true;
    }
}
var currentPath = location.pathname;
var pathLength = currentPath.split('/').length;
var pathToSearch = '/help/search?q=';

if (currentPath.match('public')){
    pathLength=pathLength-2;

switch (pathLength){
    case 2:
        pathToSearch = '/help/search?q='
        break;
    case 3:
        pathToSearch = '../help/search?q='
        break;
    case 4:
        pathToSearch = '../../help/search?q='
        break;
    default:
       pathToSearch = 'help/search?q='
}
   }
function SubmitSearch(searchWords, text, regEx) {
    if (searchWords == text || searchWords.length == 0) {
        document.getElementById("NoValidSearchTextLabel").style.display = "none";
        document.getElementById("NoSearchTextLabel").style.display = "inline";
    }
    else
        if (searchWords.toString().match(regEx)) {
        //location.href="/Search.aspx?cx=006471719688142198866%3Aihmg_8q2czc&cof=FORID%3A11%3BNB%3A1&q=" + encodeURI(searchWords)+"&sa.x=7&sa.y=1&sa=submitname";
			_gaq.push(['_trackEvent','faqSearchUsed','S:'+document.getElementById('q').value]);
			searchWords = searchWords.toLowerCase();
			location.href = pathToSearch + encodeURIComponent(searchWords);
        return false;
    }
    else {
        document.getElementById("NoSearchTextLabel").style.display = "none";
        document.getElementById("NoValidSearchTextLabel").style.display = "inline";
    }
}

function SubmitSearchRight(searchWords, text, regEx) {
    if (searchWords == text || searchWords.length == 0) {
        document.getElementById("NoValidRightSearchTextLabel").style.display = "none";
        document.getElementById("NoSearchRightTextLabel").style.display = "inline";
    }
    else
        if (searchWords.toString().match(regEx)) {
        //location.href="/Search.aspx?cx=006471719688142198866%3Aihmg_8q2czc&cof=FORID%3A11%3BNB%3A1&q=" + encodeURI(searchWords)+"&sa.x=7&sa.y=1&sa=submitname";
	searchWords = searchWords.toLowerCase();
            location.href = pathToSearch + encodeURIComponent(searchWords);
        return false;
    }
    else {
        document.getElementById("NoSearchRightTextLabel").style.display = "none";
        document.getElementById("NoValidRightSearchTextLabel").style.display = "inline";
    }
}

function onSubmit(value) {
    try {
        document.getElementById("faqbuttons").style.display = "inline";
        document.getElementById("hIsPostback").value = value;
        document.mainform.method = "post";
        document.mainform.submit();
    } catch (e) {
        alert(e)
    }
}

var pixelspeed = 0, refreshspeed = 10; //refreshspeed = x ms
var offOpacity = 0, refreshspeed2 = 5; //refreshspeed2 = increment of opacity
var ot = new Array();
var currentO = new Array();




function changeOpacity(element, varNo, startO, endO, speed, imageLoad, srcElement) {
    if (currentO[varNo] != endO) {
        if (currentO[varNo] == -1) currentO[varNo] = startO;
        if (startO < endO) {
            currentO[varNo] += speed;
            if (currentO[varNo] > endO) currentO[varNo] = endO;
        }
        else {
            currentO[varNo] -= speed;
            if (currentO[varNo] < endO) currentO[varNo] = endO;
        }
        if (document.all) {//IE
            document.getElementById(element).style.filter = "alpha(opacity=" + currentO[varNo] + ")";
        }
        else {//mozilla
            document.getElementById(element).style.opacity = currentO[varNo] / 100;
        }
        if (currentO[varNo] != endO) {
            ot[varNo] = setTimeout("changeOpacity('" + element + "', '" + varNo + "', " + startO + ", " + endO + ", " + speed + ", '" + imageLoad + "', '" + srcElement + "')", refreshspeed);
        }
        else {
            if (currentO[varNo] <= 0) document.getElementById(element).style.display = 'none';
            currentO[varNo] = -1;
        }
    }
}

function checkEnter(e, caller) //e is event object passed from function invocation
{
    var characterCode //literal character code will be stored in this variable

    if (e && e.which || e.which == 0) { //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
    {
		if(caller == 'imgRightSearch'){
			 SubmitSearchRight(document.getElementById('qRight').value,'Enter your search here','^([a-zA-Z0-9 \?!-]+)');	
		}
		else{
			SubmitSearch(document.getElementById('q').value, 'Enter your search here', '^([a-zA-Z0-9 \?!-]+)');	
		}		
        return false;
    }
    else {
        return true;
    }
}
var currentPath = location.pathname;
var pathLength = currentPath.split('/').length;
var pathToSearch = '/help/search?q=';

if (currentPath.match('public')){
    pathLength=pathLength-2;

switch (pathLength){
    case 2:
        pathToSearch = '/help/search?q='
        break;
    case 3:
        pathToSearch = '../help/search?q='
        break;
    case 4:
        pathToSearch = '../../help/search?q='
        break;
    default:
       pathToSearch = 'help/search?q='
}
   }
function SubmitSearch(searchWords, text, regEx) {
    if (searchWords == text || searchWords.length == 0) {
        document.getElementById("NoValidSearchTextLabel").style.display = "none";
        document.getElementById("NoSearchTextLabel").style.display = "inline";
    }
    else
        if (searchWords.toString().match(regEx)) {
        //location.href="/Search.aspx?cx=006471719688142198866%3Aihmg_8q2czc&cof=FORID%3A11%3BNB%3A1&q=" + encodeURI(searchWords)+"&sa.x=7&sa.y=1&sa=submitname";
			_gaq.push(['_trackEvent','faqSearchUsed','S:'+document.getElementById('q').value]);
			searchWords = searchWords.toLowerCase();
			location.href = pathToSearch + encodeURIComponent(searchWords);
        return false;
    }
    else {
        document.getElementById("NoSearchTextLabel").style.display = "none";
        document.getElementById("NoValidSearchTextLabel").style.display = "inline";
    }
}

function SubmitSearchRight(searchWords, text, regEx) {
    if (searchWords == text || searchWords.length == 0) {
        document.getElementById("NoValidRightSearchTextLabel").style.display = "none";
        document.getElementById("NoSearchRightTextLabel").style.display = "inline";
    }
    else
        if (searchWords.toString().match(regEx)) {
        //location.href="/Search.aspx?cx=006471719688142198866%3Aihmg_8q2czc&cof=FORID%3A11%3BNB%3A1&q=" + encodeURI(searchWords)+"&sa.x=7&sa.y=1&sa=submitname";
	searchWords = searchWords.toLowerCase();
            location.href = pathToSearch + encodeURIComponent(searchWords);
        return false;
    }
    else {
        document.getElementById("NoSearchRightTextLabel").style.display = "none";
        document.getElementById("NoValidRightSearchTextLabel").style.display = "inline";
    }
}

function onSubmit(value) {
    try {
        document.getElementById("faqbuttons").style.display = "inline";
        document.getElementById("hIsPostback").value = value;
        document.mainform.method = "post";
        document.mainform.submit();
    } catch (e) {
        alert(e)
    }
}

var pixelspeed = 0, refreshspeed = 10; //refreshspeed = x ms
var offOpacity = 0, refreshspeed2 = 5; //refreshspeed2 = increment of opacity
var ot = new Array();
var currentO = new Array();




function changeOpacity(element, varNo, startO, endO, speed, imageLoad, srcElement) {
    if (currentO[varNo] != endO) {
        if (currentO[varNo] == -1) currentO[varNo] = startO;
        if (startO < endO) {
            currentO[varNo] += speed;
            if (currentO[varNo] > endO) currentO[varNo] = endO;
        }
        else {
            currentO[varNo] -= speed;
            if (currentO[varNo] < endO) currentO[varNo] = endO;
        }
        if (document.all) {//IE
            document.getElementById(element).style.filter = "alpha(opacity=" + currentO[varNo] + ")";
        }
        else {//mozilla
            document.getElementById(element).style.opacity = currentO[varNo] / 100;
        }
        if (currentO[varNo] != endO) {
            ot[varNo] = setTimeout("changeOpacity('" + element + "', '" + varNo + "', " + startO + ", " + endO + ", " + speed + ", '" + imageLoad + "', '" + srcElement + "')", refreshspeed);
        }
        else {
            if (currentO[varNo] <= 0) document.getElementById(element).style.display = 'none';
            currentO[varNo] = -1;
        }
    }
}

(function($){
	$(document).ready(function(){
		$('.js-form').each(function(){
			var $form = $(this);
			$form.find('input[type=text], input[type=button], input[type=image]').keyup(function(e){
				if(e.which === 13){ //enter key
					$form.find('input[type=submit]').click();
				}
			});
		});
	});
})(jQuery);

