﻿var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
       var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
       var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";
       var imgStyle = "display:inline-block;" + myImage.style.cssText;
       var strNewHTML="<span "+imgID+imgClass+imgTitle+" style=\""+"width:"+myImage.width+"px; height:" + myImage.height+"px;"+imgStyle + ";"
                      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+"(src=\'"+myImage.src+"\', sizingMethod='scale');\"></span>";
       myImage.outerHTML = strNewHTML;	  
    }
}
function gDomLocator(elm) {
    var x,y=0;
    x=elm.offsetLeft;
    y=elm.offsetTop;
    elm=elm.offsetParent;
    while(elm != null) {
        x=parseInt(x)+parseInt(elm.offsetLeft);
        y=parseInt(y)+parseInt(elm.offsetTop);
        elm=elm.offsetParent;
    }
    return {t:y,l:x};
}
function sDomStyle(dpara) {
        if (dpara.id) var dObj=document.getElementById(dpara.id);
        else if (dpara.obj) var dObj=dpara.obj;
        else return false;
        if (dpara.w) dObj.style.width=dpara.w+'px';
        if (dpara.h) dObj.style.height=dpara.h+'px';
        if (dpara.t) dObj.style.top=dpara.t+'px';
        if (dpara.l) dObj.style.left=dpara.l+'px';
        if (dpara.p) dObj.style.position=dpara.p;
}
function getStyle( elem, name ) {
    if (elem.style[name])
        return elem.style[name];
    else if (elem.currentStyle)
        return elem.currentStyle[name];
    else if (document.defaultView && document.defaultView.getComputedStyle) {
        name = name.replace(/([A-Z])/g,"-$1");
        name = name.toLowerCase();
        var s = document.defaultView.getComputedStyle(elem,"");
        return s && s.getPropertyValue(name);
    } else
        return null;
}
function remove( elem ) {
    if ( elem ) elem.parentNode.removeChild( elem );
}
function empty( elem ) {
    while ( elem.firstChild )
        remove( elem.firstChild );
}
function hide( elem ) {
    var curDisplay = getStyle( elem, 'display' );
    if ( curDisplay != 'none' )
        elem.$oldDisplay = curDisplay;
    elem.style.display = 'none';
}
function show( elem ) {
    elem.style.display = 'block';
}
function gShowRoomDom(parID,frameID,fImg,baseW,baseH) {
    var gFrm=document.createElement('div');
    gFrm.id=frameID;
    sDomStyle({obj:gFrm,h:baseH,w:baseW,t:0,l:0,p:'absolute'});
    var gPara=[];
    gPara[0]={t:0,l:0,w:fImg[0].w,h:fImg[0].h};
    gPara[1]={t:0,l:fImg[0].w,w:baseW-fImg[0].w-fImg[2].w,h:fImg[1].h};
    gPara[2]={t:0,l:fImg[0].w+gPara[1].w,w:fImg[2].w,h:fImg[2].h};
    gPara[3]={t:fImg[2].h,l:fImg[0].w+gPara[1].w,w:fImg[3].w,h:baseH-fImg[0].h-fImg[6].h};
    gPara[4]={t:fImg[2].h+gPara[3].h,l:fImg[0].w+gPara[1].w,w:fImg[4].w,h:fImg[4].h};
    gPara[5]={t:fImg[2].h+gPara[3].h,l:fImg[0].w,w:baseW-fImg[0].w-fImg[2].w,h:fImg[5].h};
    gPara[6]={t:fImg[2].h+gPara[3].h,l:0,w:fImg[6].w,h:fImg[6].h};
    gPara[7]={t:fImg[0].h,l:0,w:fImg[7].w,h:baseH-fImg[0].h-fImg[6].h};
    gPara[8]={t:fImg[0].h,l:fImg[0].w,w:baseW-fImg[0].w-fImg[2].w,h:baseH-fImg[0].h-fImg[6].h};
    for(var i=0;i<9;i++) gFrm.innerHTML+='<img src="'+fImg[i].img+'" width="'+gPara[i].w+'px'+'" height="'+gPara[i].h+'px'+'" border="0px" '+'id="frame_img_0" style="top:'+gPara[i].t+'px;left:'+gPara[i].l+'px;'+'position:absolute;" />';
    document.getElementById(parID).appendChild(gFrm);
    return gFrm;
}
function gCloseUpDom(parentID,imgTop,imgLeft,imgPara) {
        var gClose=document.createElement('div');
        gClose.id='sp_close_button';
        gClose.innerHTML=
        '<a href="#" id="a_close_plate">'
        +'<img src="'+imgPara.img+'" width="'+imgPara.w+'px'
        +'" height="'+imgPara.h+'px'+'" border="0px" '
        + 'id="sp_close_button" style="top:'+imgTop+'px;left:'+imgLeft+'px;'
        + 'position:absolute;" onload="fixPNG(this)" style="cursor: pointer;"/>'
        +'</a>';
        var focusPoint = function() {
              hide(document.getElementById(parentID));
              return false;
        };
        sDomStyle({obj:gClose,h:imgPara.h,w:imgPara.w,p:'absolute'});
        gClose.onclick = focusPoint;
        document.getElementById(parentID).appendChild(gClose);
        return gClose;
}
function gImageDom(parID,imgID,imgTop,imgLeft,imgPara,borderW) {
        var gIcon=document.createElement('div');
        gIcon.id=imgID+'_div';
        gIcon.innerHTML='<img src="'+imgPara.img+'" width="'+imgPara.w+'px'
        +'" height="'+imgPara.h+'px'+'" border="'+borderW+'px'+'" '
        + 'id="'+imgID+'" style="top:0px;left:0px;position:absolute;" onload="fixPNG(this)" />';
        sDomStyle({obj:gIcon,h:imgPara.h,w:imgPara.w,t:imgTop,l:imgLeft,p:'absolute'});
        document.getElementById(parID).appendChild(gIcon);
        return gIcon;
}
function gParagraphDom(parID,paraDomID,paraID,outPara) {
        var gColor='black';
        if (outPara.color) gColor=outPara.color;
        var gPara=document.createElement('div');
        gPara.id=paraDomID;
        gPara.innerHTML = '<p id="'+paraID+'" style="width:'+outPara.w+'px;height:'+outPara.h
        + 'px;top:0px;left:0px;position:absolute;border: '+ outPara.border
        +'px solid #ccc;padding: 0px;margin:0px;overflow:auto;font-size: '+ outPara.fontsize+'px;color:'+gColor+'" >' 
        + outPara.content + '</p>';
        sDomStyle({obj:gPara,h:outPara.h,w:outPara.w,t:outPara.t,l:outPara.l,p:'absolute'});
        document.getElementById(parID).appendChild(gPara);
        return gPara;
}

var agData=[];
agData.push({eName:'Allan Cheng',cName:'鄭博文',city:'Alhambra',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=3'});
agData.push({eName:'Tom Romano',cName:'',city:'Alhambra',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=4'});
agData.push({eName:'Lisa Leung',cName:'梁沈令儀',city:'Arcadia',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=5'});
agData.push({eName:'Allan Kam',cName:'金拔群',city:'Artesia',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=6'});
agData.push({eName:'Jim Barr',cName:'',city:'Cerritos',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=7'});
agData.push({eName:'Christy Lee',cName:'陳珍娜',city:'City of Industy',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=8'});
agData.push({eName:'Vicky Chen',cName:'陳悅',city:'Diamond Bar',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=9'});
agData.push({eName:'Jim Sundo',cName:'',city:'Hacienda Heights',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=10'});
agData.push({eName:'Richard Tay',cName:'鄭炳鑫',city:'Irvine',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=11'});
agData.push({eName:'Sean S Cheng',cName:'',city:'Los Angeles',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=12'});
agData.push({eName:'Glen Higashida',cName:'',city:'Monterey Park',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=13'});
agData.push({eName:'Lanni Wong',cName:'',city:'Monterey Park',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=14'});
agData.push({eName:'Steve Tieu',cName:'',city:'Rosemead',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=15'});
agData.push({eName:'Lili Yu',cName:'俞中禮',city:'Rowland Heights',url:'ccyp.com/SpecialEvents/SFC/SC_test.asp?AgentID=16'});
agData.push({eName:'Edward Cheng',cName:'鄭泰康',city:'San Gabriel',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=17'});
agData.push({eName:'Emily Kwan',cName:'關伍琨瑜',city:'San Gabriel',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=18'});
agData.push({eName:'Aaron Vuong',cName:'王克茂',city:'Temple City',url:'ccyp.com/SpecialEvents/SFC/SC_test.asp?AgentID=19'});
agData.push({eName:'Christine W Chang',cName:'',city:'Walnut',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=20'});
agData.push({eName:'Pactrick Lau',cName:'劉紹強',city:'Walnut',url:'ccyp.com/SpecialEvents/SFC/SC.asp?AgentID=21'});

function attaAgentList(get_data) {
        var hrefUrl="";
        var package="";
        var combine="";
        var aDesc="";
        for (var i=0;i<get_data.length;i++) {
             aDesc=get_data[i].eName+' '+get_data[i].cName+', '+get_data[i].city;
             hrefUrl='http://'+get_data[i].url;
             package='<a href="'+hrefUrl+'" style="font-family:arial;font-size:12px;" target="blank">'+aDesc+'<br \></a>';
             combine=combine+package;
        }
        document.getElementById('sf_agent_para').firstChild.nodeValue="";
        document.getElementById("sf_agent_para").innerHTML=combine;
}


var top5AdData=[];
function prepAdData() {
top5AdData.push({img:'SC01.jpg',title:'Allan_Cheng',url:'testurl'});
top5AdData.push({img:'SC02.jpg',title:'Tom_Romano',url:'testurl'});
top5AdData.push({img:'SC03.jpg',title:'Lisa_Leung',url:'testurl'});
top5AdData.push({img:'SC04.jpg',title:'Allan_Kam',url:'testurl'});
top5AdData.push({img:'SC05.jpg',title:'Jim_Barr',url:'testurl'});
top5AdData.push({img:'SC06.jpg',title:'Christy_Lee',url:'testurl'});
top5AdData.push({img:'SC07.jpg',title:'Vicky_Chen',url:'testurl'});
top5AdData.push({img:'SC08.jpg',title:'Jim_Sundo',url:'testurl'});
top5AdData.push({img:'SC09.jpg',title:'Richard_Tay',url:'testurl'});
top5AdData.push({img:'SC10.jpg',title:'Sean_Cheng',url:'testurl'});
top5AdData.push({img:'SC11.jpg',title:'Glen_Higashida',url:'testurl'});
top5AdData.push({img:'SC12.jpg',title:'Lanni_Wong',url:'testurl'});
top5AdData.push({img:'SC13.jpg',title:'Steve_Tieu',url:'testurl'});
top5AdData.push({img:'SC14.jpg',title:'Lili_Yu',url:'testurl'});
top5AdData.push({img:'SC15.jpg',title:'Edward_Cheng',url:'testurl'});
top5AdData.push({img:'SC16.jpg',title:'Emily_Kwan',url:'testurl'});
top5AdData.push({img:'SC17.jpg',title:'Aaron_Vuong',url:'testurl'});
top5AdData.push({img:'SC18.jpg',title:'Christine_Chang',url:'testurl'});
top5AdData.push({img:'SC19.jpg',title:'Pactrick_Lau',url:'testurl'});
}

var top5PreloadImage=[];
function preloadAdImg() {

        for (i=0;i<top5AdData.length;i++)
        {
              var newImg="sfimg/"+top5AdData[i].img;
              top5PreloadImage[i] = new Image(370,60);
              top5PreloadImage[i].src=newImg;
        }
}

var currTop5AdData=-1;
function twingleTop5AdContent() {
        var lastTop5Ad=top5AdData.length-1;
        currTop5AdData+=1;
        if (currTop5AdData>lastTop5Ad) currTop5AdData=0;
        document.getElementById('top5Image').src=top5PreloadImage[currTop5AdData].src;
        setTimeout("twingleTop5AdContent()",2000);
}

var defFrm=[];
defFrm[0]={img:"sfimg/sf_lt.png",w:20,h:21};
defFrm[1]={img:"sfimg/sf_t.png",w:20,h:21};
defFrm[2]={img:"sfimg/sf_rt.png",w:33,h:21};
defFrm[3]={img:"sfimg/sf_r.png",w:33,h:19};
defFrm[4]={img:"sfimg/sf_rb.png",w:33,h:32};
defFrm[5]={img:"sfimg/sf_b.png",w:20,h:32};
defFrm[6]={img:"sfimg/sf_lb.png",w:20,h:32};
defFrm[7]={img:"sfimg/sf_l.png",w:20,h:32};
defFrm[8]={img:"sfimg/sf_c.png",w:20,h:30};
var closeIcon={img:'sfimg/statefarm_close.png',over:'sfimg/statefarm_close.png',w:23,h:22};
var logoIcon={img:'sfimg/statefarm_logo.png',over:'sfimg/statefarm_logo.png',w:55,h:52};
function initBoard(widthB,heightB) {
        var dBoard = document.getElementById('dispBoard');
        sDomStyle({obj:dBoard,t:220,l:810});
        empty(dBoard);
        gShowRoomDom('dispBoard','disp_frame',defFrm,widthB,heightB);
        gImageDom('dispBoard','sf_logo_img',10,205,logoIcon,0);
        gCloseUpDom('dispBoard',10,widthB-45,closeIcon);
        gParagraphDom('dispBoard','sf_title_div','sf_title_para',
        {content:'Southern California',w:250,h:20,t:30,l:35,border:0,fontsize:14,color:'red'});
        gParagraphDom('dispBoard','sf_agent_div','sf_agent_para',
        {content:'agent list',w:250,h:400,t:65,l:35,border:0,fontsize:14,color:'blue'});
        attaAgentList(agData);
        hide(dBoard);
}
function modifyDisp() {
        var gLoca=gDomLocator(document.getElementById('top5Image'));
        sDomStyle({id:'dispBoard',t:gLoca.t-8,l:gLoca.l+370});
}

var clockTimeoutID;
function popupDispBoard() {
        modifyDisp();
        show(document.getElementById('dispBoard'));
        clockTimeoutID=setTimeout("closeDispBoard()",5000);
}
function init() {
        prepAdData();
        preloadAdImg();
        initBoard(306,400);
        setTimeout("twingleTop5AdContent()",1000);
}
function closeDispBoard() {
        hide(document.getElementById('dispBoard'));
}
function stophide() {
        if (clockTimeoutID) clearTimeout(clockTimeoutID);
        clockTimeoutID=setTimeout("closeDispBoard()",5000);
}


