// NewsworthyAudioC2L.js source code
//©Copyright 2006 Newsworthy, Inc. All Rights Reserved

var x=new String(Math.random());
var m_oC2LWindow=null;    // Reference to the window's object
var m_iRefCount=0;        // Refernece counter (Guarantees that no infinte recursion occurs)
/*For Gr1 displaying page, set value to 585; else height=205*/
/*
//WashingtonTimes
var m_sC2LWindowFeatures='location=0,menubar=0,status=0,width=525,height=665';
*/

//COX
var m_sC2LWindowFeatures='location=0,menubar=0,status=0,width=525,height=665';
//var m_sC2LWindowFeatures='location=0,menubar=0,status=0';
var m_sC2LWindowName='_blank';
 



//All parameters except for UserName, Environment, and Debug are required
function OpenC2LWindow(PartnerKey,ArticleGUID,ArticleURL,PartnerSpecificParam,SiteKey,UserName,Environment,Debug)
{
    try
    {    
        var sUrl="";
        sUrl +="C2lPlayer.aspx?PartnerKey=" + PartnerKey;
        sUrl +="&SiteKey=" + SiteKey;
        sUrl +="&ArticleGUID=" + ArticleGUID;
        sUrl +="&ArticleURL=" + ArticleURL;
        sUrl +="&PartnerSpecificParam=" + PartnerSpecificParam;
        sUrl +="&UserName=" + typeof(UserName)=="string"?UserName:"";
        sUrl="C2lPlayer.aspx?PartnerKey=COXNewspapers&SiteKey=sharedoh&ArticleGUID=sharedoh_oh_story_news_local_2007_05_17_ddn051707dplweb&ArticleURL=http://alt.coxnewsweb.com/cnishared/newsworthy/sharedoh//oh/story/news/local/2007/05/17//sharedoh_oh_story_news_local_2007_05_17_ddn051707dplweb.mp3&PartnerSpecificParam=AdUrl=http://ad.doubleclick.net/adj/ddn.cni/$PAGE%23ap%40click2listen%23pg%40$PAGE%23sub%40$SUB%23fromsite%40sharedoh%23";
        //If this window was launched before, kill it first
        if (m_oC2LWindow!=null)
        {
            if (!m_oC2LWindow.closed) 
                m_oC2LWindow.close();
            m_iRefCount=0;        // Reset counter
            m_oC2LWindow=null;
        }
 
        m_iRefCount++;    // increment counter
	
//alert(sUrl);
window.open(sUrl, m_sC2LWindowName, m_sC2LWindowFeatures);
//        m_oC2LWindow = window.open(sUrl, m_sC2LWindowName, m_sC2LWindowFeatures);
  //      m_oC2LWindow.focus();
    }
    catch(e)
    {
    
        //m_iRefCount<2 conditions makes sure that the recursive call occurs only once
        //if it was invoked once and the same exception is raised, the function will display 
        //an alert box with the error number and message.
        if ((e.number==-2147418094||e.number==-2147024891) && m_iRefCount<2)
        {
            /*
                Error number -2147418094 has the following massage associated with it...
                The callee (server [not server application]) is not available and disappeared; 
                all connections are invalid. The call did not execute.                
                ... which means that the client has closed the browser whose reference is stored in the 
                oC2LWindow object.
                
                Error number -2147024891 has this message
                Access is denied.
                                
                Set the oC2LWindow object to null and try again one more time.
             */
             oC2LWindow=null;
             OpenC2LWindow(PartnerKey,ArticleGUID,ArticleURL,PartnerSpecificParam,UserName,Environment,Debug);
        }
        else
            alert("Failed to execute OpenC2LWindow()\n\n"+ e.number+ "\n" + e.message);
    }
    
}