﻿var postbackElement;

function beginRequest(sender, args) {
    postbackElement = args.get_postBackElement();   //document.body
}

function pageLoaded(sender, args) 
{
    if (postbackElement)
    {
        //scroll up to account for the large image not present when a user, currently on the home control, wants to see another control
        var ctrlId = postbackElement.id.substring(postbackElement.id.lastIndexOf('_')+1);
        
        if (ctrlId == 'lnkTopic' | ctrlId == 'imgCartoon' | ctrlId == 'lnkCartoon')
        {
            window.scrollTo(0,0); 
            blnFromHome = false;
        }
    }
} 


function HandleChangeBodyControl(strContent)
{
    if (window.location.href.toLowerCase().indexOf('/content.aspx') == - 1)
        document.location.href = 'content.aspx?cc=' + strContent;
    else
    {        
        if (parent.frm300x250 != undefined) parent.frm300x250.location.reload();
        document.location.href = 'content.aspx?cc=' + strContent;
        //CallSever(strContent, 'divContent');
    }
}

function HandleKeywordChange(SourceID, strValue, DestID, e, blnForce)
{
     if ((strValue.length > 0) & ((e.keyCode == 32) | (e.keyCode == 8) | (e.keyCode == 46) | (strValue.length == 50) | (blnForce == 1)))
        CallServer(SourceID + String.fromCharCode(20) + strValue, DestID);
}


function CallBackHandler(result, context)
{       
    var aryContext = context.split(String.fromCharCode(30));
    var aryResults = result.split(String.fromCharCode(30));
    var strControlID = aryContext[0];
          
    switch (strControlID)
    {
        case 'ctl00_cphRightRail_RightRail1_KeywordSearch1_lblMessage': 
            //keyword search in rightrail
            var txtCtrl = document.getElementById(strControlID);
            if (aryResults.length > 0)
                if (aryResults[0] != 'undefined') 
                {
                    txtCtrl.innerText = aryResults[0];
                    if (txtCtrl.innerText.substring(0,2) == '0 ')
                        txtCtrl.style.color = 'red';
                    else
                        txtCtrl.style.color = 'green';
                }
            else
                txtCtrl.value = '';
            
            break;
        case 'lblSearchMessage': 
            //admin keyword search
            var txtCtrl = document.getElementById(strControlID);
            if (aryResults.length > 0)
                if (aryResults[0] != 'undefined') 
                {
                    txtCtrl.innerText = aryResults[0];
                    if (txtCtrl.innerText.substring(0,2) == '0 ')
                        txtCtrl.style.color = 'red';
                    else
                        txtCtrl.style.color = 'green';
                }
            else
                txtCtrl.value = '';
            
            break;
//        case 'ctl00_cphMain_SearchResults1_EmailForm1_lblEmailMessage':
//            var lblCtrl = document.getElementById(strControlID);
//            lblCtrl.innerText = aryResults[0];
//            
////            if (aryResults[0] == 'Message Sent!')
////                lblCtrl.style.color = 'green';
////            else
////                lblCtrl.style.color = 'red';
//                
//            if (aryResults[0].indexOf('sending email...') > -1)
//            {
//                lblCtrl.style.color = 'green';
//                __doPostBack('btnSend',document.getElementById('hdnID').value);
//            }
//            else
//                lblCtrl.style.color = 'red';
//            
//            break;
        default:
            break;
    }
}

function CreateXmlReq()
{
	try
	{
		XmlReq = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlReq = null;
		}
	}
	if(!XmlReq && typeof XMLHttpRequest != "undefined") 
	{
		XmlReq = new XMLHttpRequest();
	}
}
  
function ErrorCallBack(result,context)
{
    alert("Error occurred : " + result);
}

//if (typeof(Sys) !== 'undefined') {
//  Sys.Application.notifyScriptLoaded();
//}
