var selectedRowID = -1;
var ctlselectedRow = null;
var pluginPath = null;

  
function ShowUpload(args) {
    var width = 420;
    var height = 450;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top + ",toolbars=no,menubar=no,location=no,status=no"; //"";
    var url = "http://" +  window.location.host + "/wp-content/plugins/eshop/deliverylist/ajaxupload/index.php";
  //  alert("showupload args = " + args);
    return window.open(url + args ,"dataitem",windowFeatures);
}                          

function ShowServiceAdDetail(serviceAdID)
{  
  
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("divShippingDetail").innerHTML = xmlhttp.responseText; //the response/result must be echoed out.
            document.getElementById('txtFirstName').focus();      
        }
    }
    // alert("http://" + document.domain + "/eshop/deliverylist/deliverylist.class.php");
    //ajx=1 is a flag to signal that it was sent via ajax. need to do this because wordpress won't load the php initialized, so i have to use my own initialized
    //variables.
    
    xmlhttp.open("GET","http://" + window.location.host +  "/wp-content/plugins/eshop/deliverylist/deliverylist.class.php?sel=" + serviceAdID +  "&ajx=1" ,true); //"&cbp=" + cbProd
    xmlhttp.send();
}

function GetServiceAdDetail(row){
    alert("ROW");
     //loop through shipping list and make sure the background colors are reset to unselected color.
     //and remove the astrik
    var tblAd =  document.getElementById('lstServicesAds');
    
    for(i = 0; i < tblAd.rows.length; i++)
    { 
        tblAd.rows[i].bgColor='#eeeef8'; 
        tblAd.rows[i].style.backgroundColor ='#eeeef8'; 
    } 
    
   selectedRowID = row.getAttribute('name');
  
   ShowServiceAdDetail(selectedRowID); //do an ajax load.
  
   if(ctlselectedRow)  //set the selected row back to default color.
   {
        ctlselectedRow.bgColor =  '#ADD8E6';// '#eeeef8';
   }
   ctlselectedRow = row; //now set the newly selected row to the selectedRow variable.
   
   row.bgColor ='#ADD8E6'; //set the newly selected row color to highlight.
   // document.getElementById(shippingID).bgColor='#99CCFF'; 
   row.style.backgroundColor =  '#ADD8E6';//this works for firefox.

}

function SetPluginPath(path)
{
    alert(path);
  //  pluginPath = path;
}

function SetSelectedRowId(rowId)
{
     selectedRowID = rowId;  
}

function ChangeColor(ctl, action)
{
    var mouseOverRowID =  ctl.getAttribute('name');//mouse over row id     
    
        
    switch(action)
    {
       case "over":
            if(selectedRowID != mouseOverRowID )
            {
               ctl.bgColor='#317082';  //works for firefox
            //   ctl.style.background ="red"; 
               
             //  document.getElementById('mouseOverRowID').bgColor = "red"; 
                                            //ctl.style.backgroundColor  ='#317082';
                                                           //ctl.className='td2';

               //td1
            }
        break;
        case "out":
            if(selectedRowID != mouseOverRowID )
            {
               
             // var obj =    document.getElementById('mouseOverRowID');
              // obj.style.background="red";
               ctl.bgColor='#eeeef8'; //works for firefox
             //  ctl.style.background ="black";  
                                            //ctl.style.backgroundColor  ='#eeeef8';
                                                             //ctl.className='td1';
            }
        break;
    }
    
  //  var obj = event.srcElement;
   // alert(obj.tagName);
    
    
 /*  this works for ie maybe query for element .. id='member' name='$shippingid'
 
 event.srcElement  is not null 
 
  var ie = document.all;
    var ns = document.getElementById && !ie;
    var obj = ns ? ctl.target : event.srcElement;
    
    if (obj.tagName=="TD") {
                obj.style.background="red";
                obj.style.background="black"
    }
   */             


}     
      

  
/*function OnChangeCboProducts(cboProducts)
{
    alert("cbo id:" +  cboProducts[cboProducts.selectedIndex].id);
    //++++TEST
    document.getElementById('txtSelectedShippingId').value =  cboProducts[cboProducts.selectedIndex].id;
    
    if(cboProducts[cboProducts.selectedIndex].text.toLowerCase() == "Select a Product To Ship".toLowerCase())
    {
        document.getElementById('btnSaveShipping').style.visibility = 'hidden';  //hide save button
        document.getElementById('btnUpdateShipping').style.visibility='visible'; //show update button
    }
    else   //A customer product was selected to enter shipping details. Hide the update button, and show the save button.
    {
        document.getElementById('btnSaveShipping').style.visibility = 'visible';
        document.getElementById('btnUpdateShipping').style.visibility='hidden'; 
        
        //loop through shipping list and make sure the background colors are reset to unselected color.
        var tblShipping =  document.getElementById('lstShipProducts');
        
        for(i = 0; i < tblShipping.rows.length; i++)
        {
           tblShipping.rows[i].bgColor='#eeeef8'; 
        }
    }
    //if value is not null or text is not select product. then
    //show the save button, hide the update button.
   // document.getElementsByName('btnSaveShipping')[0].style.visibility = 'hidden';

} */
