/**
 * user javascript function
 */
 function readListControl(objId,checkBoxesCount,MCount,message,ops)
 {
    //alert(objId)
    obj = document.getElementById(objId)
     //alert(obj);
      
    //alert(checkBoxesCount)
    itemsChecked = 0;
     
    for(i = 0; i < checkBoxesCount; i++)
    {
        objItem = document.getElementById(objId + '_' + i);

        if(objItem == null)
        {
            continue;
        }
        // If i does not equal the checkbox that is never to be disabled.
        if(objItem.checked)
            itemsChecked ++;
     }
     //alert("items checked : " + itemsChecked);
     //alert("Max Count : " + MaxCount);
     if(ops == 0) // max
     {
        if(itemsChecked > MCount) // MCount is either maxcount or mincount
        {
         alert(message);
         return false;
        }  
     }
     else
     {
        if( MCount > itemsChecked)
        {
         alert(message);
         return false;
        }
     }
     
 }
 
        function ValidateTerms(oSrc, args) {
           args.IsValid = (args.Value  == "True");
        }
 function PrintMe()
 {
    window.print();
 }
 function  TipChange(input,toCtl)
 {
    toCtl.value = input.replace("$",'');
 }
 function ConfirmMeWithTip(input)
 {
 
  
    var txtTip = document.getElementById("ctl00_ContentPlaceHolder1_txtTipAmount");
    alert(txtTip);
    alert(txtTip.value);
    if(txtTip.value == 0)
    {
        var name=prompt(input,"Harry Potter");
        if (name!=null && name!="")
        {
            txtTip.value = name;
        }
    }
    //else 
      //  window.confirm(input)   

    return false;
    //debugger use this for javascript debug
    if (window.confirm(input))
    {
    
        return true;
    }
    else
        return false;
 }
 function ConfirmMe(input)
 {
    //debugger use this for javascript debug
    if (window.confirm(input))
        return true;
    else
        return false;
 }
 function StopMe(input)
 {
    //if(input.length
    alert(input);
    return false;
 }
 function AlertMe()
 {
    element1 = document.getElementById('ctl00_ContentPlaceHolder1_ResultMessage1_tblResult');
    element1.style.height = 'auto';
    //element.style.left =  element.style.left + 40 ;
    //alert(element.style.top);
    //alert('from alertme');
 }
 ///// modal
 function modalWin() {
 
    if (window.showModalDialog) {
    window.showModalDialog("menu.aspx","name","dialogWidth:255px;dialogHeight:250px");
    } 
    else 
    {
window.open('menu.aspx','name','height=255,width=250,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes');
}
} 
 
 ////// below for calling webservice
 
 function WebCall()
 {
			PageMethods.GetTime("677", OnComplete, OnError, OnTimeOut);
			
            return false;
    
 }
 function OnComplete(arg)
		{
//            var selectObject = document.getElementById("ctl00_ContentPlaceHolder1_ProductTopDisplay1_NewProductName");
//            
//		    selectObject.innerHTML = arg;
			alert(arg);
		}

		function OnTimeOut(arg)
		{
			alert("timeOut has occured");
		}

		function OnError(arg)
		{
			alert("error has occured: " + arg._message);
		}
		
		
	var oldgridSelectedColor;

function mOv(element)
{
  setMouseOverColor(element)
}
function setMouseOverColor(element) {

try
{
    oldgridSelectedColor = element.style.backgroundColor;
    element.style.backgroundColor='#FF9933';
    element.style.cursor='pointer';
    //element.style.textDecoration='underline';
    element.title='Click to customize this item \r\nAdditional options may be available';
    }
    catch(err)
    {}
}
function setMouseOverColorPlain(element) {

try
{
    oldgridSelectedColor = element.style.backgroundColor;
    element.style.backgroundColor='#FF9933';
    element.style.cursor='pointer';
    //element.style.textDecoration='underline';
    element.title='Click to select this restaurant';
    }
    catch(err)
    {}
}
function mOu(element) 
{
 setMouseOutColor(element) }

function setMouseOutColor(element) {

try
{
    element.style.backgroundColor=oldgridSelectedColor;
    element.style.textDecoration='none';
    hideObject('n1');
    }
    catch(err)
    {}
}
function MIC(eventArgument)
{
  if(BrowserDetect.browser == "Explorer" || BrowserDetect.browser == "Firefox" )
    MenuItemClick( eventArgument);
  else
  {
    var location1 = window.location.protocol + "//" + window.location.host +  window.location.pathname ;
    //alert (" Location " + location);
    location.href=  location1 + "?pid="+eventArgument
  }
}
function MICS(eventArgument) // Self postback
{
 
var location1 = window.location.protocol + "//" + window.location.host +  window.location.pathname ;
  location.href=  location1 + "?pid="+eventArgument+"#Menu"
  
}

function MenuItemClick( eventArgument)
{
    scrollToTop();
    __doPostBack('pid', eventArgument)
}
function scrollToTop()
{
    window.scrollTo(0,0);
}
function scrollToDown()
{
    window.scrollTo(300,300);
}
ns4 = document.layers;
ie4 = document.all;
nn6 = document.getElementById && !document.all;
function showObject1(e1) {
if (ns4) {
     document.n1.visibility = "show";
     document.n1.left = e1.pageX+25;
     document.n1.top = e1.pageY=25;
  }
  else if (ie4) {
     document.all['n1'].style.visibility = "visible";
     document.all['n1'].style.left = e1.clientX + 25;
     document.all['n1'].style.top = e1.clientY + 25;
  }
  else  {
        //alert(document.getElementById('n1').style.left);
     document.getElementById('n1').style.visibility = "visible";
     document.getElementById('n1').style.left = e1.clientX + 25 + 'px';
     document.getElementById('n1').style.top = e1.clientY + 25+ 'px';
  }
}
function showObject(e,objectId) {
   
//   alert(e.pageX);
//   alert(e.clientX);
//   alert(e.clientY);
  if (ns4) {
     document.n1.visibility = "show";
     document.n1.left = e.pageX+25;
     document.n1.top = e.pageY=25;
  }
  else if (ie4) {
     document.all[objectId].style.visibility = "visible";
     document.all[objectId].style.left = e.clientX + 25;
     document.all[objectId].style.top = e.clientY + 25;
  }
  else  {
        //alert(document.getElementById('n1').style.left);
     document.getElementById(objectId).style.visibility = "visible";
     document.getElementById(objectId).style.left = e.clientX + 25 + 'px';
     document.getElementById(objectId).style.top = e.clientY + 25+ 'px';
  }
}
function hideObject(objectId) {
  if (ns4) {
     eval('document.'+ objectId +'.visibility') = "hide";
  }
  else if (ie4) {
     document.all[objectId].style.visibility = "hidden";
  }
  else if (nn6) {
     document.getElementById(objectId).style.visibility = "hidden";
  }
}
function AddToFav()
{
    AddToFav('http://www.Rmeals.com','Order food online from your local restaurants');
}
function AddToFav(linky,BKtitle)
{
var nonie = 'Sorry, only Internet Explorer supports this method to add a bookmark/favourite\n But please feel free to visit the site\'s home page to add favorite'; 

    var title1 = BKtitle;
    var link1 = linky ;
     if (document.all)
    window.external.AddFavorite(link1, title1);
    else if (window.sidebar)
    alert('Due to security restrictions placed in Firefox, we are unable to automatically add a bookmark.\nPlease   press: CTRL+D to add the bookmark manually.');
    else
        alert (nonie);
}
function ShowDeliveryHelp()
{
     var helpText = 'Enter correct delivery street name /Zip only. Address needs to be verified by the software.\n\nYou can enter more information such as company name, driver instruction and etc. at the time of checkout.\n\nIf Yahoo.com can find it, we find it.';
     alert(helpText);
}
function ShowHelp(what)
{
    var helpText = '';
    if(what == 1) // Service Tip
     helpText = 'Rmeals.com brings you this extraordinary service at the negotiated price same as the restaurant or cheaper. To offset the cost, we request you to be generous on optional \'Rmeals.com Tip\'. Thx.';
     else if (what==2) // Delivery Tip
     helpText = 'Please be generous on optional driver tip for the driver who brings you the hot food right off the restaurant';
     else if (what==3) // couponcode help
        helpText = 'If you do not have coupon code, System can generate couponcode for you.'
     else if (what==4) // is it public help
        helpText = 'Selecting this makes the user can see this coupon code while adding items.'
     else if (what==5) // Why e-mail is required
        helpText = 'E-mail is required to identify the user and send and track the order. \n\n It is very important to provide the correct e-mail address.'
         else if (what==6) // Why billing address is required
        helpText = 'Billing address is required for verification only if you decided pay your order by credit card instead of other options such as cash.'
         else if (what==7) // Save Card for future use
        helpText = 'Your entered credit card is encrypted and saved in a secured database and can be used on your future orders. This will speed up your ordering time next time.'
    else
        helpText = what;
     alert(helpText);
     
}

function CategoryChange(obj)
 {
    //alert();
    location.href = '#' + obj.value;
    //if(obj.options.length > -1)
    obj.selectedIndex = 0;
 }
 function ShowMenu(objId)
 {
     tabObj = document.getElementById('tab'+ objId)
    imgObj = document.getElementById('img'+ objId)
    //alert(imgObj.src);
    //obj.style.display='';
    //alert(obj)
    //alert(obj.style)
    //alert(obj.style.display)
    tabObj.style.display = "";
    
//    if(obj.style.display == "none")
//    obj.style.display = "";
//    else
//    obj.style.display = "none";
//   if (document.getElementbyId) { // DOM3 = IE5, NS6 
//    document.getElementbyId('objId').style.visibility = 'hidden'; 
//    } 
//  else { 
//    if (document.layers) { // Netscape 4 
//      //document.hideShow.visibility = 'visible'; 
//    } 
//    else { // IE 4 
//        //document.all.hideShow.style.visibility = 'visible'; 
//      } 
//    }

}
var posx = 0;
var posy = 0;
function getpos(e) {
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    } else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft;
        posy = e.clientY + document.body.scrollTop;
    }
}
function showpic(url) {
    var pic = document.getElementById("pic");
    pic.src = url;

    var picdiv = document.getElementById("picdiv");
    if (posx > 0 && posy > 0) {
        posx = posx - 180;
        posy = posy - 160;
        picdiv.style.top = (posy > 0) ? (posx > (document.body.offsetHeight - 240)) ? (document.body.offsetHeight - 240 - 50) : posy : 15
        picdiv.style.left = (posx > 0) ? (posx > (document.body.offsetWidth - 320)) ? (document.body.offsetWidth - 320 - 50) : posx : 15;
    } else {
        picdiv.style.top = 150;
        picdiv.style.left = 150;
    }

    picdiv.style.visibility = "visible";
}
function hidepic() {
    var picdiv = document.getElementById("picdiv");
    picdiv.style.visibility = "hidden";
}
