function DeleteRegistryItem(idx) { 
  var msg = "Are you sure that you want to\n" +
            "delete this item from your registry?\n";
  if(confirm(msg)) {
    var url = "/cgi-local/Registry.cgi?m=EditItem&Action=Delete&idx=" + idx;
    location.replace(url);
  }
}


function RemoveTempBookmark(idx) { 
  var msg = "Are you sure that you want to\n" +
            "delete this item from your saved gifts?\n";
  if(confirm(msg)) {
    var url = "/cgi-bin/Bookmarks.cgi?m=RemoveTemp&idx=" + idx;
    location.replace(url);
  }
}


function DeleteBookmark(idx,product_id,return_url) { 
  var msg = "Clicking the 'OK' button will completely delete this item from your saved gifts.\n\n" +

            "Are you sure you want to completely delete this item?\n";

  var msg2 = "Are you sure you want to delete this item?\n";

  if (product_id != '') {
     if(confirm(msg)) {
        var url = "/cgi-bin/Bookmarks.cgi?m=EditItem&Action=Delete&idx=" + idx + "&pid=" + product_id + "&RURL=" + return_url;
        location.replace(url);
     }
  } else {
     if(confirm(msg2)) {
        var url = "/cgi-bin/Bookmarks.cgi?m=EditItem&Action=Delete&idx=" + idx + "&RURL=" + return_url;
        location.replace(url);
     }
  }
}


function DeleteRecipientProfile(idx) { 
  var msg = "Are you sure that you want to delete\n" +
            "this profile from your recipient list?\n";
  if(confirm(msg)) {
    var url = "/cgi-bin/Gifts.cgi?m=Delete_Profile&idx=" + idx;
    location.replace(url);
  }
}


function AddToRegistry(product_id) { 
  var url = "/s/?m=Gift_Registry_Confirm&pid=" + product_id;
  var win =  window.open(url,"Preview","width=550,height=350,top=100,left=250");
  win.focus();
}


function AddToBookmarks(product_id,recipient_id) { 
  var url = "/s/?m=Save_Gift_Confirm_M&pid=" + product_id;
  var win =  window.open(url,"Preview","width=550,height=350,top=100,left=250");
  win.focus();
}


function SaveGift(product_id,vector) { 
  var url = "/cgi-bin/Save_Gift.cgi?m=Save&pid=" + product_id + "&vector=" + vector;
  var win =  window.open(url,"Preview","resizable,scrollbars,width=400,height=450,top=50,left=50");
  win.focus();
}


function EmailGift(product_id,vector) { 

  if (vector == undefined || vector == null) {
     vector = '';
  }

  var url = "/s/?m=Email_Gift_Confirm&pid=" + product_id + "&vector=" + vector;
  var win =  window.open(url,"Preview","width=550,height=350,top=100,left=250");
  win.focus();
}


function Save(product_id,vector) { 

  if (vector == undefined || vector == null) {
     vector = '';
  }

  var url = "/s/?m=Save_Options&pid=" + product_id + "&vector=" + vector;
  var win =  window.open(url,"Preview","width=550,height=350,top=100,left=250");
  win.focus();
}


function Save_b(product_id,vector,funct) { 

  if (vector == undefined || vector == null) {
     vector = '';
  }

  var url = "/s/?m=Save_Options&pid=" + product_id + "&vector=" + vector + "&funct=" + funct;
  var win =  window.open(url,"Preview","width=550,height=350,top=100,left=250");
  win.focus();
}


function popUp(url,name,w,h,x,y,addOpt) {
  var win =  window.open(url,name,'status=no,width=' + w + ',height=' + h + ',top=' + y + ',left=' + x + addOpt);
  win.focus();
}


function popUp_b(url,name,w,h,x,y,xOffset,yOffset,tool,scroll,resize,stat,addOpt) {

  var width = w;
  var height = h;
  var x = 0;
  var y = 0;
  var xOffset = xOffset;
  var yOffset = yOffset;
  var toolbar = tool;
  var scrollbars = scroll;
  var resizable = resize;
  var status = stat;

  if (typeof window.screenLeft != "undefined") { //IE
     x = window.screenLeft;
     y = window.screenTop - 100;
  }
  else if (typeof window.screenX != "undefined") { //NS/Moz
     x = window.screenX;
     y = window.screenY;
  }
  
  if (x < 0) { x = 0; }
  if (y < 0) { y = 0; }

  x = String(x + xOffset);
  y = String(y + yOffset);

  var params = "width=" + width +
    ",height=" + height +
    ",toolbar=" + toolbar +
    ",menubar=" + toolbar +
    ",location=" + toolbar +
    ",scrollbars=" + scrollbars +
    ",resizable=" + resizable +
    ",status=" + status +
    ",screenX=" + x + ",screenY=" + y + ",top=" + y + ",left=" + x;

  var popup = window.open(url, '_blank', params);
  popup.focus();
}


function CountCharacters(field,max_characters,output_field) { 

  if (field.value.length > max_characters) {
    field.value = field.value.substring(0,max_characters);
    alert("The maximum number of characters is " + max_characters);
  }

  output_field.value=field.value.length;

}


function CountChars(field,max_characters,output_field) { 

  if (field.value.length > max_characters) {
    field.value = field.value.substring(0,max_characters);
    alert("The maximum number of characters is " + max_characters);
  }

  document.getElementById(output_field).innerHTML = field.value.length;

}


function DisplayHelpWindow(message_id,section_id,page_id) { 
  var url = "/cgi-bin/Help.cgi?m=Help_Message&mesgid=" + message_id + "&secid=" + section_id + "&pagid=" + page_id;
  var win =  window.open(url,"Preview","resizable,scrollbars,width=450,height=420,top=95,left=95");
  win.focus() ;
}


function open_div(div_field) { 

  var element = document.getElementById(div_field);
  var element_h = document.getElementById(div_field + "_h");

  element.style.display = "none";
  element_h.style.display = "";

  element.style.visibility = "hidden";
  element_h.style.visibility = "visible";

}


function close_div(div_field) { 

  var element = document.getElementById(div_field);
  var element_h = document.getElementById(div_field + "_h");

  element.style.display = "";
  element_h.style.display = "none";

  element.style.visibility = "visible";
  element_h.style.visibility = "hidden";

}


function noEnter () {

   return !(window.event && window.event.keyCode == 13);

}


function formQuoteValue (formValue) {

   return formValue.replace(/\"/g,'&quot;');

}


function toggle(obj) {

  var element = document.getElementById(obj);

  if (element.style.display == 'none' || element.style.visibility == 'hidden') {

     element.style.display = "";
     element.style.visibility = "visible";

  } else {

     element.style.display = "none";
     element.style.visibility = "hidden";

  }

}


function close_obj(obj) {

  var element = document.getElementById(obj);

  if (element != null) {

     element.style.display = "none";
     element.style.visibility = "hidden";

  }

}


function cB (obj, color) {

   obj.style.backgroundColor = color;

}


function cC (obj, className) {

   obj.setAttribute('class', className);
   obj.setAttribute('className', className);

}


function gT (link) {

   parent.location=link;

}


function giftPopUp(href) {

  var width = '765';
  var height = '600';
  var x = 0;
  var y = 0;
  var xOffset = 50;
  var yOffset = 75;
  var toolbar = 'yes';
  var scrollbars = 'yes';
  var resizable = 'yes';
  var status = 'yes';  
  
  if (typeof window.screenLeft != "undefined") { //IE
     x = window.screenLeft;
     y = window.screenTop - 100;
  }
  else if (typeof window.screenX != "undefined") { //NS/Moz
     x = window.screenX;
     y = window.screenY;
  }
  
  if (x < 0) { x = 0; }
  if (y < 0) { y = 0; }

  x = String(x + xOffset);
  y = String(y + yOffset);

  var param1 = "width=" + width +
    ",height=" + height +
    ",toolbar=" + toolbar +
    ",menubar=" + toolbar +
    ",location=" + toolbar +
    ",scrollbars=" + scrollbars +
    ",resizable=" + resizable +
    ",status=" + status +
    ",screenX=" + x + ",screenY=" + y + ",top=" + y + ",left=" + x;

  if( navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('America Online') == -1 && navigator.userAgent.indexOf('AOL ') == -1) {

     var wnd = window.open('', '_blank', param1);
   
     var rlink = wnd.document.createElement('a');
     rlink.href =  href;
     rlink.target = "_self";
     wnd.document.body.appendChild(rlink);
     rlink.click();
  }else{
     var popup = window.open(href, '_blank', param1);
     if (popup.opener == null) popup.opener = self;
  }

}
