﻿var opacity = 0.8;
var tileList;
var whereSeperator = "|";   
var minZoom = 1;
var maxZoom = 16;     

function getMap()         
{          
	try
	{  
 		map = new VEMap('MapPanel');			
 		//map.SetDashboardSize(VEDashboardSize.Small);
		map.LoadMap(new VELatLong(10, 0), 2 ,'r' ,false, VEMapMode.Mode2D, true);
		tileList = new TileList(map);		
		
		DrawingInit();
		
		
		//add draw control
		//map.AddControl(document.getElementById('DrawPanel'));  
		attachDefaultMouseEvents();
		attachEvents4IE6Only();
		//map.ClearInfoBoxStyles();
		
		//document.getElementById("MapPanel").appendChild(document.getElementById("divInfoBox"));
		
		
		
	}
	catch(ex)
	{
		//alert(ex.message);
	}    
} 

function showMiniMap()
{
    if (map.GetMapMode() == 2){
        map.SetMapMode(VEMapMode.Mode2D);
    }
    
    map.ShowMiniMap(12,235);            
    //map.ShowMiniMap();            
}
function showNavControl(show){
    if (show == true){
        map.ShowDashboard();
    }else {
        map.HideDashboard();
    }
}

function clearAllOverlays(){
    
    //map.Clear();
    //map.DeleteAllShapes();    
    for (var i = 0; i < map.GetShapeLayerCount(); i++){
        map.GetShapeLayerByIndex(i).DeleteAllShapes();
    }
    //map.DeleteAllShapeLayers();
    tileList.deleteAllTiles();
    
    vmShapeList.clearAll();
    
    

}
function deleteShapeById(id){
    try {
        map.DeleteShape(map.GetShapeByID(id));
        hideInfoBox();
    }catch (ex){
    }
    
}
 
//Concanate values in check boxes into an sql where claus
function checkBoxesToWhereClause(divId, checkBoxClass, colName){
    var theForm = document.getElementById(divId);
    var theBoxes = theForm.getElementsByTagName("input");
    
    var theBox = null;
    var whereClause = "";
    //alert (theBoxes.length);
    for (var i = 0; i < theBoxes.length ; i++){
        b = theBoxes[i];
        if ((b.type == "checkbox") || (b.type =="radio")){
            //alert (b.name);
            if (b.name == checkBoxClass & b.checked == true){
                whereClause = whereClause + colName + "='" + b.value + "' or ";
            }
        }
    }    
    return whereClause.substring(0, whereClause.length-4)  + "" ;   
}
function checkBoxesToWhereClauseShort(divId, checkBoxClass, colName){
    var theForm = document.getElementById(divId);
    var theBoxes = theForm.getElementsByTagName("input");
    
    var theBox = null;
    var whereClause = "";
    //alert (theBoxes.length);
    for (var i = 0; i < theBoxes.length ; i++){
        b = theBoxes[i];
        if ((b.type == "checkbox") || (b.type =="radio")){
            //alert (b.name);
            if (b.name == checkBoxClass & b.checked == true){
                whereClause = whereClause +   " '" + b.value + "',";
            }
        }
    }    
    if (whereClause.length > 0){
        whereClause = whereClause.substring(0, whereClause.length-1);
        whereClause = " ( " + colName  + " in " +  " ( " + whereClause + " ) " + ")";
    }
    //alert (whereClause);
    return whereClause;
}

//Copy the value in check boxes into an array for using as input parmeter when request a tile
function checkBoxesToWhereValues(divId, checkBoxClass, seperator){
    var theForm = document.getElementById(divId);
    var theBoxes = theForm.getElementsByTagName("input");
    
    var theBox = null;
    var whereClause = "";
    //alert (theBoxes.length);
    for (var i = 0; i < theBoxes.length ; i++){
        b = theBoxes[i];
        if ((b.type == "checkbox") || (b.type =="radio")){
            //alert (b.name);
            if (b.name == checkBoxClass & b.checked == true){
                whereClause = whereClause +  b.value + seperator;
            }
        }
    }    
    return whereClause.substring(0, whereClause.length-seperator.length);
}

//Check and uncheck all boxes in a div
function toggleBoxes (divId, checkBoxClass, checked){
    var theForm = document.getElementById(divId);
    var theBoxes = theForm.getElementsByTagName("input");
    //alert (checked);
    for (var i = 0; i < theBoxes.length ; i++){
        b = theBoxes[i];
        if (b.type == "checkbox"){
            //alert (b.name);
            if (b.name == checkBoxClass){
                b.checked = checked;
            }
        }
    }
}

function getValuesOfCheckedBox(divId, checkBoxClass){
    var vals = new Array();
    var theForm = document.getElementById(divId);
    var theBoxes = theForm.getElementsByTagName("input");
    var count = 0;
    //alert (checked);
    for (var i = 0; i < theBoxes.length ; i++){
        b = theBoxes[i];
        if (b.type == "checkbox"){
            //alert (b.name);
            if (b.name == checkBoxClass && b.checked ==true){                
                vals[count] = b.value;
                count++;
            }
        }
    }
    return vals;
}
//if whereColName == "" -> all of will be selected
function createTileOfPoints (divId, checkBoxClass, tileId, tableName, themeColName, whereColName, minZoom, maxZoom, iconType, sameIcon){
    var theTile = null;
    var whereSeperator = "|";        
    
    tileList.deleteTileById(tileId);       
    var whereValues = checkBoxesToWhereValues(divId, checkBoxClass,whereSeperator);
            
    if (whereColName=="") {
        whereValues ="";
    }else {
        if (whereValues ==""){
            return;
        }
    }
    theTile = new VMTile(map, tileId);
        
    theTile.setTableName ( tableName);           
    theTile.setThemeColName ( themeColName);            
    theTile.setWhereColName(whereColName);          
    theTile.setWhereValues(whereValues);            
    theTile.setWhereSeperator(whereSeperator);                  
    theTile.setShapeType ("POINT");
    
    theTile.setIconType(iconType);
    theTile.setSameIcon(sameIcon);
    theTile.setOpacity (opacity);                
    //theTile.setZIndex(zIndex);
    tileList.addTile(theTile);
    
    theTile.addTile( map, maxZoom, minZoom);         
}

//if whereColName = "" -> select everything
function createTileOfShapes (divId, checkBoxClass, tileId, tableName, tableToUpdate, themeColName, whereColName, shapeType, minZoom, maxZoom, colorHexColName){
    var theTile = null;
    var whereSeperator = "|";        
    
    tileList.deleteTileById(tileId);       
    var whereValues = checkBoxesToWhereValues(divId, checkBoxClass,whereSeperator);
    //alert (whereValues);      
    if (whereValues!="") {
        theTile = new VMTile(map, tileId);
        
        theTile.setTableName ( tableName);   
        theTile.setTableToUpdate(tableToUpdate);         
        theTile.setThemeColName ( themeColName);
        theTile.setColorHexColName ( colorHexColName);            
        theTile.setWhereColName(whereColName);          
        theTile.setWhereValues(whereValues);            
        theTile.setWhereSeperator(whereSeperator);                  
        theTile.setShapeType ( shapeType);
        
        theTile.setOpacity (opacity);                
        //theTile.setZIndex(zIndex);
        tileList.addTile(theTile);
        
        theTile.addTile( map, maxZoom, minZoom);   
       
    }
}
/*
//gather the values from checkboxes and create a tile
//tableName: table or view name to get the data
//tableToUpdate: the physical table with the sdo2txt, row_status column. row_status colum will be updated to "READ" once it read from database
function createTile (divId, checkBoxClass, tileId, tableName, tableToUpdate, themeColName, whereColName, shapeType, minZoom, maxZoom, iconType){
    var theTile = null;
    var whereSeperator = "|";        
    
    tileList.deleteTileById(tileId);       
    var whereValues = checkBoxesToWhereValues(divId, checkBoxClass,whereSeperator);
            
    if (whereValues!="") {
        theTile = new VMTile(map, tileId);
        
        theTile.setTableName ( tableName);   
        theTile.setTableToUpdate(tableToUpdate);         
        theTile.setThemeColName ( themeColName);            
        theTile.setWhereColName(whereColName);          
        theTile.setWhereValues(whereValues);            
        theTile.setWhereSeperator(whereSeperator);                  
        theTile.setShapeType ( shapeType);
        theTile.setIconType(iconType);
        theTile.setOpacity (opacity);                
        //theTile.setZIndex(zIndex);
        tileList.addTile(theTile);
        
        theTile.addTile( map, maxZoom, minZoom);         
    }
}
*/

/*********** tile manager **************/
function switchTiles(id1, id2){
    alert (id1);
    alert(id2);
    tileList.switchZIndex(id1,id2);
}


/***************************** deal with 3D mode */
//this is not working yet, the ifram show up blank
//and if you use AddControl to map, it move the control around
//possible issue: need a deep copy of element to add it to shim and remove it from its parent node
function addControl(id){    
    var el = document.getElementById(id);    
    //map.AddControl(el);
    addShim(el,id + "Shim");    
}

function addShim(el,sid)  //add iframe shim       
{   
        var s = document.createElement("iframe");            
        s.id = sid;            
        s.frameBorder = "0";            
        s.style.position = "absolute";            
        s.style.zIndex = "1";            
        s.style.top  = el.offsetTop;            
        s.style.left = el.offsetLeft;            
        s.width  = el.offsetWidth;            
        s.height = el.offsetHeight;
        //s.allowtransparency = "true";  
        s.scrolling="no";
        s.className="Shim";
        el.shimElement = s;      
        alert (el.parentNode.nodeName);
        el.parentNode.insertBefore(s, el);   
    
}

function getMapView()
         {
            var view = map.GetMapView();
            var topleft = view.TopLeftLatLong;
            var bottomright = view.BottomRightLatLong;
            
            document.getElementById("txtMaxX").value = bottomright.Longitude;
            document.getElementById("txtMinY").value = bottomright.Latitude;
            
            document.getElementById("txtMinX").value = topleft.Longitude;
            document.getElementById("txtMaxY").value = topleft.Latitude;
            
            
         }  



         

/**************************************************************/
/**************************************************************/
/**************************************************************/


/****************** High Schools*************************/
var hs = null;
function addHS(){
    displayMsgBox("Loading data, please wait.....!");
    if (hs){
        hs.deleteShapes();
        hs = null;
    }    
    hs = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("hsZoomToBound").checked;
    hs.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("HS", "HS_CHECKBOX","city_id");
    var iconType = "FLAG";
    var sameIcon = false;
    if (whereClause !=""){
        var displayColNames = new Array("name", "etc_cd", "address", "city", "zip", "state", "cd");    
        //alert ('where clause:' + whereClause);
        hs.importPinsFromDB("select id, name, address, city, zip, st as state, cd, lat, lng  from hs where " + whereClause , "HIGH SCHOOL",  "city", displayColNames, iconType,sameIcon);                
    }
    hideMsgBox();    
}     


/*************** us county ***********************/
function addUSCountyTile(){
        var divId = "USCOUNTY";
        var checkBoxClass = "USCOUNTY_CHECKBOX";        
        
        var tileId = "USCOUNTY";
        var tableName = "US_COUNTY";
        var tableToUpdate = "US_COUNTY";
        var themeColName = "POLY_ID";
        var whereColName = "POLY_ID";
        var shapeType = "POLYGON";
        
        createTileOfShapes (divId, checkBoxClass, tileId, tableName, tableToUpdate, themeColName, whereColName, shapeType, minZoom, maxZoom);                   
        
}

/****************** County Seat*************************/
var countyseat = null;
function addCountySeat(){
    displayMsgBox("Loading data, please wait.....!");
    if (countyseat){
        countyseat.deleteShapes();
        countyseat = null;
    }    
    countyseat = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("countyseatZoomToBound").checked;
    countyseat.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("COUNTYSEAT", "COUNTYSEAT_CHECKBOX","ID");
    var iconType = "TRIANGLE";
    var sameIcon = false;
    if (whereClause !=""){
        var displayColNames = new Array("seat_name", "county", "zip", "state");    
        //alert ('where clause:' + whereClause);
        countyseat.importPinsFromDB("select id, seat_name, cnty as county, zip, st as state, lat, lng  from us_county_seat where " + whereClause , "COUNTY SEAT",  "ID", displayColNames, iconType,sameIcon);                
    }
    hideMsgBox();    
}     

/****************** DOJOS Karate Schools (AKA) *************************/
var dojos = null;
function addDOJOS(){
    displayMsgBox("Loading data, please wait.....!");
    if (dojos){
        dojos.deleteShapes();
        dojos = null;
    }    
    dojos = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("dojosZoomToBound").checked;
    dojos.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("DOJOS", "DOJOS_CHECKBOX","ID");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "KARATE SCHOOL";
    var themeColName = "ICON_FILE";
    
    if (whereClause !=""){
        var displayColNames = new Array("country", "school", "aka_status", "chief_instructor", "website","phone", "email", "addr", "city", "state", "postal");    
        //alert ('where clause:' + whereClause);
        dojos.importPinsFromDB("select id, country, school, aka_status, chief_instructor, website, phone, email, addr, city, st as state, postal, lat, lng, icon_file  from dojos where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();    
}     

/*************** us congr ***********************/
function addUSCongrTile(){
        var divId = "USCONGR";
        var checkBoxClass = "USCONGR_CHECKBOX";        
        
        var tileId = "USCONGR";
        var tableName = "US_CONGR";
        var tableToUpdate = "US_CONGR";
        var themeColName = "";
        var colorHexColName = "COLOR_HEX";
        var whereColName = "MI_PRINX";
        var shapeType = "POLYGON";
        
        
        
        createTileOfShapes (divId, checkBoxClass, tileId, tableName, tableToUpdate, themeColName, whereColName, shapeType, minZoom, maxZoom, colorHexColName);                   
        
}
/*************** peum naa ***********************/
function addPeumNAA(){
        var divId = "PEUMNAA";
        var checkBoxClass = "PEUMNAA_CHECKBOX";        
        
        var tileId = "PEUMNAA";
        var tableName = "PEUM_NAA";
        var tableToUpdate = "PEUM_NAA";
        var themeColName = "MI_PRINX";
        var colorHexColName = "COLOR_HEX";
        var whereColName = "MI_PRINX";
        var shapeType = "POLYGON";
        
        //change the opacity for this layer only
        var temp = opacity ;
        opacity = 0.5;
        createTileOfShapes (divId, checkBoxClass, tileId, tableName, tableToUpdate, themeColName, whereColName, shapeType, minZoom, maxZoom, colorHexColName);                   
        opacity = temp;
        
}

/****************** Car Washes / Car Wash *************************/
var carwash = null;
function addCarWash(){
    displayMsgBox("Loading data, please wait.....!");
    if (carwash){
        carwash.deleteShapes();
        carwash = null;
    }    
    carwash = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("carwashZoomToBound").checked;
    carwash.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("CARWASH", "CARWASH_CHECKBOX","ID");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "CAR WASH";
    var themeColName = "icon_file";
    
    if (whereClause !=""){
        var displayColNames = new Array("brand", "company_name", "address", "city", "st","zip", "contact_title", "last_name", "first_name", "ll_phone", "supplier", "volume");    
        //alert ('where clause:' + whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        carwash.importPinsFromDB("select brand, company_name, address, city, st,zip, contact_title, last_name, first_name, ll_phone, supplier, volume, lat, lng, icon_file  from car_washes where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();    
}     

/****************** Parent owned stores *************************/
var parentOwnedStores = null;
function addParentOwnedStores(){
    displayMsgBox("Loading data, please wait.....!");
    if (parentOwnedStores){
        parentOwnedStores.deleteShapes();
        parentOwnedStores = null;
    }    
    parentOwnedStores = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("parentOwnedStoresZoomToBound").checked;
    parentOwnedStores.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("PARENTOWNEDSTORES", "PARENTOWNEDSTORES_CHECKBOX","ID");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "PARENT-OWNED STORE";
    var themeColName = "icon_file";
    
    if (whereClause !=""){
        var displayColNames = new Array("brand", "address", "city", "st","zip", "ll_phone", "prev_owner");    
        //alert ('where clause:' + whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        parentOwnedStores.importPinsFromDB("select brand, address, city, st,zip, ll_phone, prev_owner, lat, lng, icon_file  from parent_owned_stores where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();    
}     


/****************** Car Washes / Car Wash *************************/
var lube = null;
function addLube(){
    displayMsgBox("Loading data, please wait.....!");
    if (lube){
        lube.deleteShapes();
        lube = null;
    }    
    lube = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("lubeZoomToBound").checked;
    lube.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("LUBE", "LUBE_CHECKBOX","ID");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "LUBE SITE";
    var themeColName = "icon_file";
    
    if (whereClause !=""){
        var displayColNames = new Array("company_name", "address", "city", "st","zip", "contact_title", "last_name", "first_name", "ll_phone", "supplier", "volume");    
        //alert ('where clause:' + whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        lube.importPinsFromDB("select brand_cat, company_name, address, city, st,zip, contact_title, last_name, first_name, ll_phone, supplier, volume, lat, lng, icon_file  from lube_sites where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();    
}     


/****************** ROTC BASE*************************/
var rotcbase = null;
function addROTCBase(){
    displayMsgBox("Loading data, please wait.....!");
    if (rotcbase){
        rotcbase.deleteShapes();
        rotcbase = null;
    }    
    rotcbase = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("rotcbaseZoomToBound").checked;
    rotcbase.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("ROTCBASE", "ROTCBASE_CHECKBOX","mi_prinx");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "ROTC BASE COLLEGE";
    var themeColName = "icon_file";
    
    if (whereClause !=""){
        var displayColNames = new Array("name", "base", "address", "city", "st","zip");    
        //alert ('where clause:' + whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        rotcbase.importPinsFromDB("select mi_prinx, name, address, city, st,zip, base, lat, lng, icon_file  from colleges_base where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();       
}     

/****************** ROTC SAT*************************/
var rotcsat = null;
function addROTCSat(){
   displayMsgBox("Loading data, please wait.....!");
    if (rotcsat){
        rotcsat.deleteShapes();
        rotcsat = null;
    }    
    rotcsat = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("rotcsatZoomToBound").checked;
    rotcsat.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("ROTCSAT", "ROTCSAT_CHECKBOX","mi_prinx");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "ROTC SATELLITE COLLEGE";
    var themeColName = "icon_file";
    
    if (whereClause !=""){
        var displayColNames = new Array("name","address", "city", "st","zip", "base");    
        //alert ('where clause:' + whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        rotcsat.importPinsFromDB("select mi_prinx, name, address, city, st,zip, base, lat, lng, icon_file  from colleges_sat where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();       
}     

/****************** PEUM Customers*************************/
var peumcust = null;
function addPEUMCust(){
    displayMsgBox("Loading data, please wait.....!");
    if (peumcust){
        peumcust.deleteShapes();
        peumcust = null;
    }    
    peumcust = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("peumcustZoomToBound").checked;
    peumcust.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("PEUMCUST", "PEUMCUST_CHECKBOX","sales_ref_id");
    var iconType = "TRIANGLE";
    var sameIcon = false;
    var title = "CUSTOMER SITE";
    var themeColName = "sales_ref_id";
    if (whereClause !=""){
        var displayColNames = new Array("sales_rep","station_nm", "address", "city", "st","zip", "cust_site_id", "brand", "contact", "ll_phone", "mbl_phone");    
        //alert ('where clause:' + whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        peumcust.importPinsFromDB("select sales_rep, sales_ref_id, station_nm, address, city, st,zip, cust_site_id, brand, contact, ll_phone, mbl_phone, lat, lng, sales_ref_id  from peum_customers where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();    
}     

/****************** PEUM Customers by brand*************************/
var peumcustbrand = null;
function addPEUMCustBrand(){
    displayMsgBox("Loading data, please wait.....!");
    if (peumcustbrand){
        peumcustbrand.deleteShapes();
        peumcustbrand = null;
    }    
    peumcustbrand = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("peumcustbrandZoomToBound").checked;
    peumcustbrand.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("PEUMCUSTBRAND", "PEUMCUSTBRAND_CHECKBOX","brand");
    var iconType = "CUSTOM";
    var sameIcon = false;
    var title = "CUSTOMER SITE";
    var themeColName = "icon_file_brand";
    if (whereClause !=""){
        var displayColNames = new Array("sales_rep","station_nm", "address", "city", "st","zip", "cust_site_id", "brand", "contact", "ll_phone", "mbl_phone");    
        //prompt ('where clause:',whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        peumcustbrand.importPinsFromDB("select icon_file_brand, sales_rep, sales_ref_id, station_nm, address, city, st,zip, cust_site_id, brand, contact, ll_phone, mbl_phone, lat, lng, sales_ref_id  from peum_customers where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();    
}     


/****************** peum competitives*************************/
var peumcomp = null;
function addPEUMComp(){
   displayMsgBox("Loading data, please wait.....!");
    if (peumcomp){
        peumcomp.deleteShapes();
        peumcomp = null;
    }    
    peumcomp = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("peumcompZoomToBound").checked;
    peumcomp.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("PEUMCOMP", "PEUMCOMP_CHECKBOX","brand_status");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = false;
    var title = "COMPETITIVE SITE";
    var themeColName = "icon_file_visit_status";    
    
    if (whereClause !=""){
        var displayColNames = new Array("brand", "contact_date", "station_nm", "owner", "address", "city", "st","zip", "prospective_parent_reps", "ll_phone", "mbl_phone", "avail_date", "supplier", "volume", "ownership", "comp_status", "wash", "bays", "qsr", "dsl", "visit_status");    
        //alert ('where clause:' + whereClause);
        //      importPinsFromDB(sqlClause, theTitle, theThemeColName, theDisplayColNames,theIconType, theSameIcon)
        peumcomp.importPinsFromDB("select brand, cast(CONTACT_DATE as char) as contact_date, station_nm, owner, address, city, st,zip, prospective_parent_reps, ll_phone, mbl_phone, cast(avail_date as char) as avail_date, supplier, volume, ownership, comp_status, wash, bays, qsr, dsl, visit_status, lat, lng,icon_file_visit_status  from peum_competitives where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();      
}     


/*************** big3 ***********************/
//tile of point requirement:
// MI_PRINX, ROW_STATUS must be there
// for iconType = "CUSTOM" if sameicon = false -> icon file name must be value in "themcolname" + ".png"
//                          if it is same icon, iconFileName = tileId + ".png"
//iconTYpe can be random too

function addBig3(){
        var divId = "BIG3";
        var checkBoxClass = "BIG3_CHECKBOX";        
        
        var tileId = "BIG3";
        var tableName = "big3";
        var tableToUpdate = "big3";
        var themeColName = "brand_visit_status";        //icon file name must be value "themecolname" + ".png"
        var colorHexColName = null;
        var whereColName = "brand_visit_status";
        var shapeType = "POINT";
        var iconType = "CUSTOM";
        var sameIcon = false;                       // if it is same icon, iconFileName = tileId + ".png"
        
        
        
        createTileOfPoints (divId, checkBoxClass, tileId, tableName, themeColName, whereColName, minZoom, maxZoom, iconType, sameIcon)
        
        
}

/****************** tax point*************************/
var taxPoint = null;
function addTaxPoint(){
    displayMsgBox("Loading data, please wait.....!");
    if (taxPoint){
        taxPoint.deleteShapes();
        taxPoint = null;
    }    
    taxPoint = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("taxpointZoomToBound").checked;
    taxPoint.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("TAXPOINT", "TAXPOINT_CHECKBOX","city_id");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "TAX POINT";
    var themeColName = "ICON_FILE";
    
    if (whereClause !=""){
        
        var displayColNames = new Array("city", "county", "STATE","CURRENCY", "COUNTY_TAX", "CITY_TAX","SALES_TAX");    
        //alert ('where clause:' + whereClause);        
        taxPoint.importPinsFromDB("select city_id, city, county, state, currency, county_tax, city_tax, sales_tax, lng, lat, icon_file from tax_points where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();      
}     


/****************** tax point*************************/
var parentHQ = null;
function addParentHQ(){
    displayMsgBox("Loading data, please wait.....!");
    if (parentHQ){
        parentHQ.deleteShapes();
        parentHQ = null;
    }    
    parentHQ = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("parenthqZoomToBound").checked;
    parentHQ.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("PARENTHQ", "PARENTHQ_CHECKBOX","office_id");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "PARENT PETROLEUM'S OFFICE";
    var themeColName = "ICON_FILE";
    
    if (whereClause !=""){
        var displayColNames = new Array("name", "address", "address2","city", "st", "zip");    
        parentHQ.importPinsFromDB("select office_id, name, address, address2, city, st, zip, lng, lat, icon_file from peum_hq where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
        //alert ('where clause:' + whereClause);
        
    }
    hideMsgBox();      
}     

/****************** petro terminals*************************/
var petroTerminal = null;
function addPetroTerminal(){
    displayMsgBox("Loading data, please wait.....!");
    if (petroTerminal){
        petroTerminal.deleteShapes();
        petroTerminal = null;
    }    
    petroTerminal = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("petroterminalZoomToBound").checked;
    petroTerminal.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("PETROTERMINAL", "PETROTERMINAL_CHECKBOX","term_id");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "PETRO TERMINAL";
    var themeColName = "ICON_FILE";
    
    if (whereClause !=""){
        var displayColNames = new Array("name", "address", "city","tenants");    
        //alert ('where clause:' + whereClause);
        petroTerminal.importPinsFromDB("select term_id, name, address, city, tenants, lng, lat, icon_file from petro_terminals where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();      
}     

/****************** petro terminals*************************/
var petroRefinery = null;
function addPetroRefinery(){
    displayMsgBox("Loading data, please wait.....!");
    if (petroRefinery){
        petroRefinery.deleteShapes();
        petroRefinery = null;
    }    
    petroRefinery = new VMShapeCollection(map);
    var zoomToBound = document.getElementById("petrorefineryZoomToBound").checked;
    petroRefinery.setZoomToBound(zoomToBound);
    
    var whereClause = checkBoxesToWhereClauseShort("PETROREFINERY", "PETROREFINERY_CHECKBOX","refin_id");
    var iconType = "CUSTOM";  //the icon filename must be title + ".png"
    var sameIcon = true;
    var title = "REFINERY";
    var themeColName = "ICON_FILE";
    
    if (whereClause !=""){
        var displayColNames = new Array("name", "brand", "address", "address2", "city", "st");    
        //alert ('where clause:' + whereClause);
        petroRefinery.importPinsFromDB("select refin_id, name, address, address2, city, st, lng, lat, icon_file from refineries where " + whereClause , title,  themeColName, displayColNames, iconType,sameIcon);                        
    }
    hideMsgBox();      
}     

function initPEUM(mapViewMode, centerLat, centerLng, zoomLevel){   
    
    showLayer('ParentHQNag', 'ParentHQTab');
    //Road Shaded Aerial Hybrid Oblique Birdseye BirdseyeHybrid
    //alert (mapViewMode);
    if (mapViewMode == 'HYBRID'){    
        //map.SetMapMode(VEMapMode.Mode2D);    
        map.SetMapStyle(VEMapStyle.Hybrid);       
    }else if (mapViewMode == 'AERIAL'){
        map.SetMapMode(VEMapMode.Mode2D);    
        map.SetMapStyle(VEMapStyle.Aerial);
    }else if (mapViewMode == 'BIRDSEYE'){
        map.SetMapMode(VEMapMode.Mode2D);    
        map.SetMapStyle(VEMapStyle.Birdseye);
    }else if (mapViewMode == 'BIRDSEYEHYBRID'){
        map.SetMapMode(VEMapMode.Mode2D);    
        map.SetMapStyle(VEMapStyle.BirdseyeHybrid);
    }else if (mapViewMode == 'OBLIQUE'){
        map.SetMapMode(VEMapMode.Mode2D);    
        map.SetMapStyle(VEMapStyle.Oblique);                
    }else if (mapViewMode == '3D'){
        map.SetMapMode(VEMapMode.Mode3D);        
    }else {
        map.SetMapMode(VEMapMode.Mode2D);    
        map.SetMapStyle(VEMapStyle.Road);    
    }
   
    //var center = new VELatLong(centerLat, centerLng);
    var lat = 1*centerLat;
    var lng = 1*centerLng;
    var zoom = 1*zoomLevel;
    var center = new VELatLong(lat, lng);    
    map.SetZoomLevel (zoom);
    
    map.SetCenter (center);    
            
    document.getElementById("parenthqZoomToBound").checked  = false;
    toggleBoxes('PARENTHQ','PARENTHQ_CHECKBOX', true);
    addParentHQ();
    
    
    
}