function onOtherSiteChange(src,chkboxname)
{
	var chkboxctrl=document.getElementById(chkboxname);
	var inputctrl=document.getElementById(src);
	if(chkboxctrl&&inputctrl&&!chkboxctrl.mouseOver&&(!document.activeElement||document.activeElement.id!=chkboxctrl.id))
	{
		if(inputctrl.value&&inputctrl.value.length!=0)
		{
			chkboxctrl.checked=true;
		}
		else
		{
			chkboxctrl.checked=false;
		}
	}
}
function setCheckBoxProperty(chkboxname,propname,propvalue)
{
	var chkboxctrl=document.getElementById(chkboxname);
	if(chkboxctrl)
	{
		if(propname=='mouseOver')
		{
			chkboxctrl.mouseOver=propvalue;
		}
		else
		{
			chkboxctrl.checked=propvalue;
		}
	}
}
function setRadioButtom(src)
{
	var srcE=document.getElementById(src);
	if(srcE)
	{
		if(srcE.checked)
		{	
			var rb=document.getElementById('rdPreferredLangs');
			if(rb)
			{
				rb.checked=true;
			}
		}
		else
		{
			var inputs=document.getElementsByTagName("input");
			if(inputs)
			{
				var checked=false;
				for(i=0;i<inputs.length;++i)
				{
					if(inputs[i].id.substr(0, 7)=="chkLang")
					{
						if(inputs[i].checked)
						{
							checked=true;
							break;
						}
					}
				}
				if(!checked)
				{
					var rb=document.getElementById('rdAllLangs');
					if(rb)
					{
						rb.checked=true;
					}
				}
			}
		}
	}
}

function ShowAll()
{
	var el = document.getElementById("dwn_arrow");
	el.className = 'dwn_arrow';
}
function Show(divfilterid)
{
	var el = document.getElementById(divfilterid);
	if(el)
	    el.className = divfilterid;
}
function getTargetFromEvent(e)
{
	if (!e) var e = window.event;
	if (e.target) var tg = e.target;
	else if (e.srcElement) var tg = e.srcElement;
	tg = tg.parentNode;
	return tg;
}
var target;
var isWebSelected=false;
function SelectLink(e,divfilterid,inputhiddenid,cmCode,mkt)
{
	target=getTargetFromEvent(e);
	clearSelection(target.parentNode.childNodes);
	target.className = 'selected';
	var el = document.getElementById(divfilterid);
	var liarray=target.parentElement.getElementsByTagName('li');
	el.className = 'hide';
	if(liarray.length-1 == cmCode)
	{
        isWebSelected=true;
	    submitForm(inputhiddenid,cmCode,true,mkt,false);
	}
	else
	{
	    submitForm(inputhiddenid,cmCode,false,mkt,false);
	}
}
function clearSelection(childnodes)
{
	for(var i=0;i<childnodes.length;i++)
	{
		var node = childnodes[i];
		if(node && node.nodeName == 'LI')
		{
			node.className='';
		}
	}  
}
function Hide(divfilterid, element)
{

	var el = document.getElementById(divfilterid);
	if(el)
	    el.className = 'hide';
}
var strHref = window.location.href;
var qscpos=strHref.indexOf("qsc");
var qscval=0;
if (qscpos>-1)
{
    qscval=strHref.substring(qscpos+5,qscpos+6);
}
function createInputElement(formid,searchbutton,inputhiddenid)
{
    var qscname="qsc0";
    if (searchbutton!='Top')
    {
        qscname="qsc1";
    }
	var field = document.createElement("input");
	field.setAttribute("type","hidden");
    field.setAttribute("id",inputhiddenid);
	field.setAttribute("value",qscval)
	field.setAttribute("name",qscname);
	document.getElementById(formid).appendChild(field);
}
function setFocus(txtquery,isfocusrequired)
{
	var input=document.getElementById(txtquery);
	if(input)
	{
		if(isfocusrequired)
		{
			input.focus();
		}
		input.style.width = 8.5+'em';
		isRedirect=true;
	}
}
function showDropDown(lidropdown)
{
	
	var liclass=document.getElementById(lidropdown);
	if(liclass)
	{
		liclass.className = 'dwn_arrow_parent';
	}
}
function setSearchBoxFormCode1(cmCode,inputhiddenid)
{
	var input=getObjectById(inputhiddenid);
	if(input)
	{ 
		input.value=cmCode;
	}
}
window.onload = moveHeadingDiv;
function moveHeadingDiv()
{
    var sourcenode = getObjectById('headingid');
    var targetnode=getObjectById('searchresult');
    var sourcenode1 = getObjectById('didumean0');
    var targetnode1=getObjectById('didumean');
    if (sourcenode && sourcenode.innerHTML.length>0 && targetnode)
    {
        targetnode.innerHTML=sourcenode.innerHTML;
        sourcenode.parentNode.removeChild(sourcenode);
    }
    if (sourcenode1 && sourcenode1.innerHTML.length>0 && targetnode1)
    {
        targetnode1.innerHTML=sourcenode1.innerHTML;
        sourcenode1.parentNode.removeChild(sourcenode1);
    }
    registerClickEvent();
}
function getObjectById(elid)
{
	if (document.getElementById)
	{
		return document.getElementById(elid);
	}
	else if (document.all)
	{
		return document.all[elid];
	}
	else if (document.layers)
	{
		return document.layers[elid];
	}
}
function changeLinkHideShow()
{
	mkt2_start=document.cookie.indexOf('mkt2' + "=");
	mkt2_start=mkt2_start + 8;
	mkt2_end=document.cookie.indexOf(";",mkt2_start);
	cookie_mkt2=document.cookie.substring(mkt2_start,mkt2_end);
	mkt1_start=document.cookie.indexOf('mkt1' + "=");
	mkt1_start=mkt1_start + 10;
	mkt1_end=document.cookie.indexOf(";",mkt1_start);
	cookie_mkt1=document.cookie.substring(mkt1_start,mkt1_end);
	var mscomchangelinkid = getObjectById('mscom_changelinkid');
	
	if(mscomchangelinkid && cookie_mkt1==cookie_mkt2)
	{
		mscomchangelinkid.className = 'hide';
	}
	else
	{
		mscomchangelinkid.className = 'mscom_changelink';
	}

}
//Function to strip out < and > characters
function stripSymbols (rsltextbox) 
{
    var objrslttextbox = getObjectById(rsltextbox); 
    if (objrslttextbox)
    {
        var s = objrslttextbox.value;
        filteredValues = "<>"; // Characters to strip out
        var i;
        var returnString = "";
        for (i = 0; i < s.length; i++) 
        { 
            // Search through string and append to unfiltered values to returnString.
            var c = s.charAt(i);
            if (filteredValues.indexOf(c) == -1) 
            {
                returnString += c; 
            }
            else
            {
                returnString += " ";
            }
        } 
        objrslttextbox.value = returnString;
    }
}
//function to submit the form
function submitForm (inputhiddenid,cmCode,setFormActionToLive,mkt,allowNull) 
{
    //holds input hidden variable
    var objinputhidden=getObjectById(inputhiddenid);
    //holds form object
    var form;
    //holds result text box value
    var rsltextbox;
    //checks for the null value
    if (objinputhidden)
    {
        //gives the form object holding hidden field
        form=objinputhidden.form ;
    }
    //returns result text box object
    var objrsltextbox=getObjectsByTagAndId(form,'input','text');
    //checks for the null value
    if (objrsltextbox)
    {
        //trims spaces
        rsltextbox = trim(objrsltextbox.value,' ');
    }
    //checks for the null value
    if (rsltextbox && rsltextbox.length>0)
    {
        setSearchBoxFormCode1(cmCode,inputhiddenid)
        //if web option is selected in the drop down or web button is clicked and value of text box is not null
        //it will set action url to live.com
        if (setFormActionToLive)
        {
            var lform='';
            //if web button is clicked update form value with 'MSSBMN' and if web optionis selected 
            //in the drop down then update form value with 'BMME'
            if(allowNull)
                lform='MSSBMN';
            else
                lform='BMME';
            var url='http://search.live.com/results.aspx?mkt=' + mkt + '&q=' + encodeURIComponent(rsltextbox) + '&FORM=' + lform;
            isRedirect=true;
            setWindowLocation(url);
        }
        else
        {
            stripSymbols (objrsltextbox.id)
            //submits the form
            form.submit();
        }
    }
    //if web button is clicked and value of text box is null or spaces it will redirect to live.com
    else if (allowNull && ((rsltextbox && rsltextbox.length == 0) || !rsltextbox))
    {
        window.location.href='http://search.live.com/results.aspx?mkt=' + mkt + '&FORM=MSSBMN';
    }
}
//function to submit the no result form
function submitNoResultForm (txtNoRsltTextBoxId,mkt) 
{
    //returns result text box object
    var objrsltextbox=getObjectById(txtNoRsltTextBoxId);
    //holds form object
    var form;
    //holds result text box value
    var rsltextbox;
    //checks for the null value
    if (objrsltextbox)
    {
        //gives the form object holding hidden field
        form=objrsltextbox.form
    }
    //checks for the null value
    if (objrsltextbox)
    {
        //trims spaces
        rsltextbox = trim(objrsltextbox.value,' ');
    }
    //checks for the null value
    if (rsltextbox && rsltextbox.length>0)
    {   
        //if web button is clicked and value of text box is not null, it will set action url to live.com
        var url='http://search.live.com/results.aspx?mkt=' + mkt + '&q=' + encodeURIComponent(rsltextbox) + '&FORM=MSSBMN';
        isRedirect=true;
        setWindowLocation(url);
    }
    //if web button is clicked and value of text box is null or spaces it will redirect to live.com
    else if ((rsltextbox && rsltextbox.length == 0) || !rsltextbox)
    {
        window.location.href='http://search.live.com/results.aspx?mkt=' + mkt + '&FORM=MSSBMN';
    }
}
function getObjectsByTagAndId(node,tag,type)
{
	var array = node.getElementsByTagName(tag);
	var output=null;
	for(var i=0;i<array.length;i++)
	{
	    if(array[i].type==type)
		{
			output=array[i];
			return output;
		}
	}
	return output;
}
function getObjectsByTagTypeAndName(node,tag,type,name)
{
	var array = node.getElementsByTagName(tag);
	var output=null;
	for(var i=0;i<array.length;i++)
	{
	    if(array[i].type==type && array[i].name==name)
		{
			output=array[i];
			return output;
		}
	}
	return output;
}

//trims spaces
function trim(str, chars) {
    var trimmedstr;
    if (str)
    {
        chars = chars || "\\s";
        trimmedstr = str.replace(new RegExp("^[" + chars + "]+", "g"), "");
    }
    return trimmedstr;
}
//redirects to the live.com in case of no result after 3 seconds.
function redirectToLive(q,mkt)
{
    isRedirect=true;
    var redirecttime = 5000;
    var trimmedvalue = trim(q,' ');
    if (trimmedvalue && trimmedvalue.length>0)
    {
        var url='http://search.live.com/results.aspx?mkt=' + mkt + '&q=' + trimmedvalue + '&FORM=BMMENO';
        setTimeout("setWindowLocation('" + url + "')",redirecttime);
    }
}
function setWindowLocation(purl)
{
    if (isRedirect)
    {
        window.location.href=purl;
    }
}
function getTextBoxValue(inputhiddenid)
{
    //holds input hidden variable
    var objinputhidden=getObjectById(inputhiddenid);
    //holds form object
    var form;
    //holds result text box value
    var rsltextbox;
    //checks for the null value
    if (objinputhidden)
    {
        //gives the form object holding hidden field
        form=objinputhidden.form;
    }
    //returns result text box object
    var objrsltextbox=getObjectsByTagAndId(form,'input','text');
    //checks for the null value
    if (objrsltextbox)
    {
        rsltextbox = objrsltextbox.value;
    }
    return rsltextbox;
}
var isRedirect=true;
function cancelRedirection()
{
    isRedirect=false;
}
function _utf8_encode (string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

}

return utftext;
}
function registerClickEvent()
{
    var linkdiv;
    var linklist;
    var array = document.getElementsByTagName('div');
    for(var i=0;i<array.length;i++)
    {
        if(array[i].className=='tdNavigationLinks' || array[i].className=='mscom_abslnklst' || array[i].className=='mscom_changelink' || array[i].className=='spellsuggest')
	    {
		    linkddiv=array[i];
		    if (linkddiv)
            linklist=linkddiv.getElementsByTagName('a');
            if (linklist)
            {
                for(var j=0;j<linklist.length;j++)
                {
                    if(linklist[j].href.length>0)
	                {
		                linklist[j].onclick=cancelRedirection;
	                }
                }
            }
    		
        }
    }
}
function onFormSubmit(formid,searchbutton)
{
    var mkt=mktval;
    var output=true;
    //returns form object
    var form=getObjectById(formid);
    //checks for the null value
    var ul;
    if (form)
    {
        //return ul object
        if (searchbutton=='Top')
            ul = getObjectById('slScopeSelect0');
        else
            ul = getObjectById('slScopeSelect01');
            var liarray=0;
        if(ul)
            liarray=ul.getElementsByTagName('li');
        //if the web option is selected in the drop down it will set variable to false.
        if (liarray.length>0 && ul.childNodes[liarray.length-1].className=='selected')
        {
            output=false;
        }
    }
    //it will execute the below code only if web option is selected in the drop down.
    if (!output)
    {
        var objrsltextbox;
        var rsltextbox;
        //returns text box object.
        if (searchbutton=='Top')
            objrsltextbox=getObjectById('txtQuery0');
        else
            objrsltextbox=getObjectById('txtQuery1');
        //checks for the null value
        if (objrsltextbox)
        {
            //trims spaces
            rsltextbox = trim(objrsltextbox.value,' ');
        }
            //checks for the null value
        if (form && rsltextbox && rsltextbox.length>0)
        {
            var url='http://search.live.com/results.aspx?mkt=' + mkt + '&q=' + encodeURIComponent(rsltextbox) + '&FORM=BMME';
            isRedirect=true;
            setWindowLocation(url);
        }
    }
    return output;
}

function clickClear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickRecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
