var PageCallObj = {};
var accPVar = {
	temp:null,	
	time2Exec:true,
	currElemId:"",
	prevElemId:"",	
	overTime:"",
	call_delay:2000,
	approxLatency:1000,
	call_params:"",
	func:"",
	numeric:/^\d+$/,
	call_out_flag:"aco",
	priceFunctionId:"1",
	definitionFunctionId:"2",
	promoPopFunctionId:"3",
	planDetailsPopId:"4",
	acc_def_pop_container:"acc_def_pop_container",
	acc_price_pop_container:"acc_price_pop_container",
	acc_promo_pop:"acc_promo_details_container",
	acc_plan_details_pop:"acc_plan_details_pop",
	acc_price_pop:"acc_price_pop",
	acc_def_pop:"acc_def_pop",	
	pop_elem:"",
	statusObj:{},
	fixedElem:{},
	funcThread:{
		"t1":{"outTime":"","overTime":"","currentEvent":"","currentID":""},
		"t2":{"outTime":"","overTime":"","currentEvent":"","currentID":""},
		"t3":{"outTime":"","overTime":"","currentEvent":"","currentID":""},
		"t4":{"outTime":"","overTime":"","currentEvent":"","currentID":""}
	},
	currentEvent:null
}
function init_acc_pops(){
    var planId = "";
    var defName = "", popWindow = "";
    var x = 0;
    var func = "";
    var doc = document.getElementsByTagName("body")[0].getElementsByTagName("*");   
    var callDelay = 0;
    accPVar.currentElemIdByFunc = {};
    accPVar.fixedElem["f_"+accPVar.acc_def_pop_container]="";
    accPVar.fixedElem["f_"+accPVar.acc_price_pop]="";
    accPVar.fixedElem["f_"+accPVar.acc_promo_pop]="";
    accPVar.fixedElem["f_"+accPVar.acc_plan_details_pop]="";
    for (x = 0; x < doc.length; x++) {
        var subStr = null;
        callDelay = 0;
        func = "";
        try {
            subStr = doc[x].id + "";
        } 
        catch (err) {
        }
        if (null != subStr && subStr != "") {
            var wdSplit = subStr.split("_");
            if (wdSplit.length >= 2 && wdSplit[0] == accPVar.call_out_flag) {
            	try {
                    func = wdSplit[1]+ "";
                } 
                catch (err) {
                }
              
                subStr = subStr + "_" + x;
                doc[x].id = subStr;
                
                //Event.observe($(subStr), 'mouseout', cancelAccEvent.bindAsEventListener());
                Event.observe($(subStr), 'mouseover', handleAccHoverEvent.bindAsEventListener());
                
                if(func!=accPVar.planDetailsPopId){//exclude #4 from click event                	
                	document.getElementById(subStr).onclick = handleAccClickEvent;
                }
                
                if (accPVar.numeric.test(func) == true) {                 	
                    switch (func) {
                        case accPVar.priceFunctionId:
                            planId = wdSplit[2];
                            defName = "";
                            callDelay = 500;
                            popWindow = accPVar.acc_price_pop;
                            break;
                        case accPVar.definitionFunctionId:
                            defName = getDefKey("", subStr);
                            planId = "";
                            callDelay = 500;
                            popWindow = accPVar.acc_def_pop_container;
                            break;
                        case accPVar.promoPopFunctionId:
                            defName = wdSplit[3];
                            planId = wdSplit[2];
                            popWindow = accPVar.acc_promo_pop;
                            callDelay = 500;
                            break;
                        case accPVar.planDetailsPopId:
                        	defName = "";
                            planId = wdSplit[2];
                            popWindow = accPVar.acc_plan_details_pop;
                            callDelay = 500;
                            break;
                    }
                    PageCallObj[subStr] = {
                        type: func,
                        defName: defName,
                        planId: planId,
                        popWindow: popWindow,
                        innerHeader: "",
                        pageText: "",
                        elemWasClicked: false,
                        elemIsActive: false,
                        popIsActive: false,
                        lineItemSwitch: 1,
                        status:"",
                        event:null,
                        callDelay:callDelay,
                        timeout:null,
                        cancelAction:"",
                        time2Exec:false
                    };
                    
                }
            }
        }
    }
}

function getDefKey(autoElemId, actualElemId){//parses definition key from element ID		
    var defkey = "";
    var elemId = "";    
    try {
    	if (autoElemId != null && autoElemId != "") {
            var temp = autoElemId.split("_");
            autoElemId = autoElemId.substring(0, (autoElemId.length - ((temp[temp.length - 1].length) + 1)));
        }
        
        elemId = (actualElemId != null && actualElemId != "") ? actualElemId : autoElemId;
        
        var arr = elemId.split("_");
        if (arr.length > 2) {
            defkey = elemId.substring((arr[0].length + arr[1].length + 2), elemId.length);
        }
    } 
    catch (err) {
    
        return null;
    }
    
    return defkey;
}

function clearPrevious(){
    try {
        if (accPVar.prevElemId) {
            PageCallObj[accPVar.prevElemId].elemIsActive = false;
            PageCallObj[accPVar.prevElemId].elemWasClicked = false;
            PageCallObj[accPVar.prevElemId].popIsActive = false;           
        }
    } 
    catch (err) {
    }
}

function handleAccClickEvent(event){
	var handleMe = this;
	var fxdWin = ("f_"+PageCallObj[handleMe.id].popWindow);
	var thread = accPVar.funcThread[("t"+PageCallObj[handleMe.id].type)];	
	//if(accPVar.fixedElem[fxdWin]==""){
		accPVar.clicked = true;
	    clearTimeout(thread.outTime);
	    cancelAccEvent(thread.currentID);  
	    accPVar.prevElemId = accPVar.currElemId;
	    accPVar.currElemId = handleMe.id;	 
	    thread.currentID = handleMe.id;
	   // clearPrevious();   
	    PageCallObj[handleMe.id].elemIsActive = true;
	    PageCallObj[handleMe.id].elemWasClicked = true;	   
	    Event.stopObserving($(handleMe.id),"mouseout");
	    document.getElementById(PageCallObj[handleMe.id].popWindow).onmouseout = "";
	    document.getElementById(PageCallObj[handleMe.id].popWindow).onmouseover = "";    
	    execFunc(handleMe.id,event);
//	}
   return false;
}
function handleAccHoverEvent(event){	
	var handleMe = Event.element(event);	
	var currentID = (handleMe!=null && typeof handleMe.id=="string")?
			handleMe.id:(typeof event=="string" && event!="")?event:accPVar.currElemId;
	
    if(typeof currentID == "string" && typeof PageCallObj[currentID]!="undefined"){
		var fxdWin = ("f_"+PageCallObj[currentID].popWindow);    
	    var thread = accPVar.funcThread[("t"+PageCallObj[currentID].type)];   
	    
	    if (PageCallObj[currentID].elemWasClicked == false && accPVar.fixedElem[fxdWin]=="") {
	       if (PageCallObj[currentID].elemIsActive == false) {
	        	clearTimeout(thread.outTime);        	
	        	PageCallObj[currentID].time2Exec = true;
	            accPVar.prevElemId = accPVar.currElemId;
	            accPVar.currElemId = currentID;
	            thread.currentID = currentID;
	            accPVar.currentEvent = (!event)?window.event:event;
	           // clearPrevious();
	            PageCallObj[currentID].event = accPVar.currentEvent;
	            PageCallObj[currentID].elemIsActive = true;          
	           
	            var outFunc = function(e){	            	
	            	var args =  $A(arguments);	            	
	        		var id = args[1];	        		
	        		var threadCP = args[2];
	        		var thread = accPVar.funcThread[("t"+PageCallObj[id].type)];         		
	        	
	        		if(id == thread.currentID){	        		
		        		if(PageCallObj[id].elemIsActive){
		        			clearTimeout(threadCP.outTime);
		        		}
		        		if(!PageCallObj[id].elemWasClicked){
			            	cancelAccEvent(id);
			            	threadCP.outTime = setTimeout("if(PageCallObj[\""+id+"\"].elemIsActive!=true ){closePop(PageCallObj[\""+id+"\"].popWindow);}", 200);
		        		}
	        		}
	            }          
	            
	            Event.observe($(currentID), 'mouseout', outFunc.bindAsEventListener(this,currentID,thread));        
	            thread.overTime = setTimeout("(PageCallObj[\""+currentID+"\"].time2Exec==true)?execFunc(\""+currentID+ "\",accPVar.currentEvent):'';accPVar.currentEvent=null;", 
	            		((PageCallObj[currentID].callDelay>0)?PageCallObj[currentID].callDelay:(accPVar.call_delay - accPVar.approxLatency)));
	       }
	    }
    }
}
function cancelAccEvent(event){		
	//alert('cancel!');
	var handleMe = (typeof event =="object")?Event.element(event):null;
	var currentID = (handleMe!=null && typeof handleMe.id=="string")?
			handleMe.id:(typeof event=="string" && event!="")?event:accPVar.currElemId;
	if(typeof currentID=="string" && typeof PageCallObj[currentID]!="undefined"){
		var thread = accPVar.funcThread[("t"+PageCallObj[currentID].type)];
		var fxdWin = ("f_"+PageCallObj[currentID].popWindow);	
	    if (((currentID && PageCallObj[currentID]) &&
	    		accPVar.fixedElem[fxdWin]=="" &&
	    			(PageCallObj[currentID].elemIsActive == true || PageCallObj[currentID].popIsActive == true))
	    			 || (typeof event == "string" && event!="")) {
	    	      
	        PageCallObj[currentID].time2Exec = false;
	        PageCallObj[currentID].elemIsActive = false;
	        PageCallObj[currentID].popIsActive = false;
	        PageCallObj[currentID].elemWasClicked = false;
	        PageCallObj[currentID].event = null;
	        accPVar.currentEvent = null;
	     	clearTimeout(thread.overTime);
	     	thread.overTime = null;
	     	thread.currentID = "";
	        accPVar.clicked = false;
	        if(PageCallObj[currentID].cancelAction){        
	        	(PageCallObj[currentID].cancelAction)(currentID);
	        	PageCallObj[currentID].cancelAction = "";
	        }       
	    }    
	}
}

function execFunc(e_id,event){	
	var e = (typeof event!="undefined")?event:null;	
    switch (PageCallObj[e_id].type) {
        case accPVar.priceFunctionId:
        	accPVar.pop_elem = accPVar.acc_price_pop;
        	showPricingPop(e_id);// Price CallOut
            break;
        case accPVar.definitionFunctionId:
        	accPVar.pop_elem = accPVar.acc_def_pop;
            showDefCallOut(e_id); // Definition CallOut
            break;
        case accPVar.promoPopFunctionId:
        	accPVar.pop_elem = accPVar.acc_promo_pop;
            showPromoLayer(e_id);
            break;
        case accPVar.planDetailsPopId:
        	accPVar.pop_elem = accPVar.acc_promo_pop;        	
        	showPlanDetails(e,e_id);
        	break;
        default:
            break;
    }
}

function showDefCallOut(e_id){
	var currentID = e_id;	
    var defkey = getDefKey(currentID, null);
    var targetId = "pop_under_" + currentID;
    var displayTarget = $(target);
    
    var curleft = curtop = 0;
    var obj = $(currentID);
    var target = $(currentID);
    
    PageCallObj[currentID].popWindow = accPVar.acc_def_pop_container;
    
    if (PageCallObj[currentID].elemWasClicked == false) {
        document.getElementById(accPVar.acc_def_pop_container).onmouseover = function(){
        	clearTimeout(accPVar.funcThread[("t"+PageCallObj[currentID].type)].outTime);
			PageCallObj[currentID].popIsActive = true;		
        }
        document.getElementById(accPVar.acc_def_pop_container).onmouseout = function(){
        	PageCallObj[currentID].popIsActive = false;
        	accPVar.funcThread[("t"+PageCallObj[currentID].type)].outTime = setTimeout("closePop(accPVar.acc_def_pop_container)", 500);;
			
        }
    }
    else {
    	accPVar.fixedElem[("f_"+accPVar.acc_def_pop_container)] = currentID;
        document.getElementById(accPVar.acc_def_pop_container).onmouseover = "";
        document.getElementById(accPVar.acc_def_pop_container).onmouseout = "";
        
    }
    
    $(accPVar.acc_def_pop).onmouseover = function(){
        PageCallObj[currentID].elemIsActive = true;
        
    }
    $(accPVar.acc_def_pop).onmouseout = function(){
        PageCallObj[currentID].elemIsActive = false;
    }
    if (defkey != null && defkey != "") {
        $(accPVar.acc_def_pop).innerHTML = '<div class="acc_dp_body">' + '<div class="acc_def_pops_inner"><div class="acc_dp_header"><span id="dp_head_' + currentID + '" class="acc_dp_title"></span><img src="/01/img/activePops/acc_def_pop_close_x.png" width="14" height="14" style="float:right" onclick="closePop(\'' + accPVar.acc_def_pop_container + '\')"/></div><div class="acc_dp_content"><div id="dp_inner_' + currentID + '" class="acc_dp_content_inner"></div></div></div></div><div class="acc_db_bottom_cap"><img src="/01/img/activePops/acc_dp_tri_pointer.gif" width="20" height="10"/></div>';
        if (PageCallObj[currentID].pageText.isEmpty()) {
            sendRequestAndPopulate(defkey, accPVar.definitionFunctionId, currentID);
        }
        else {
            $("dp_head_" + currentID).innerHTML = PageCallObj[currentID].innerHeader;
            $("dp_inner_" + currentID).innerHTML = PageCallObj[currentID].pageText;
            posDefPop(obj);
        }
        
    }
    initCanvases();
}

function posDefPop(obj){
    var curleft = curtop = 0;
    var div = $(acc_def_pop);
    
    div.style.visibility = 'visible';
    div.style.display = 'block';
    div.style.position = 'absolute';
    $(accPVar.acc_def_pop_container).style.display = "block";   
    //Correctly Position DIV
    
    do {
        curleft += obj.offsetLeft;
        curtop += obj.offsetTop;
    }
    while (obj = obj.offsetParent);
    
    curtop = (curtop - parseInt($(acc_def_pop).getDimensions()["height"])) + 5;
    div.style.left = curleft - 170;
    div.style.top = curtop;
    div.style.top = curtop;
}

function showLineItems(e_id){
	var currentID = e_id;
    if (PageCallObj[currentID].lineItemSwitch > 0) {
        $("reoccuringLine_2").hide();
    }
    else {
        $("reoccuringLine_2").show();
    }
    PageCallObj[currentID].lineItemSwitch *= -1;
}

function showPricingPop(e_id){   
	var currentID = e_id;
    var target = $(currentID);
    var div = $(accPVar.acc_price_pop);
    var curleft = curtop = 0;
    var obj = $(currentID);
    var currentPlanId = PageCallObj[currentID].planId;
    
    if (PageCallObj[accPVar.currElemId].elemWasClicked == false) {
        document.getElementById(accPVar.acc_price_pop_container).onmouseover = function(){
        	clearTimeout(accPVar.funcThread[("t"+PageCallObj[currentID].type)].outTime);
            PageCallObj[accPVar.currElemId].popIsActive = true;
        }
        document.getElementById(accPVar.acc_price_pop_container).onmouseout = function(){
            PageCallObj[accPVar.currElemId].popIsActive = false;
            accPVar.funcThread[("t"+PageCallObj[currentID].type)].outTime = setTimeout("closePop(accPVar.acc_price_pop)", 500);
        }
    }
    else {
    	//accPVar.fixedElem[("f_"+accPVar.acc_price_pop)] = currentID;
        document.getElementById(accPVar.acc_price_pop_container).onmouseover = "";
        document.getElementById(accPVar.acc_price_pop_container).onmouseout = "";
    }
    
    $(accPVar.acc_price_pop).onmouseover = function(){
        PageCallObj[currentID].elemIsActive = true;
        
    }
    $(accPVar.acc_price_pop).onmouseout = function(){
        PageCallObj[currentID].elemIsActive = false;
    }
    
    if (jsonData != null && jsonData != "") {
        var jCartData = eval(jsonData[currentPlanId]);
        if (jCartData != null && jCartData != "undefined") {
        	
        	div.style.visibility = 'visible';
            div.style.display = 'block';
            div.style.position = 'absolute';
            $(accPVar.acc_price_pop_container).style.display = 'block';
            do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            }
            while (obj = obj.offsetParent);
            
            curtop = curtop + parseInt(target.offsetHeight);
            div.style.left = curleft - 253;
            div.style.top = curtop;
            
            
            
            /////////////////////////////////////////////////////////
            //clean...
            $("acc_pp_LineItemText").innerHTML = "<!-- -->";
            $("acc_pp_LineItemPricing").innerHTML = "<!-- -->";
            $("acc_pp_LineItems").innerHTML = "<!-- -->";
            $("acc_pp_dynaPrice").innerHTML = "<!-- -->";
            $("acc_pp_dynaPriceText_2").innerHTML = "<!-- -->";
            $("acc_pp_dynaPrice_2").innerHTML = "<!-- -->";
            $("acc_pp_baseOneTimeFeesText_2").innerHTML = "<!-- -->";
            $("acc_pp_baseOneTimeFees_2").innerHTML = "<!-- -->";
            $("pp_baseMonthly_2").hide();
            $("pp_oneTimeFees_2").hide();
            $("baseLine_1").hide();
            $("acc_pp_baseLineItems").innerHTML = "<!-- -->";
            //end clean...
            ////////////////////////////////////////////////////////
            
            var pContent = jCartData.pricing;
            var showDiscount = false;
            var showMonthly = false;
            $("acc_pp_dynaPriceText").innerHTML = jCartData.pricingText;				
            $("acc_pp_monthlyTotalText").innerHTML = "Estimated Total:";
            $("acc_pp_baseOneTimeFeesText").innerHTML = "Base One-time Fees:";
            $("acc_pp_oneTimeFeesText").innerHTML = "Total One-time Fees:";
            
            $("acc_pp_monthlyTotal").innerHTML = "$" + jCartData['monthlyTotal'].dollars + "." + jCartData['monthlyTotal'].cents + " /mo.";
            $("acc_pp_dynaPrice").innerHTML = "$" + jCartData['basePricing'].dollars + "." + jCartData['basePricing'].cents + " /mo.";
            $("acc_pp_baseOneTimeFees").innerHTML = "$" + jCartData['baseOneTimePricing'].dollars + "." + jCartData['baseOneTimePricing'].cents;
            $("acc_pp_oneTimeFees").innerHTML = "$" + jCartData['oneTimeFees'].dollars + "." + jCartData['oneTimeFees'].cents;
            
            if (jCartData['promotions']) {
                var promoHash = $H(jCartData['promotions']);
                promoHash.each(function(p){
                    var promo = p.value;
                    if (promo.promotionType == "BASE_MONTHLY_DISCOUNT") {
                        showMonthly = true;
                        $("acc_pp_dynaPrice").innerHTML = "<del>$" + jCartData['originalBasePricing'].dollars + "." + jCartData['originalBasePricing'].cents + " /mo.</del>";
                        $("acc_pp_dynaPriceText_2").innerHTML = "<span class='promotionPriceColor' style='font-weight:bold;'>Promo "+jCartData.pricingText+"</span>";
                        $("acc_pp_dynaPrice_2").innerHTML = "<span class='promotionPriceColor' style='font-weight:bold;'>$" + jCartData['basePricing'].dollars + "." + jCartData['basePricing'].cents + " /mo.</span>";//$('pp_baseMonthly').insert({after:"<tr><td>dsdf<!-- sdfsdf--></td></tr>"});
                        $("pp_baseMonthly_2").show();
                    }
                    else 
                        if (promo.promotionType == "ONE_TIME_FEE_DISCOUNT") {
                            showDiscount = true;
                            $("acc_pp_baseOneTimeFees").innerHTML = "$" + jCartData['originalOneTimePricing'].dollars + "." + jCartData['originalOneTimePricing'].cents;
                            $("acc_pp_baseOneTimeFeesText_2").innerHTML = "<span class='promotionPriceColor' style='font-weight:bold;'>Promotion Discount:</span>";
                            $("acc_pp_baseOneTimeFees_2").innerHTML = "<span class='promotionPriceColor' style='font-weight:bold;'>- $" + promo.discount.dollars + "." + promo.discount.cents + "</span>";
                            $("pp_oneTimeFees_2").show();
                            $("pp_oneTimeFees").show();
                        }
                });
            }
            
            if (jCartData['optionsCost'].price != 0) {
                if (jCartData['lineItemPricing'].recurringLineItems.length > 0) {
                    var lip = jCartData['lineItemPricing'];
                    var x = 0;
                    $("acc_pp_LineItemText").innerHTML = '<span style="cursor:pointer;" onclick="showLineItems(\''+currentID+'\');"><img src="/01/img/activePops/dropArrow_pricePop.gif" hspace="3"/>Options Selected:</span> ';
                    $("acc_pp_LineItemPricing").innerHTML = "$" + jCartData['optionsCost'].dollars+"."+jCartData['optionsCost'].cents + " /mo.";
                    
                    var lipHtml = "";
                    lipHtml += "<ul>";
                    for (x = 0; x < lip.recurringLineItems.length; x++) {
                        lipHtml += "<li>" + lip.recurringLineItems[x].label + ":  $" + lip.recurringLineItems[x].pricing.dollars + "." + lip.recurringLineItems[x].pricing.cents + " /mo.</li>";
                    }
                    lipHtml += "</ul>";
                    $("acc_pp_LineItems").innerHTML = lipHtml;
                }
            }
            
            if (jCartData['lineItemPricing'].onetimeLineItems.length > 0) {
                var blip = jCartData['lineItemPricing'];
                var x = 0;
                var blipHtml = "";
                blipHtml += "<table cellpadding='0' cellspacing='0'>";
                for (x = 0; x < blip.onetimeLineItems.length; x++) {
                    blipHtml += "<tr>";
                    blipHtml += "<td class='acc_pp_text_column' style='color:#999;'>" + blip.onetimeLineItems[x].label + ":</td>";
                    blipHtml += "<td class='acc_pp_price_column' style='color:#999;'>$" + blip.onetimeLineItems[x].pricing.dollars + "." + blip.onetimeLineItems[x].pricing.cents + "</td>";
                    blipHtml += "</tr>";
                }
                blipHtml += "</table>";
                $("baseLine_1").show();
                $("acc_pp_baseLineItems").innerHTML = blipHtml;
            }
            if (jCartData['basePricing'].price != jCartData['monthlyTotal'].price || showMonthly == true) {
                $('acc_pp_baseOneTimeFees_dash').show();
                $('acc_pp_monthlyTotal_dash').show();
                $('acc_pp_monthlyTotal_row').show();
            }
            else {
                $('acc_pp_baseOneTimeFees_dash').hide();
                $('acc_pp_monthlyTotal_dash').hide();
                $('acc_pp_monthlyTotal_row').hide();
            }
            if (jCartData['baseOneTimePricing'].price != jCartData['oneTimeFees'].price || showDiscount == true) {
                $('acc_pp_totalOnetimeFees_dash').show();
                $('acc_pp_totalOnetimeFees_row').show();
            }
            else {
                $('acc_pp_totalOnetimeFees_dash').hide();
                $('acc_pp_totalOnetimeFees_row').hide();
            }
            
            if (PageCallObj[currentID].lineItemSwitch < 0) {
                $("reoccuringLine_2").hide();
            }
            else {
                $("reoccuringLine_2").show();
            }
        }
    }
}

function sendRequestAndPopulate(key, callType, e_id){//use for def pop only. need to modify for others later
	var currentID = e_id;
    var popId = "";
    var pars = encodeURI('callKey=' + key + '&callType=' + callType);
    
    var url = '/features/accPops.html';
    new Ajax.Request(dynamicUrls.resolveUrl(url), {
        parameters: pars,
        method: 'POST',
        onSuccess: function(transport){
            var jsonRaw = transport.responseText;
            var obj = $(currentID);
            try {
                var jsonContent = eval('(' + jsonRaw + ')');
                
                if (jsonContent["def"] != "" && jsonContent["headline"] != "") {
                    PageCallObj[currentID].pageText = jsonContent["def"];
                    PageCallObj[currentID].innerHeader = jsonContent["headline"];
                    $("dp_head_" + currentID).innerHTML = PageCallObj[currentID].innerHeader;
                    $("dp_inner_" + currentID).innerHTML = PageCallObj[currentID].pageText;
                    posDefPop(obj);
                }
            } 
            catch (err) {
                ///
            }
        }
    });
}

function closePop(id,elemId){
	//get the popWindowId to close
    var tmp = (id != null && id != "") ? id : (accPVar.currElemId != null && accPVar.currElemId != "") ? PageCallObj[accPVar.currElemId].popWindow : "";        
    if ($(tmp)) {    	
    	accPVar.fixedElem[("f_"+tmp)] = "";
    	cancelAccEvent((typeof elemId=="string" && elemId!="")?elemId:accPVar.currElemId);       
        document.getElementById(tmp).style.display = "none";
    }
}

function reset_activePops(globalVars){
	var cp = null;
	cp = accPVar;
	
	try{		
		if(globalVars){
			//TODO compare keys in globalVars with default keys of accPVars 
			accPVar = globalVars;
		}		
	}catch(err){
		accPVar = cp;
	}	
    init_acc_pops();
}

function showPromoLayer(e_id){	
	var currentID = e_id;
    var currentPlanId = PageCallObj[currentID].planId;
    var promoId = PageCallObj[currentID].defName;
    var plan = null;
    if(PageCallObj[currentID].elemWasClicked || accPVar.fixedElem[("f_"+accPVar.acc_promo_pop)]==""){
	    PageCallObj[currentID].popIsActive = true;
	   
	    $(accPVar.acc_promo_pop).show();
	    for (var x = 0; x < servicePlans.length; x++) {
	        if (servicePlans[x].planId == currentPlanId) {
	            plan = servicePlans[x];
	            break;
	        }
	    }
	    
	    if(plan!=null){
		    var currentPromo = plan.promotions[promoId];
		    var promoExpDate = new Date(currentPromo.expirationDate);
		    var qualContent = "";
		    
		    if (currentPromo.qualifications) {
		        qualContent = currentPromo.qualifications;
		    }
		    var pdate = (promoExpDate.getMonth()+1) + "/" + promoExpDate.getDate() + "/" + promoExpDate.getFullYear();
		    var termsUrl = "/shopping/promotionalTerms.html?planId=" + plan.planId + "&typeId=" + plan.serviceTypeId + "&promoId=" + promoId;
		
		    if(PageCallObj[accPVar.currElemId].elemWasClicked == false){
		    	
			    $(accPVar.acc_promo_pop).onmouseover = function(){    	
			    	clearTimeout(accPVar.funcThread[("t"+PageCallObj[currentID].type)].outTime);
			    	PageCallObj[accPVar.currElemId].elemIsActive = true;
			    }
			    $(accPVar.acc_promo_pop).onmouseout = function(){    	
			   	 	PageCallObj[accPVar.currElemId].elemIsActive = false;
			   	 	accPVar.funcThread[("t"+PageCallObj[currentID].type)].outTime = setTimeout("closePop(accPVar.acc_promo_pop)", 100);
			    }
		    }else{
		    	accPVar.fixedElem[("f_"+accPVar.acc_promo_pop)] = currentID;
		    	 $(accPVar.acc_promo_pop).onmouseover = "";
		    	 $(accPVar.acc_promo_pop).onmouseout = "";
		    }
		    
		    if(accPVar.statusObj['overSpecialOffer'] && 
		    	accPVar.statusObj['overSpecialOffer']==true && 
		    		cycleSpecialOffers != null){
		    	if(PageCallObj[currentID].elemWasClicked == true){    	
			    	try{
			    		clearInterval(cycleSpecialOffers);
			    		cycleSpecialOffers = "pause2";
			    		PageCallObj[currentID].cancelAction = function(){    		
			    			if(null!=cycleSpecialOffers){
			    				cycleSpecialOffers = window.setInterval(cycleOffers,cycleSpecialOffersDelay);
			    			}
			    		}
			    	}catch(err){}  
		    	}else if(PageCallObj[accPVar.prevElemId] && PageCallObj[accPVar.prevElemId].cancelAction){
		    		try{    	
			    		PageCallObj[currentID].cancelAction = function(){    		
			    			if(null!=cycleSpecialOffers){
			    				cycleSpecialOffers = window.setInterval(cycleOffers,cycleSpecialOffersDelay);
			    			}
			    		}
			    		PageCallObj[accPVar.prevElemId].cancelAction = "";
		    		}catch(err){}
		    	}    	
		    }    
		    $('promoLayerDynaClose').innerHTML = "<img class=\"modalCloseBttn\" src=\"/01/img/activePops/acc_pp_close_x.png\" width=\"14\" onclick=\"closePop('acc_promo_details_container','"+currentID+ "');\" style=\"cursor:pointer;\"/>";
		    $('acc_promo_header').innerHTML = currentPromo.shortDescription;
		    $('acc_promo_content').innerHTML = qualContent + "<div style='padding-top:15px;font-weight:bold;'>Offer Expires on " + pdate + "</div>" + ((currentPromo.termsAndConditions && !currentPromo.termsAndConditions.isEmpty()) ? "<div class='LINK_COLOR'><a href='/shopping/promotionalTerms.html' onclick='newWindow(\"" + termsUrl + "\",515,300);return false;' rel='nofollow'>Terms &amp; Conditions Apply</a></div>" : "<br/><br/>");
	    }
    }
}

function showPlanDetails(evt,e_id){		
	var xcrd = 0;
	var ycrd = 0;	
	var currentID = e_id;	
	var pob = getServicePlan(PageCallObj[currentID].planId);
	
	PageCallObj[currentID].cancelAction = function(id){//timeout for mousemove only	
		if(PageCallObj[id].timeout!=null)
			clearTimeout(PageCallObj[id].timeout);
		PageCallObj[id].timeout = 
			setTimeout("if(PageCallObj[\""+id+"\"].elemIsActive==false)"+
				"{$(\""+id+"\").onmousemove = '';}",700);	
	}

	
	
	var setCoor = function(event){		
		var e = (!event)?window.event:event;	
		var xcrd = 0;	
		if(e.pageX){
			xcrd = e.pageX;			
		}else if(e.clientX){
			xcrd = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;		
		}	
		if(xcrd != 0){
			$(accPVar.acc_plan_details_pop).style.left = xcrd-225;			
		}
	}
	//reposition as mouse moves
	Event.observe($(currentID), 'mousemove', setCoor.bindAsEventListener());	
	
	if(!PageCallObj[currentID].popIsActive){		
		setCoor(evt);	
		var elem = $(currentID);			
		var dcurTop = 0;
		do{			
		    dcurTop += elem.offsetTop;
		}while (elem = elem.offsetParent);
		dcurTop = (dcurTop - parseInt($(acc_plan_details_pop).getDimensions()["height"])) + ((ie)?15:0);
		$(accPVar.acc_plan_details_pop).style.top = dcurTop;						
	}
	var overFunc = function(e){	
		var args =  $A(arguments);	
		var id = args[1];
		clearTimeout(accPVar.funcThread[("t"+PageCallObj[id].type)].outTime);
		PageCallObj[id].popIsActive = true;
	}
	var outFunc = function(e){
		var args =  $A(arguments);	
		var id = args[1];
		clearTimeout(accPVar.funcThread[("t"+PageCallObj[id].type)].outTime);
		PageCallObj[id].popIsActive = false;
		accPVar.funcThread[("t"+PageCallObj[id].type)].outTime = setTimeout("if(!PageCallObj[\""+id+"\"].popIsActive || !PageCallObj[\""+id+"\"].elemIsActive){closePop(accPVar.acc_plan_details_pop)}", 400);		
	}
	Event.observe($(PageCallObj[currentID].popWindow), 'mouseover', overFunc.bindAsEventListener(this,currentID));
	Event.observe($(PageCallObj[currentID].popWindow), 'mouseout', outFunc.bindAsEventListener(this,currentID));
	
	$('acc_plan_details_pop').innerHTML = '<div id="acc_plan_details_pop_text"><div id="acc_dtlp_planTitle"><!-- --></div><div id="acc_dtlp_planDescription" style="clear:both;"><!-- --></div></div><div id="acc_plan_details_pop_bottom_cap"><img src="/01/img/activePops/acc_dp_tri_pointer.gif"/></div>';
	var t_text = '<span>'+pob.planName+'</span>'+'<img width="86" height="36" style="float:right;" src="/shared/providers/'+pob.pid+'/img/small.gif"/>';
	$('acc_dtlp_planTitle').innerHTML = t_text;
	$('acc_dtlp_planDescription').innerHTML = pob.desc;
	$(accPVar.acc_plan_details_pop).show();
}

addOnLoadFunction('init_acc_pops()');
