/**
*
*  Simple Context Menu
*  http://www.webtoolkit.info/
*
**/

var SimpleContextMenu = {

    // private attributes
    _menus : new Array,
    _attachedElement : null,
    _menuElement : null,
    _preventDefault : true,
    _preventForms : true,


    // public method. Sets up whole context menu stuff..
    setup : function (conf) {
                
        if ( document.all && document.getElementById && !window.opera ) {
            SimpleContextMenu.IE = true;
        }

        if ( !document.all && document.getElementById && !window.opera ) {
            SimpleContextMenu.FF = true;
        }

        if ( document.all && document.getElementById && window.opera ) {
            SimpleContextMenu.OP = true;
        }

        if ( SimpleContextMenu.IE || SimpleContextMenu.FF ) {
           
            document.oncontextmenu = SimpleContextMenu._hide;
            document.onclick = SimpleContextMenu._show;

            if (conf && typeof(conf.preventDefault) != "undefined") {
                SimpleContextMenu._preventDefault = conf.preventDefault;
            }

            if (conf && typeof(conf.preventForms) != "undefined") {
                SimpleContextMenu._preventForms = conf.preventForms;
            }

        }

    },


    // public method. Attaches context menus to specific class names
    attach : function (classNames, menuId) {

        if (typeof(classNames) == "string") {
            SimpleContextMenu._menus[classNames] = menuId;
        }

        if (typeof(classNames) == "object") {
            for (x = 0; x < classNames.length; x++) {
                SimpleContextMenu._menus[classNames[x]] = menuId;
            }
        }

    },


    // private method. Get which context menu to show
    _getMenuElementId : function (e) {

        if (SimpleContextMenu.IE) {
            SimpleContextMenu._attachedElement = event.srcElement;
        } else {
            SimpleContextMenu._attachedElement = e.target;
        }

        while(SimpleContextMenu._attachedElement != null) {
            var className = SimpleContextMenu._attachedElement.className;

            if (typeof(className) != "undefined") {
                className = className.replace(/^\s+/g, "").replace(/\s+$/g, "")
                var classArray = className.split(/[ ]+/g);

                for (i = 0; i < classArray.length; i++) {
                    if (SimpleContextMenu._menus[classArray[i]]) {
                        return SimpleContextMenu._menus[classArray[i]];
                    }
                }
            }

            if (SimpleContextMenu.IE) {
                SimpleContextMenu._attachedElement = SimpleContextMenu._attachedElement.parentElement;
            } else {
                SimpleContextMenu._attachedElement = SimpleContextMenu._attachedElement.parentNode;
            }
        }

        return null;

    },


    // private method. Shows context menu
    _getReturnValue : function (e) {

        var returnValue = true;
        var evt = SimpleContextMenu.IE ? window.event : e;

        if (evt.button != 1) {
            if (evt.target) {
                var el = evt.target;
            } else if (evt.srcElement) {
                var el = evt.srcElement;
            }

            var tname = el.tagName.toLowerCase();

            if ((tname == "input" || tname == "textarea")) {
                if (!SimpleContextMenu._preventForms) {
                    returnValue = true;
                } else {
                    returnValue = false;
                }
            } else {
                if (!SimpleContextMenu._preventDefault) {
                    returnValue = true;
                } else {
                    returnValue = false;
                }
            }
        }

        return returnValue;

    },


    // private method. Shows context menu
    _show : function (e) {

        SimpleContextMenu._hide();
        var menuElementId = SimpleContextMenu._getMenuElementId(e);

        if (menuElementId) {
            var m = SimpleContextMenu._getMousePosition(e);
            var s = SimpleContextMenu._getScrollPosition(e);

            SimpleContextMenu._menuElement = document.getElementById(menuElementId);
            SimpleContextMenu._menuElement.style.right = m.x + s.x + 'px';
            SimpleContextMenu._menuElement.style.top = m.y + s.y + 'px';
            SimpleContextMenu._menuElement.style.display = 'block';
            
            return false;
        }

        return SimpleContextMenu._getReturnValue(e);

    },


    // private method. Hides context menu
    _hide : function () {

        if (SimpleContextMenu._menuElement) {
            SimpleContextMenu._menuElement.style.display = 'none';
        }

    },


    // private method. Returns mouse position
    _getMousePosition : function (e) {

        e = e ? e : window.event;
        var position = {
            'x' : e.clientX,
            'y' : e.clientY
        }

        return position;

    },


    // private method. Get document scroll position
    _getScrollPosition : function () {

        var x = 0;
        var y = 0;
        if( typeof( window.pageYOffset ) == 'number' ) {
            x = window.pageXOffset;
            y = window.pageYOffset;
        } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
         
            x = document.documentElement.scrollLeft;
            y = document.documentElement.scrollTop;
        } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
            x = document.body.scrollLeft;
            y = document.body.scrollTop;
        }

        var position = {
            'x' : x,
            'y' : y
        }

        return position;

    }

}

function showDatabrwse(str)
{
   var Cstr
   document.getElementById('schWell').style.display = 'none'
   document.getElementById('welItemBW').style.display = 'block'
   document.getElementById("txtbrwse").value=str
   document.getElementById("wellDWV").innerHTML = str
   if (str == "Voices")
         Cstr = "Voice"
   else if (str == "Wishes")
        Cstr = "Wish"
   else if (str == "Dishes")
       Cstr = "Dish"
   else
       Cstr = "All" 
   document.getElementById("hbrwse").value=Cstr   
   showBold()   
      
}

function showDatacatagry(str)
{
   document.getElementById('schWell').style.display = 'none'
   document.getElementById('welItemCatg').style.display = 'block'
    document.getElementById("txtcatory").value=str
    document.getElementById("wellCatg").innerHTML=str
   showBold()
}


function showDataArea(str)
{
  document.getElementById('schWell').style.display = 'none'
  document.getElementById('welItemAREA').style.display = 'block'
    document.getElementById("txtarea").value=str
    document.getElementById("wellArea").innerHTML=str
    showBold()
}


function showDataDistance(str)
{
    document.getElementById('schWell').style.display = 'none'
    document.getElementById('welItemDIS').style.display = 'block'
    document.getElementById("txtdistance").value=str
    document.getElementById("wellDistance").innerHTML=str
    showBold()
}


function onLod()
{
   document.getElementById("txtarea").value="AREA"
   document.getElementById("txtbrwse").value="BROWSE"
    document.getElementById("hbrwse").value=""
   document.getElementById("txtcatory").value="CATEGORY"
   document.getElementById("txtdistance").value="DISTANCE"
   document.getElementById("txtzip").value=""
   document.getElementById("txtcity").value=""
   document.getElementById("txtkeyword").value=""
}


function removeItem(id,cntID)
{ 
    if( id == "wellDWV")
    {
       document.getElementById(id).innerHTML = "BROWSE"
       document.getElementById(cntID).value = "BROWSE"
       document.getElementById('welItemBW').style.display = 'none'
    }
    else if( id == "wellCatg")
    {
       document.getElementById(id).innerHTML = "CATEGORY"
       document.getElementById(cntID).value = "CATEGORY"
       document.getElementById('welItemCatg').style.display = 'none'
    }
    else if( id == "wellArea")
    {
       document.getElementById(id).innerHTML = "AREA"
       document.getElementById(cntID).value = "AREA"
       document.getElementById('welItemAREA').style.display = 'none'
    }
    else if( id == "wellDistance")
    {
       document.getElementById(id).innerHTML = "DISTANCE"
       document.getElementById(cntID).value = "DISTANCE"
       document.getElementById('welItemDIS').style.display = 'none'
    }
    else if( id == "wellKeyWord")
    {
       document.getElementById(id).innerHTML = ""
       document.getElementById(cntID).value = ""
       document.getElementById('welItemKW').style.display = 'none'
    }
    else if( id == "wellZip")
    {
       document.getElementById(id).innerHTML = ""
       document.getElementById(cntID).value = ""
       document.getElementById('welItemZIP').style.display = 'none'
    }
    else if( id == "wellCity")
    {
       document.getElementById(id).innerHTML = ""
       document.getElementById(cntID).value = ""
       document.getElementById('welItemCITY').style.display = 'none'
    }
    
    
       
           
    
    
    
   checkFlag()
}

function checkFlag()
{
  var cty=document.getElementById('welItemCITY').style.display
  var zip=document.getElementById('welItemZIP').style.display
  var kWord=document.getElementById('welItemKW').style.display
  var dis=document.getElementById('welItemDIS').style.display
  var area=document.getElementById('welItemAREA').style.display
  var catg=document.getElementById('welItemCatg').style.display
  var bw=document.getElementById('welItemBW').style.display
  if( cty=='none' && zip=='none' && kWord=='none' && dis=='none' && area=='none' && catg=='none' && bw=='none')
  {
    document.getElementById('schWell').style.display = 'block'
     var objsearchbtn =document.getElementById('imgSearch');
     objsearchbtn.src='images/search_bt.gif';
  }
}

function fillWellData(id)
{
    document.getElementById('schWell').style.display = 'none'
    if (id == "txtcity")
    {
     var val = document.getElementById(id).value
     if(val.length < 16)
     {
         var retval=CharsOnly("txtcity")
	    if(retval==true)
	    {
         document.getElementById("wellCity").innerHTML = val
         document.getElementById('welItemCITY').style.display = 'block'
         }
     }     
     else if(val.length > 14)
        {   
            var val = document.getElementById(id).value    
            document.getElementById("wellCity").innerHTML = val.substring(0,13)+'....'
        }
     
    }
    else if(id == "txtzip")
    {  
    var val = document.getElementById(id).value
    var retval=CheckSpecialSearch("txtzip")
	if(retval==true)
	{
        document.getElementById("wellZip").innerHTML = val
        document.getElementById('welItemZIP').style.display = 'block'
    }
    
    }
    else if(id == "txtkeyword")
    {

    var val = document.getElementById(id).value
    if(val.length < 13)
    {
    document.getElementById("wellKeyWord").innerHTML = val
    }
    else if(val.length > 14)
    {       
        document.getElementById("wellKeyWord").innerHTML = val.substring(0,13)+'....'
    }
    
    document.getElementById('welItemKW').style.display = 'block'
    }
    // Bold Search button
    
    
     var objsearchbtn =document.getElementById('imgSearch');
     objsearchbtn.src='images/search_bt_bold12.gif';
    
}

function NumericOnlyVal(ID)
{
       var x2 = document.getElementById(ID);
       var webValue = x2.value; 
       var flag = 0; 
        var xChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.`'~!@#$%^&*()+=[]\\\;-_/{}|\":<>?"; 
        for (var i = 0; i < webValue.length; i++) 
            {
             if (xChars.indexOf(webValue.charAt(i)) != -1) 
                 {    
                    if(i==0)
                    {
                    xValue=""
                    }        
                    flag = 1;
                    break;                                 
                 }       
            }
              if(flag == 1)
              {
               x2.value = xValue1; 
               return false;     
              } 
              else
              {
              xValue1=webValue
               return true;
              }
 }
 function CharsOnly(id)
    {

    var x2 = document.getElementById(id);
    var webValue = x2.value; 
    var flag = 0;              
    var xChars = "0123456789`~!@#$%^'&*()+=[]\\\;/{}|\",:<>?'"; 
    for (var i = 0; i < webValue.length; i++) 
    {  
    if (xChars.indexOf(webValue.charAt(i)) != -1) 
    {     
    if(i==0)
    {
    yValue=""
    }   
    flag = 1;
    break;                                 
    }       
    }
    if(flag == 1)
    {
    x2.value = yValue; 
    return false;     
    } 
    else
    {
    yValue=webValue
    return true;
    }                              
  }  
  
  function CheckSpecialSearch(id)
    {

    var x2 = document.getElementById(id);
    var webValue = x2.value; 
    var flag = 0;              
    var xChars = "`~!@#$%^'&*()+=[]\\\;/{}|\",:<>?'"; 
    for (var i = 0; i < webValue.length; i++) 
    {  
    if (xChars.indexOf(webValue.charAt(i)) != -1) 
    {     
    if(i==0)
    {
    yValue=""
    }   
    flag = 1;
    break;                                 
    }       
    }
    if(flag == 1)
    {
    x2.value = yValue; 
    return false;     
    } 
    else
    {
    yValue=webValue
    return true;
    }                              
  }  
  
  