//document.body.onload = InitPage;


function InitPage()
{
    try
    {
        InitPageHandler();
    }
    catch(e)
    {}
    
    var submitButton = document.getElementById("Editor_SubmitButton")
    if (submitButton != null)
        submitButton.onclick = Editor_SubmitButton_Clicked;
    
    var saveButton = document.getElementById("Editor_SaveButton")
    if (saveButton != null)
        saveButton.onclick = Editor_SaveButton_Clicked;

    var clearButton = document.getElementById("Editor_ClearButton")
    if (clearButton != null)
        clearButton.onclick = Editor_ClearButton_Clicked;

    var deleteButton = document.getElementById("Editor_DeleteButton")
    if (deleteButton != null)
        deleteButton.onclick = Editor_DeleteButton_Clicked;

    var searchButton = document.getElementById("Editor_SearchButton")
    if (searchButton != null)
        searchButton.onclick = Editor_SearchButton_Clicked;

}

function Editor_SubmitButton_Clicked()
{
    
    var action = document.getElementById("hidFormAction");
    action.value = "Editor_Submit";
    
    
    alert ("Action clicked =" + action.value);
    document.forms[0].submit();
}
function Editor_SaveButton_Clicked()
{
    
    var action = document.getElementById("hidFormAction");
    action.value = "Editor_Save";
    alert ("Action clicked =" + action.value);
    document.forms[0].submit();
}
function Editor_ClearButton_Clicked()
{
    
    var action = document.getElementById("hidFormAction");
    action.value = "Editor_Clear";
    alert ("Action clicked =" + action.value);
    document.forms[0].submit();
}
function Editor_DeleteButton_Clicked()
{
    
    var action = document.getElementById("hidFormAction");
    action.value = "Editor_Delete";
    alert ("Action clicked =" + action.value);
    document.forms[0].submit();
}
function Editor_SearchButton_Clicked()
{
    
    var action = document.getElementById("hidFormAction");
    action.value = "Editor_Search";
    alert ("Action clicked =" + action.value);
    document.forms[0].submit();
}



var browserName=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

 // Browser class
function Browser()
{
	if ( parseInt( navigator.appVersion.charAt(0) ) >= 4 )
    // Browser check.
    {
	    this.isDOM = document.getElementById ? true : false ;
        this.isNav6 = (navigator.appName == "Netscape") ? true : false ;
        this.isNav4 = (navigator.appName == "Netscape" && !(this.isDOM)) ? true : false ;
        this.isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false ;
    }
}
var browser = new Browser();
        
        
function ShowPopupMenu(p_control)
{
    //window.status ="show";
    //alert (p_token)
    divAction = document.getElementById(p_control);
    
//     divAction.innerHTML = "<a  class='ContactActionLink' href='http://www.yahoo.com' onmouseover=ShowActions('" + p_token + "') onmouseout=HideActions('" + p_token + "')> test2</a>";
//     divAction.innerHTML += "<br><a  class='ContactActionLink' href='http://www.yahoo.com' onmouseover=ShowActions('" + p_token + "') onmouseout=HideActions('" + p_token + "')> test3</a>";
    //alert (divAction.innerHTML)
    divAction.style.display = "block";
    
    
}

function HidePopupMenu(p_control)
{
    //window.status = "hide";
    divAction = document.getElementById(p_control);
    //alert (divAction.style.left)
    //divAction.innerHTML = "<a  class='ContactActionLink' href='http://www.yahoo.com'> test2</a>";
    //alert (divAction.innerHTML)
    divAction.style.display = "none";
    
    
}

//function ClosePopupWindow()
//{
//    try
//    {
//        
//        parent.EmailThis_HideFrame();
//        
//    }
//    catch(e)
//    {
//        window.close();
//    }
//}



function Subscribe()
{
    window.open("/Page/Subscription.aspx" ,"Subscription","height=400,width=500,left=400,top=250, scrollbars=no resizable=yes toolbar=no location=no")

}
function EmailThis(p_token)
{
    window.open("/Page/EmailPosting.aspx?xc=" + p_token ,"EmailThis","height=400,width=500,left=400,top=250, scrollbars=no resizable=yes toolbar=no location=no")

}

//var subscriptionControl = null;
//var emailPostingControl = null;
var popupControl = null;
var popupFrame = null;
var popupFrameUrl = null;

window.document.onclick=handleDocumentClick;

function handleDocumentClick()
{
//    if (subscriptionControl != null)
//        SubscriptionControl_HideFrame();
//        
//    if (emailPostingControl != null)
//        EmailPostingControl_HideFrame();
        
    if (popupControl != null)
        PopupControl_HideFrame(popupControl);    
}


function GetCenterPosition(p_width, p_height)
{
    var w;
     var l = document.documentElement.scrollLeft;
    if(document.innerWidth)
    { w=document.innerWidth;
    } else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
    } else if(document.body){ w=document.body.clientWidth; }
    w = l + (( w - p_width) /2) ;
    w = w < 0 ? 0 : w;
    
     var t = document.documentElement.scrollTop;
     var h;
    if(document.innerHeight){ h=document.innerHeight;
    } else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
    } else if(document.body){ h=document.body.clientHeight; }
    h = t + (( h - p_height) /2) ;
    h = h < 0 ? 0 : h;
    
    return {left: w, top: h };
}

function PopupControl_Show(p_controlId, p_width, p_height)
{
    popupControl = document.getElementById (p_controlId + "Div" );
    popupFrameId = eval(p_controlId + "_FrameId");
    popupFrameUrl = eval(p_controlId + "_Url");
    
    
    //alert (popupFrameUrl);
    popupFrame = document.getElementById (popupFrameId);
    
    if (popupControl.style.display != "block")
    {
        
        popupControl.style.display = "block";
        
        var wSize = GetCenterPosition(p_width, p_height);
       
        popupControl.style.left = wSize.left;       
        popupControl.style.top = wSize.top;        
     
    }
   
}

function PopupControl_HideFrame()
{
    if (popupControl != null)
    {
        popupFrame.src = "";
        popupFrame.src = popupFrameUrl;
        popupControl.style.display = "none";
        popupControl = null
     }
}

function ClosePopupWindow()
{
    try
    {
        parent.PopupControl_HideFrame()
        
    }
    catch(e)
    {
        window.close();
    }
}

function OpenPage(p_url)
{
    if (parent != null)
    {
    alert (parent)
        parent.location.href=p_url;
    }
    else
        location.href =p_url;
}

function FindObjectPosition(obj)
{
	var curleft = curtop = 0;
//If the browser supports offsetParent we proceed.

	if (obj.offsetParent) {
//Every time we find a new object, we add its offsetLeft and offsetTop to curleft and curtop.

	    do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
//The tricky bit: return value of the = operator
//Now we get to the tricky bit:

		} while (obj = obj.offsetParent);
    }
return [curleft, curtop];

}


function ContentNavigation(p_top, p_url)
{
    if (p_top == 1)
        top.location.href = p_url;
    if (p_top == 2)
        window.open(p_url,"new" )
    else
        location.href = p_url;

}

function GoCustomize(p_url)
{
//alert ('test')
    newWin = open(p_url, 'Customize', "height=600,width=800,left=200,top=100, scrollbars=yes resizable=yes toolbar=no location=no");
    newWin.focus();
}



function CleanScript(p_code)
{
    while (p_code.indexOf("&apos;") != -1)
    {
        p_code = p_code.replace("&apos;", "'");
    }
    while (p_code.indexOf("&quot;") != -1)
    {
        p_code = p_code.replace("&quot;", "\"");
    }
    while (p_code.indexOf("<br>") != -1)
    {
        p_code = p_code.replace("<br>", "\r\n");
    }
    return p_code;
}