// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var search_list_count = 0;
var search_list_index = -1;
var guide_rotator_ndex = 0;
function display_ad_result()
{
    $("ad-result").innerHTML = $("widget_code").value
}

// This method is to load the body background image dynamically while page is getting load
function bodybg(source)
{
    document.body.background = source;
}
function validate(email) {
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(email == '') {
        alert('Invalid Email Address');
        return false;
    }else if(email.match(emailRegEx)){
        return true;
    }else{
        alert('Invalid Email Address');
        return false;
    }
}

function loadArticleDetail(event) {
    var target = jQuery(event.target);
    window.location.href = target.val();
	/*
//    This part was used to get the selected article response and to update it in AJAX.
// This requirement has been changes and on select the action will be taken to individual article page.
    var selectedValue = target.val();
    var containerDiv = target.parents("div.rightoverallbox").find("div.rightbottom div.article_detail");
    var _url = '/articles/' + selectedValue + '/article_detail';
    jQuery.ajax({
        type: "GET",
        url: _url,
        dataType: "html",
        success: function(msg) {
            containerDiv.html(msg);
        }     
    });
	*/
}
// Method is used to load the celebrity widget dynamically while selects the value from dropdown
function loadCelebrityDetail(event) {
    var target = jQuery(event.target);
    var selectedValue = target.val();
    window.location.href = selectedValue;
/*
// The followinf code will load the description of selected article
// This  has been commented as the requirement was changed to load to the individual celebrity pick page
    if (target.attr("id") == "tmif_select") {
        var containerDiv = jQuery("#widget_common_tmif");
        var tmif_tm10 = "tmif"
    }
    if (target.attr("id") == "tastemaker_select") {
        var containerDiv = jQuery("#widget_common_tm10");
        var tmif_tm10 = "tm10"
    }

    var _url = '/celebrity-picks/'+selectedValue ;
    jQuery.ajax({
        type: "GET",
        url: _url,
        dataType: "html",
        success: function(msg) {
            containerDiv.html(msg);
        },
        complete: function () {
             GG_Drop.Fancy.init();
            if (tmif_tm10 == "tmif") {
                jQuery("#tmif_select").change(loadCelebrityDetail);
                tmif_description_hide_show();
             }
            if (tmif_tm10 == "tm10")
                jQuery("#tastemaker_select").change(loadCelebrityDetail);
                tm10_description_hide_show();
                
        }
    });
*/
}


function loadMediaSearch(event,action) {
    var target      = jQuery(event.target);
    var search_text  = target.find("#search_text").val();
    var sort_value   = target.find("select").val();
    var mw_id        = target.find("#mw_id").val();
    var media_widget = target.find("hidden").val();
    var resultDiv  = target.parents("div#image_update");
    var _url = '/admin/'+action+'/' + mw_id + '/' + escape(search_text) + '/' + escape(sort_value)
    
    jQuery.ajax( {
        type: "GET",
        url: _url,
        dataType: "html",
        success: function(msg) {
            resultDiv.html(msg);
        }
    });
}


// Script for Slide show in gift of the day widget
function slideshow(val,position,size)
{ 
    var item 
    // count based on postion
    if (position == "next")
        {
            item = val + 1
            if(item == size)
                {
                    // To make a cyclic Next. If it reaches last record then it will rotate from first record.
                    item = 0;
                }
            }
            
            else
                {
                    item = val -1
                    if(item == -1)
                        // To make a cyclic previous. if it reaches first record then it will rotate from last record.
                    item = size -1
                }
                // rotation based on count  
                if (document.getElementById("gotd_"+item))
                    {
                        document.getElementById("gotd_"+val).style.display = "none"
                        document.getElementById("gotd_"+item).style.display = "block"
                    }
                }
                
                
                //Script for Image Rollover for slideshow
                function slideshowRollover(obj,value)
                {
                    obj.src = value;
                }
                
                // Script to replace the src and display a big image for gift of the day widget			
                function show_big_image(index,position)
                {
                    var thumb_container;
                    var selected_hat;
                    var parent;
                    var selected_image;
                    var count;
                    thumb_container = jQuery("#gotd_thumbnail_"+index);
                    selected_hat = thumb_container.find(".hats_selected")
                    for (count = 0 ; count < selected_hat.length ; count ++)
                        {
                            jQuery(selected_hat[count]).removeClass("hats_selected")
                            jQuery(selected_hat[count]).addClass("hats")
                        }
                        selected_image = jQuery("#side_"+index+"_"+position);
                        parent = selected_image.parent();
                        parent.removeClass("hats");
                        parent.addClass("hats_selected");
                        
                        document.getElementById("big_"+index).alt = document.getElementById("side_"+index+"_"+position).alt;
                        src_split = document.getElementById("side_"+index+"_"+position).src.split("/small/");
                        document.getElementById("big_"+index).src = src_split[0]+"/original/"+src_split[1];
                    }
 function controlGiftSearch(index_active){
	var search_area;
	var search_table;
	search_area = jQuery.find("#sp-results");
	search_table = jQuery(search_area[0]).find("table.live_rollover");
	if (search_table.length > 0)
	{
	var aLinks  = search_table.find("a");
	window.location.href = aLinks[0].href;
	}
}                   
                    
/*  Code for Live Search */
function callLiveSearch(event) {
	var app_name;
	var keucode;
	app_name = window.navigator.appName;
			if (app_name == "Microsoft Internet Explorer") {
			keycode = window.event.keyCode; 
			}
			else {
			keycode = event.keyCode; }
	var search_container;
	// Do not consider Control keys Alt Ctrl 
    if (keycode >= 17 &&  keycode <= 20)
		return false;
	// Do not consider Arrow keys
	
	// 38 	Up
	// 40 	Down
	// 39		Right
	// 37		Left
	if ((keycode >= 37 &&  keycode <= 50 )|| keycode == 13 )
	{
		if (keycode == 38 || keycode == 39)
			{
			if (search_list_index - 1 < 0) {
				return false;
			}
			arrowControl(search_list_index - 1 , search_list_index ); 
			}
			
		if (keycode == 40 || keycode == 37)
			{
			if (search_list_index + 1 > search_list_count) {
				return false;
			}
			arrowControl(search_list_index + 1 , search_list_index ); 
			}
		if(keycode == 13){
			var elements = controlGiftSearch(search_list_index);			
		}	
			
		return false;
	}	
	var target      = jQuery.find("#live_search_query");
	var search_text  = target[0].value;
	var searchTimeout = null;
	clearInterval(searchTimeout);
	// Call getSearchResult after a delay of 500 ms
	searchTimeout = setTimeout(getSearchResult,500);
	searchTimeout = null;
	clearInterval(searchTimeout);
}
function getSearchResult()
{
	target      = jQuery.find("#live_search_query");
	search_text  = target[0].value;
    search_list_index = -1;
	
	var oldSearchText;
	oldSearchText = jQuery.find("#old_live_search_query")[0].value;
	// Check whether the search has already made for the string is so return false
	if (search_text == oldSearchText ) {
		return false;
	}
	// Store the updated search string in a hidden field.
	jQuery.find("#old_live_search_query")[0].value = search_text;
	
	
	
	// Generate the url to fire the request.
	var _url = '/live_search/?query='+search_text;
	var search_text_obj = jQuery.find("#live_search_query");
	// Fire an AJAX request
	jQuery.ajax( {
        type: "GET",
        url: _url,
        dataType: "html",
		beforeSend: function() {
			jQuery(search_text_obj[0]).removeClass("txtbox");
			jQuery(search_text_obj[0]).addClass("txtbox_searching");
		} ,
        success: function(msg) {
            document.getElementById("sp-results").innerHTML = msg;
			
        } ,
		complete: function() {
		jQuery("#sp-results").show();
  	    jQuery("#live_search_query").blur(search_clear);
		//jQuery("#sp-results table").click(openSearch);
		jQuery(".live_normal").mouseover(mouseoverfn)
		jQuery(".live_normal").mouseout(mouseoutfn)
			
		var search_area = jQuery.find("#sp-results");
		search_list_count = jQuery(search_area[0]).find("table").length - 1;
			jQuery(search_text_obj[0]).removeClass("txtbox_searching");
			jQuery(search_text_obj[0]).addClass("txtbox");
		}
     } ); 
	 return null;
}
function mouseoverfn()
{
	jQuery("#live_search_query").unbind("blur");
}


function mouseoutfn()
{
	// jQuery("#live_search_query").bind("blur");
	jQuery("#live_search_query").blur(search_clear);
}
function live_search_class(type , obj)
{
var search_area;
var search_table;
var i;
search_area = jQuery.find("#sp-results");
search_table = 	jQuery(search_area[0]).find("table");

for (i=0 ; i <=search_list_count ; i++)
	{
	if (jQuery(search_table[i]).hasClass("live_rollover") )
		{
		jQuery(search_table[i]).removeClass("live_rollover");
		jQuery(search_table[i]).addClass("live_normal");
		}
	}
	
	if (type == 1)
	{
	obj.className = "live_rollover";
	}
	else
	{
	obj.className = "live_normal";
	}
	
for (i=0 ; i <=search_list_count ; i++)
	{
	if (jQuery(search_table[i]).hasClass("live_rollover") )
		search_list_index = i;
	}
	
}

function search_clear(event)
{
	jQuery("#sp-results").hide();
	jQuery.find("#live_search_query")[0].value = jQuery("#searchtext_label").val();
	jQuery.find("#old_live_search_query")[0].value = "";
}
function openSearch(event) {
    jQuery("#live_search_query").unbind("blur");
}

function arrowControl(index_active , index_inactive)
{
var search_area;
var search_table;
search_area = jQuery.find("#sp-results");
search_table = jQuery(search_area[0]).find("table");

jQuery(search_table[index_inactive]).addClass("live_normal");
jQuery(search_table[index_inactive]).removeClass("live_rollover");

jQuery(search_table[index_active]).removeClass("live_normal");
jQuery(search_table[index_active]).addClass("live_rollover");



search_list_index = index_active;
}
/*  Code for Live Search */                    

/* Code for changing image for CMs > Guide widget */
// Date 28 April 2009
function show_guide_image(selObj)
{
    var split;
    var imageCont;
    var image;
    var oldSrc;
    split = selObj.value.split("|");
    imageCont = jQuery.find(".cmsproduct");
    image = jQuery(imageCont[0]).find("img");
    oldSrc = image[0].src.split("/images");
    imageCont[0].style.display = "block";
    image[0].src = oldSrc[0] + split[1];
	if (selObj.value == "0")
                {
                imageCont[0].style.display = "none";
		image[0].src = oldSrc[0] + "/images";
                 }
}
/* End Code */

/*  Code for personality popup in search page */
    function display_popup(event) {
	  var target = event.target
	  var TotalTop = 0;
	  var TotalLeft = 0;
	  var objChild;
	  var app_name = window.navigator.appName;
       if (target.nodeName == "IMG") {
      jQuery("#popup_container").removeClass("display_hide");
      jQuery("#popup_container").addClass("display_show");
      jQuery("#popup_container")[0].style.left = target.offsetLeft + 120 + "px";
      jQuery("#popup_container")[0].style.top = target.offsetTop + "px";
	     if (app_name == "Microsoft Internet Explorer") 
					{
					left_offsetdiff = 0
						objChild = target
						while (objChild)
								{
							 TotalTop = TotalTop + objChild.offsetTop;
							 TotalLeft = TotalLeft + objChild.offsetLeft;
							 objChild = objChild.offsetParent;
								}
							jQuery("#popup_container")[0].style.left = TotalLeft + 120 + "px";
							jQuery("#popup_container")[0].style.top = TotalTop + "px";	
					}
      }
      }
      function closepopArea () {
      jQuery("#popup_container").removeClass("display_show");
      jQuery("#popup_container").addClass("display_hide");
      }
      
/* End Code */

/*  Code to change occasion select dropdown */
function changeOccPage(event)
{
    var slugValue = event.target.value;
    var splitedValue = slugValue.split("**")/*For default occasion image */
    if (splitedValue[0] == 0){
        jQuery("#occsearch").attr("src",splitedValue[1]);
        window.location.href = "/search";
    }
    if (splitedValue[0] != 0) {
        window.location.href = "/occasions/"+slugValue;
    }
    
}

function changePerPage(event)
{
    var slugValue = event.target.value;    
    var splitedValue = slugValue.split("**")/*For default recipient image */
    if (splitedValue[0] == 0){
        jQuery("#persearch").attr("src",splitedValue[1]);
        //window.location.href = "/recipients";
        window.location.href = "/search";
    }
    if (splitedValue[0] != 0) {
        window.location.href = "/recipients/"+slugValue;
    }
}

function showOccasionImage(occId) {
    var occList = jQuery("#occasion_search");
    var options = occList[0]
    var i;
    var img_split;
    for (i=0 ; i < options.length ; i++) {
        img_split = options[i].value.split("-");
        if (img_split[0] == occId) {
            options[i].selected = "selected";
            var selBox =  jQuery(".srch_occimage");
        var occBox = selBox[0].childElements()[0];
        var old_src = occBox.src.split("/images");
        if ( img_split[0] != "0") {
        occBox.src = old_src[0] + img_split[1];
        }
        else {
        occBox.src = old_src[0] + "/images";
        }
        break;
        }
    }
}
/* End Code */

/* Function for Tags in CMS  */
function save_data(obj,id)
{
    var tag = obj.value;
    var giftid=id;  
    if(obj.checked == true)
        {
    var url="/admin/gifts/update/"+giftid+"?tag="+tag+""; 
    new Ajax.Updater('save', url, { method: 'get' });
    }
    else
        {
     var url="/admin/gifts/update/"+giftid+"?delete_tag="+tag+""; 
    new Ajax.Updater('save', url, { method: 'get' });
}}

function closeAdvperson () {
	jQuery("#getAdvPerson")[0].style.display = "none";
}
/*
Added on May 06th 2009 for GIFT Page - Karthi
*/
function ShowAccord(eid){
jQuery('#myAccordion_'+eid).Accordion({headerSelector: 'dt',panelSelector: 'dd',activeClass: 'myAccordionActive',hoverClass:'myAccordionHover',panelHeight:'300',speed:'300'});
jQuery("dl#myAccordion_"+eid+" dt.someClass").each( function(){
      if(jQuery(this).hasClass("myAccordionActive")==false)
           jQuery(this).find("a.gotd_tags1").show();
      else
           jQuery(this).find("a.gotd_tags").show();
});
jQuery("dl#myAccordion_"+eid+" div.category_name").click(function()
{
jQuery("dl#myAccordion_"+eid+" dt.someClass a.gotd_tags").hide();
jQuery("dl#myAccordion_"+eid+" dt.someClass a.gotd_tags1").show();
var h=jQuery(this).children("span").html();
jQuery(this).find("a.gotd_tags").show();
jQuery(this).find("a.gotd_tags1").hide();
});

}

/*
Added on May 11th 2009 for GIFT Page - Gani
*/
function showtwitter() {
//window.open("http://twitthis.com/twit?url="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "TwitThisPop", "width=600, height=500, location, status, scrollbars, resizable");
var url="";
url ="http://twitthis.com/twit?url="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : "");
window.open(url);
//tb_show("Twitter",url+"??TB_iframe=true&height=400&width=570")
}

function showRequestBirthday(id) {
//window.open("http://twitthis.com/twit?url="+encodeURIComponent(location.href)+"&title="+((document.title) ? encodeURIComponent(document.title.replace(/^\s*|\s*$/g,'')) : ""), "TwitThisPop", "width=600, height=500, location, status, scrollbars, resizable");
var url="";
url ="/home/birthday_popup?salt_id="+id;
//window.open(url);

GiftGeniusBox_show("Request Birthday",url+"GiftGeniusBox_iframe=true&height=315&width=345&modal=true");

}

function open_savesearch_popup(salt_id,page_from) {
 var gift_count = 0;

 /*
 // This code is to find only number of gifts in the present page
   if (jQuery("#grid_view").length == 0)
       gift_count = jQuery("#list_view").find("div.srch_rows").length;
   else 
      gift_count = jQuery("#grid_view").find("div.srch_dyimg").length;
  */
  // To find total number of gifts for the search
  gift_count = jQuery("#recordCount").val();
  var result = "";
   result = escape(get_save_search_url());
    if(page_from == 'save_search') { 
    url ="/search/refine_search?query_string="+result+"&gift_count="+gift_count+"&save_text="+salt_id;
   }else {
    url ="/search/refine_search?query_string="+result+"&gift_count="+gift_count+"&salt_id="+salt_id;
   }
 
   jQuery("#search_btn").blur();
  GiftGeniusBox_show("Save search",url+"GiftGeniusBox_iframe=true&height=230&width=340");
}

function showManuallyImport() {
var url="";
url ="/mystuff/manually_import?dummy=0&";
// To deselect the radio button
jQuery("div.friends_import1").find("input#r5").removeAttr("checked");
GiftGeniusBox_show("",url+"GiftGeniusBox_iframe=true&height=200&width=630")
}

// Added for facebook popup on 9th July, 2009 -task47206
function open_facebook() {
var url="";
url ="http://www.facebook.com/login.php?v=1.0&api_key=4c20111c836f354e990c2e63d46d5927"
GiftGeniusBox_show("",url+"GiftGeniusBox_iframe=true&height=400&width=570")
}

//Added on July 14th 2009 for Save Search popup - Gani
function open_reminder(save_search_id,save_search_name,occ_id){
     if(jQuery("#GiftGeniusBox_overlay"))
        GiftGeniusBox_remove();
    setTimeout("showReminder("+save_search_id+",'"+save_search_name+"',"+occ_id+")",300); 
}

//Added on July 14th 2009 for Save Search popup - Gani
function showReminder(save_search_id,save_search_name,occ_id){
     url ="/mystuff/set_reminder?reminder_id=&save_search_id="+save_search_id+"&save_search_name="+save_search_name+"&occ_id="+occ_id+""; 
    GiftGeniusBox_show("",url+"GiftGeniusBox_iframe=true&height=220&width=380");
}

//Added on July 14th 2009 for Save Search popup - Gani
function open_wishlist_savesearch(search_url){
    
    var url = search_url
         jQuery.ajax({
         type: "GET",
         url: url,
         dataType: "html",
         success: function(msg) {
                    gift_id=msg;
		 },
		 complete :function () {
                if(jQuery("#GiftGeniusBox_overlay"))
        GiftGeniusBox_remove();
    setTimeout("openAddGiftPopup('"+gift_id+"')",300);     
		
         }
	});
     
}

//Added on July 14th 2009 for Save Search popup - Gani
function wishlist_create(url,gid){
 jQuery("#create_wlist").blur();
 GiftGeniusBox_show('',url+"?gid="+gid+"GiftGeniusBox_iframe=true&height=150&width=461");
}

function wishlist_popup(url)
{
    GiftGeniusBox_show('',url+"?page_for=gift_for&gifted_person=user&GiftGeniusBox_iframe=true&height=150&width=461");
}

function redirect_to_register(){
        location.href="/register";
  }

/* 
Added on Aug 3 by Gayathri For wishlist create for gifted ones*/
function wishlist_create_giftedones(url,giftedone_id)
{
   
    GiftGeniusBox_show('',url+"?page_for=gift_for&gifted_person=contact&gifted_one_select="+giftedone_id+"&GiftGeniusBox_iframe=true&height=180&width=455");
}

/*
Added on May 12th 2009 for GIFT Page - Gayathri

Code for admin side ajax functonality in search
*/
var flag=0;

function search_dropdown_ajax(url)
{
   // if(flag==1)
   // return;
	
   //flag=1;
	
    a=url.split('?');
    urls='/ajaxupdate?'+a[1];
	
    jQuery.ajax({
        type: "GET",
        url: urls,
		error: function(msg,error) {
			  if (error = "timeout") {
			  jQuery("#error").append("The request timed out, please resubmit");
			  //flag=0
			  }
			  else {
			  jQuery("#error").append("ERROR: " + error);
			  //flag=0
			  }
		  },
	   success: function(msg){
				jQuery(".grey_innards").html(msg)
				//flag=0
				jQuery("#generateButton").attr('disabled', '');
			}
		
    });
    
}

/*
Added on May 12th 2009 for GIFT Page History/Back - Gani
*/
jQuery(document).ready(function(){
    jQuery(".back_search_a").click(function(){
        history.go(-1)
    })
})
//added by Gani on May 7th 2009-  Function to  display a big image for new gift of the day widget			
                function show_big_image_new(position)
                {
                    var thumb_container;
                    var selected_hat;
                    var parent;
                    var selected_image;
                    var count;
                    thumb_container = jQuery("#gotd_thumbnail");
                    selected_hat = thumb_container.find(".gift_selected")
                    for (count = 0 ; count < selected_hat.length ; count ++)
                        {
                            jQuery(selected_hat[count]).removeClass("gift_selected")
                            jQuery(selected_hat[count]).addClass("gift_not_selected")
                        }
                        selected_image = jQuery("#side_"+position);
                        parent = selected_image.parent();
                        parent.removeClass("gift_not_selected");
                        parent.addClass("gift_selected");
                        
                        document.getElementById("big").alt = document.getElementById("side_"+position).alt;
                        src_split = document.getElementById("side_"+position).src.split("/small/");
                        document.getElementById("big").src = src_split[0]+"/original/"+src_split[1];
                    }
                    
                    
// Added by Gayathri for Slidersnew_gift_tag

function showSlider() {
  jQuery('select#valueC, select#valueD').selectToUISlider({tooltip: false,labels: 0}).hide();
}
function new_gift_tag(obj)
{
    var gift_tag = obj.value;
    var tag_array = new Array();
    var taglist;
    var i;
    if(obj.checked)
    {
        document.getElementById("tag_list").value += gift_tag+",";
    }
    else
    {
      taglist = document.getElementById("tag_list").value;
      tag_array= taglist.split(',');
      document.getElementById("tag_list").value ="";
      
      for(i=0;i<=(tag_array.length-1);i++)
          {
              if(tag_array[i]!=gift_tag)
              {
                  if (tag_array[i]=="")
                  {
                      document.getElementById("tag_list").value +=tag_array[i];
                  }
                  else
                  {        
                      document.getElementById("tag_list").value +=tag_array[i]+",";
                  }
               }
          }
      }
   
}


function save_data(obj,id)
{

    var tag = obj.value;
    var giftid=id;  
    if(obj.checked == true)
        {
    var url="/admin/gifts/update/"+giftid+"?tag="+tag+""; 
    new Ajax.Updater('save', url, { method: 'get' });
    }
    else
        {
     var url="/admin/gifts/update/"+giftid+"?delete_tag="+tag+""; 
    new Ajax.Updater('save', url, { method: 'get' });
}}

/*  Script for redirect page */
function trigger_shop_url(url,value)
{
    if (value > 0)
   timerid = window.setTimeout("time_out_shop('"+url+"',"+value+");", 1000);
    else
	window.location.href = url    
}
function time_out_shop(url,value)
{
    document.getElementById("trigger_shop_url").innerHTML = value
    value = value - 1
    trigger_shop_url(url,value)
}
function go_to_link(url)
{
	window.clearInterval(timerid);
    timerid = null;
	window.location.href = url
}
/*  End code for redirect URL*/

function show_adv_list_tooltip(event)
{
	var target = event.target;
	var divObj = jQuery(target).next()[0];
	jQuery(divObj).addClass("advlist_tooltip_display");
		app_name = window.navigator.appName;
		if (app_name == "Microsoft Internet Explorer") {
		divObj.style.top = getOffsetTopIE(target) - 16 + "px";
		divObj.style.left = getOffsetLeftIE(target) + 180 + "px";
		}
		else {
		divObj.style.top = target.offsetTop - 16 + "px";
		divObj.style.left = target.offsetLeft + 180 + "px";
		}
	var containerEle = jQuery(target).parents(".recipients_row");
	containerEle.find("img")[0].src = jQuery(target).parent().find("span").text()
}

function hide_adv_list_tooltip(event)
{
	var target = event.target;
	var divObj = jQuery(target).next()[0];
	jQuery(divObj).removeClass("advlist_tooltip_display");
	var containerEle = jQuery(target).parents(".recipients_row");
	containerEle.find("img")[0].src = containerEle.find("span.main_per_src").text();
}

function getOffsetTopIE(objChild)
{
	var TotalTop = 0;
	while (objChild)
		{
	 TotalTop = TotalTop + objChild.offsetTop;
	 objChild = objChild.offsetParent;
		}
	return TotalTop;
}

function getOffsetLeftIE(objChild)
{
	var TotalLeft = 0;
	while (objChild)
		{
	 TotalLeft = TotalLeft + objChild.offsetLeft;
	 objChild = objChild.offsetParent;
		}
	return TotalLeft;
}



/*   Code for displaying pop up for recipient listings  */

/* Added by Gayathri for Upcoming Holidays */
function title_underline(obj)
{
   jQuery(obj).parent().parent().parent().children(".icon_descrip").children("a").css("text-decoration","underline");
    
}

function title_notunderline(obj)
{
   jQuery(obj).parent().parent().parent().children(".icon_descrip").children("a").css("text-decoration","none");
    

}

/* Added by Gayathri for Upcoming Holidays */
function title_underline_merchant(obj)
{
 jQuery(obj).parent().parent().find("a.anchor_style").css("text-decoration","underline");
    
}

function title_notunderline_merchant(obj)
{
    jQuery(obj).parent().parent().find("a.anchor_style").css("text-decoration","none");
}

function rectitle_underline(obj)
{
   jQuery(obj).parent().parent().children(".title_p").children("a").css("text-decoration","underline");
}

function rectitle_notunderline(obj)
{
   jQuery(obj).parent().parent().children(".title_p").children("a").css("text-decoration","none");
}
function with_up_down(obj)
{
	var advid = jQuery(obj).val();
    //var valu = jQuery(obj).parent().attr("adv");
	var valu = jQuery("#adv_"+advid).html();
	    jQuery("#select_adv_per").html(valu);
        jQuery("#select_adv").html(valu);
        jQuery("#singleorcollection").val(advid);
        jQuery(".close_icon").show();
      /*  jQuery(".adv_popuptable").hide();*/
}

function mystuff_with_up_down(obj)
{
	var advid = jQuery(obj).val();
 	var valu = jQuery("#adv_"+advid).html();
	jQuery("#rmv_per_name").show();
       jQuery("#select_mystuff_adv").html(valu);
       jQuery("#singleorcollection").val(advid);
       jQuery(".close_icon").show();
	   jQuery("#mystuff_getAdvPerson").hide();
}

/*Added by gayathri for pagination in import contacts */
function pagination_contacts(selected)
{
    start_pageno=jQuery("#start_pageno").val();
    if(parseInt(start_pageno)==selected)
    {
        return false;
    }
    if(selected==1)    {
        jQuery("#previous_link").addClass("selected_page_contacts");
    }else{
        jQuery("#previous_link").removeClass("selected_page_contacts");
    }
    jQuery("#start_pageno").val(selected);
    jQuery("#link_"+start_pageno).removeClass("selected_page_contacts");
    jQuery("#link_"+selected).addClass("selected_page_contacts");
    jQuery("#page_"+start_pageno).hide();
    jQuery("#page_"+selected).show();
  }
function next_contact_page(pagecount)
{
     //alert( jQuery("#pagenos").html())
    start_pageno=jQuery("#start_pageno").val();
     if(parseInt(start_pageno)==pagecount)
    {
        jQuery("#next_link").addClass("selected_page_contacts");
        return false;
    }
    jQuery("#previous_link").removeClass("selected_page_contacts");
    selected=parseInt(start_pageno)+1;
    jQuery("#start_pageno").val(selected);
    jQuery("#link_"+start_pageno).removeClass("selected_page_contacts");
    if(start_pageno%3==0){
        var list="";
        list+='<ul class="selectimport_lists">';
        for(var i=0;i<3;i++)
         {
             var pg=selected+i;
             
             if(pg<=pagecount){
                if(pg%3==0 || pg==pagecount)
                    list+='<li><a href="javascript:void(0);"  id="link_'+pg+'" onclick="pagination_contacts('+pg+')">'+pg+'</a></li>';
                else
                    list+='<li><a href="javascript:void(0);"  id="link_'+pg+'" onclick="pagination_contacts('+pg+')">'+pg+'</a>   ,</li>';
                }
             
         }
          list+='</ul>'
         jQuery("#pagenos").html("");
         jQuery("#pagenos").html(list);
          //alert( jQuery("#pagenos").html())
    }
    jQuery("#link_"+selected).addClass("selected_page_contacts");
    jQuery("#page_"+start_pageno).hide();
    jQuery("#page_"+selected).show();
}

function openAddGiftPopup(gift_id)
{
GiftGeniusBox_show('','/mystuff/savesearch?gift_ids='+gift_id+'&title=Who is this gift for?&GiftGeniusBox_iframe=true&height=164&width=461',null);
}
function previous_contact_page(pagecount)
{
    start_pageno=jQuery("#start_pageno").val();
     if(parseInt(start_pageno)==1)
    {
        jQuery("#previous_link").addClass("selected_page_contacts");
        return false;
    }
    jQuery("#next_link").removeClass("selected_page_contacts");
    selected=parseInt(start_pageno)-1;
    if(selected==1)    {
        jQuery("#previous_link").addClass("selected_page_contacts");
    }else{
        jQuery("#previous_link").removeClass("selected_page_contacts");
    }
    if(selected%3==0){
        var list="";
          list+='<ul class="selectimport_lists">';
        for(var i=2;i>=0;i--)
         {
             var pg=selected-i;
             if(pg>=1){
                if(pg%3==0 || pg==pagecount)
                    list+='<li><a href="javascript:void(0);"  id="link_'+pg+'" onclick="pagination_contacts('+pg+')">'+pg+'</a></li>';
                else
                    list+='<li><a href="javascript:void(0);"  id="link_'+pg+'" onclick="pagination_contacts('+pg+')">'+pg+'</a>   ,</li>';
                }
               
         }
          list+='</ul>'
       jQuery("#pagenos").html("");
         jQuery("#pagenos").html(list);
    }
    jQuery("#start_pageno").val(selected);
    jQuery("#link_"+start_pageno).removeClass("selected_page_contacts");
   
    jQuery("#link_"+selected).addClass("selected_page_contacts");
    jQuery("#page_"+start_pageno).hide();
    jQuery("#page_"+selected).show();
}
/*Added by Gayathri for Import contacts on July 9*/
 function import_contacts(){
  if(jQuery("#GiftGeniusBox_overlay"))
        GiftGeniusBox_remove();

    setTimeout("showManuallyImport()",300);  
   
  
 }

//Recently viewed gifts	
function show_gifts_list_tooltip(event)
{
	var target = event.target;
	var gift_id = jQuery(event.target).attr("src");
	var target_parent=jQuery(target).parent();
 
        list=jQuery(target_parent).children(".hidden_div_recently_viewed").html();
        
        jQuery("#show_div_list_rvwd").html(list);        
	
         var top = MyStuff.getOffsetTopIE(target) - 10;
         var left = MyStuff.getOffsetLeftIE(target) + 70 ;
         jQuery("#recently_viewed_tooltip").css("top",top);
         jQuery("#recently_viewed_tooltip").css("left",left);
         jQuery("#recently_viewed_tooltip").show();
		/*app_name = window.navigator.appName;
		if (app_name == "Microsoft Internet Explorer") {
		divObj.style.top = getOffsetTopIE(target) - 16 + "px";
		divObj.style.left = getOffsetLeftIE(target) + 70 + "px";
		}
		else {
		divObj.style.top = target.offsetTop - 16 + "px";
		divObj.style.left = target.offsetLeft + 70 + "px";
		}*/
	
}

// To display tooltip for description
function show_gifts_list_tooltip_desc(event)
{
	var target = event.target;
	
	var target_parent=jQuery(target).parent();
	var	p_parent=jQuery(target_parent).parent();
	
	list=jQuery(p_parent).children(".hidden_div_recently_viewed").html();       
        jQuery("#show_div_list_rvwd").html(list);        
	
         var top = MyStuff.getOffsetTopIE(target) - 10;
         var left = MyStuff.getOffsetLeftIE(target) + 70 ;
         jQuery("#recently_viewed_tooltip").css("top",top);
         jQuery("#recently_viewed_tooltip").css("left",left);
         jQuery("#recently_viewed_tooltip").show();
}

// To display tooltip for image
function show_gifts_list_tooltip_img(event)
{
	var target = event.target;
	var target_parent=jQuery(target).parent();
	var	p_parent=jQuery(target_parent).parent();
	var	next_div=jQuery(p_parent).next();
	
	list=jQuery(next_div).children(".hidden_div_recently_viewed").html();       
    jQuery("#show_div_list_rvwd").html(list);        
	
         var top = MyStuff.getOffsetTopIE(target) - 11;
         var left = MyStuff.getOffsetLeftIE(target) + 115 ;
         jQuery("#recently_viewed_tooltip").css("top",top);
         jQuery("#recently_viewed_tooltip").css("left",left);
         jQuery("#recently_viewed_tooltip").show();
}



function hide_gifts_list_tooltip1(event)
{
	jQuery("#recently_viewed_tooltip").hide();
	
}
function hold_rvwd_gifts_list_tooltip()
{
    jQuery("#recently_viewed_tooltip").show();
}
  function show_share_gift(gift_id,obj){
            jQuery(obj).blur();
            GiftGeniusBox_show('','/sharegift?id='+gift_id+'GiftGeniusBox_iframe=true&height=230&width=209',null);
            return false;

        }
  function remove_gift(gift_id,wishlist_id,div_id){
      
        var answer = confirm("Are you sure to remove this gift?")
	if (answer){
         var url = "/removegift";
		 data = {
		 "id" : gift_id ,
		 "wishlist_id" : wishlist_id,
		 "div_id" : div_id
		 };
         jQuery.ajax({
         type: "GET",
         url: url,
         dataType: "html", data:data,
         success: function(msg) {
                    jQuery("#"+div_id).html(msg);
		 },
		 complete :function () {
                      jQuery(".image_gift_wishlist").mouseover(share_gifts_list_tooltip);
                    jQuery(".image_gift_wishlist").mouseout(hide_share_gifts_list_tooltip);
		
         }
	});
		
	}
	else{
		return false;
	}

  }

function share_gifts_list_tooltip(event)
{
    
    var target = event.target;
    var target_parent=jQuery(target).parent().parent();
    //alert(jQuery(target_parent).html());
    var divObj = jQuery(target_parent).children("div.hidden_div_giftedones");
     var list = jQuery(divObj).html();
     var scroll_parent=jQuery(target).parents(".mywishlist_gifts")
      var scroll_div = jQuery(scroll_parent).find("div.wishlist_scroller");
             jQuery("#show_div_list").html(list);
	// Subtract the top from scroll_div.scrollTop this is to compensate the top difference when the scroll is moved.
	app_name = window.navigator.appName;
         var top = MyStuff.getOffsetTopIE(target) - 0 - scroll_div[0].scrollTop;
         var left = MyStuff.getOffsetLeftIE(target) + 50 ;
         jQuery("#gifts_tooltip").css("top",top);
         jQuery("#gifts_tooltip").css("left",left);
         jQuery("#gifts_tooltip").show();
         jQuery("#gifts_tooltip").mouseover(hold_share_gifts_list_tooltip)
    
}
function hide_share_gifts_list_tooltip(event)
{
  jQuery("#gifts_tooltip").hide();
}
function hold_share_gifts_list_tooltip(event) {
    
	jQuery("#gifts_tooltip").show();
};

function show_privacy_box(event)
{
    var target = event.target;
     jQuery(".privacy_box").hide();
    parent_div=jQuery(target).parents(".giftsearch_lists");
    app_name = window.navigator.appName;
    child_box=jQuery(parent_div).children(".privacy_box");
    /*if (app_name == "Microsoft Internet Explorer") {
        child_box.style.top = getOffsetTopIE(target) - 16 + "px";
        child_box.style.left = getOffsetLeftIE(target) + 70 + "px";
    }
    else {
       top = target.offsetTop - 14 + "px";
       left = target.offsetLeft+65+"px"; 
       jQuery(child_box).css("top",top);
       jQuery(child_box).css("left",left);
    }*/
   var top = MyStuff.getOffsetTopIE(target) - 20;
   var left = MyStuff.getOffsetLeftIE(target) + 150 ;
   jQuery(child_box).css("top",top);
   jQuery(child_box).css("left",left);
   jQuery(parent_div).children(".privacy_box").show();
   jQuery(".close_img").click(close_privacybox);
   jQuery(".privacy_radio").bind("click",change_status_savesearch);
    
}
function close_privacybox(event){
    var target = event.target;
    parent_div=jQuery(target).parents(".privacy_box");
    jQuery(parent_div).hide()
}
function change_status_savesearch(event){
    var target = event.target;
    parent_privacy=jQuery(target).parents(".privacy_box");
    parent_div=jQuery(target).parents(".giftsearch_lists");
    ul_class=jQuery(parent_div).find("ul").attr("class");
    
    id=jQuery(this).attr("name");
    status_privacy=jQuery(target).attr("id");
     var url = "/changestatus?id="+id+"&status="+status_privacy;
     jQuery.ajax({
     type: "GET",
     url: url,
     dataType: "html",
     success: function(msg) {
                jQuery(parent_privacy).html(msg);
                if(status_privacy=="public"){
                    jQuery(parent_div).find("a.privacy_icon").children().attr("src","/images/green_dot.gif");
                }else{
                jQuery(parent_div).find("a.privacy_icon").children().attr("src","/images/red_dot.gif");
                }
                 jQuery(".close_img").bind("click",close_privacybox);
                 
                                 
             },
             complete :function () {
                 jQuery(parent_div).find("ul").removeClass(ul_class);
                  ul_class="giftsearch_newlist profile_"+target.value
                   jQuery(parent_div).find("ul").addClass(ul_class);
                  jQuery(parent_privacy).hide();
                 
                
             
     }
    });
  }
  
   function add_gifted_one(){
  if(jQuery("#GiftGeniusBox_overlay"))
        GiftGeniusBox_remove();

    setTimeout("open_thickbox('')",300);  
   
  
 }
 
 function open_thickbox(obj)
{
// To deselect the radio button
 jQuery("div.friends_import1").find("input#r1").removeAttr("checked");
 jQuery("div.friends_import1").find("input#r2").removeAttr("checked");
 jQuery("div.friends_import1").find("input#r3").removeAttr("checked");
 jQuery("div.friends_import1").find("input#r4").removeAttr("checked");
 GiftGeniusBox_show('','/getcontact?from='+obj+'&GiftGeniusBox_iframe=true&height=340&width=335',null);
return false;
}
/* Request Wishlist */
function wishlist_email(id,type)
  {
    var url= "/mystuff/wishlist_url_email?id="+id+"&type="+type;
   GiftGeniusBox_show('',url+"&GiftGeniusBox_iframe=true&height=210&width=209");
  }
/* Request Birthday */
function add_bdayrequest(id){
	var url= "/mystuff/bdayrequest/"+id;
   GiftGeniusBox_show('',url+"?GiftGeniusBox_iframe=true&height=230&width=209");
} 


function new_wishlist()
{
    setTimeout("GiftGeniusBox_remove()",1000);
	top.location.href = window.location.href;
}
function edit_wishlist()
{
    setTimeout("GiftGeniusBox_remove()",500);
	 top.location.href = window.location.href;
}
function chge_contact_list_height(height){
        jQuery("#GiftGeniusBox_iframeContent").css("height",height);
  
}

function currentIframeHt() {
	return parseInt(jQuery("#GiftGeniusBox_iframeContent").css("height"));
}
function chge_ggbox_width(width){
        jQuery("#GiftGeniusBox_iframeContent").css("width",width);
  
}
function get_ggbox_height()
{
    height=jQuery("#GiftGeniusBox_iframeContent").css("height");
    return parseInt(height);
}
function get_ggbox_top(top)
{
    mar_top = jQuery("#GiftGeniusBox_window").css("margin-top");
    top = parseInt(mar_top) - top;
    jQuery("#GiftGeniusBox_window").css("margin-top",top);
}
function wishlist_edit(id)
  {
	var url= "/mystuff/wishlist/edit/"+id;
	GiftGeniusBox_show('',url+"?GiftGeniusBox_iframe=true&height=150&width=461");
  }
   function open_addNewReminder(obj) {
    GiftGeniusBox_show('','/mystuff/add_reminder?from='+obj.value+'&GiftGeniusBox_iframe=true&height=330&width=365',null);
    return false;
 }
 
function guide_rotate_right(event)
 {
	
 	var target = event.target;
	var parentContainer = jQuery(target).offsetParent();
	var totalBlocks = parentContainer.find("div.rotator_width");
	var totalBlocksLen = totalBlocks.length - 2;
	if (totalBlocksLen == 0)
		return false;
	
	var widthOfBlock = parseInt(totalBlocks[0].offsetWidth);
	var rotatorDiv = parentContainer.find("div#theImages_G1");
	var currLeftPos = parseInt(rotatorDiv[0].style.left);
	
	
	if (currLeftPos > (-1 * widthOfBlock * totalBlocksLen) ) {
	
	guide_rotator_ndex++;
	var diff_amount = -1 ;
	rotatorDiv[0].style.left = currLeftPos + (-1 * widthOfBlock) + diff_amount + "px";
	}
	else {
	rotatorDiv[0].style.left = "0px";
	guide_rotator_ndex = 0;
	}
		
 }
 
function guide_rotate_left(event)
 {
	
 	var target = event.target;
	var parentContainer = jQuery(target).offsetParent();
	var totalBlocks = parentContainer.find("div.rotator_width");
	var totalBlocksLen = totalBlocks.length - 2;
	if (totalBlocksLen == 0)
		return false;
	
	var widthOfBlock = parseInt(totalBlocks[0].offsetWidth);
	var rotatorDiv = parentContainer.find("div#theImages_G1");
	var currLeftPos = parseInt(rotatorDiv[0].style.left);
	if (currLeftPos == 0)
	{
	var diff_amount = -1 *totalBlocksLen ;
	rotatorDiv[0].style.left = currLeftPos + (-1*widthOfBlock*totalBlocksLen) + diff_amount + "px";
	}
	else
	{
	var diff = -1 * totalBlocksLen;
	if (currLeftPos > ((-1*widthOfBlock * totalBlocksLen)) + (diff-1)) {
	
	guide_rotator_ndex--;
	var diff_amount = 1 ;
	
	rotatorDiv[0].style.left = currLeftPos + (widthOfBlock) + diff_amount + "px";
	
	}
	else {
	rotatorDiv[0].style.left = "0px";
	
	guide_rotator_ndex = 0;
	}
	}
	

 }
 /*function guide_rotate_left(event)
 {
 	var target = event.target;
	var parentContainer = jQuery(target).offsetParent();
	var totalBlocks = parentContainer.find("div.rotator_width");
	var totalBlocksLen = totalBlocks.length - 2;
	if (totalBlocksLen == 0)
		return false;
	
	var widthOfBlock = parseInt(totalBlocks[0].offsetWidth);
	var rotatorDiv = parentContainer.find("div#theImages_G1");
	var currLeftPos = parseInt(rotatorDiv[0].style.left);
	if ( currLeftPos == 0) {
		var diff_amount = -2 * totalBlocksLen ;
		rotatorDiv[0].style.left = currLeftPos + (-1 * totalBlocksLen * widthOfBlock) + diff_amount + "px";
	}
	else {
		if (currLeftPos < (widthOfBlock * totalBlocksLen)  && currLeftPos < 0) {
		guide_rotator_ndex--;
		var diff_amount = 1 ;
		rotatorDiv[0].style.left = currLeftPos + (widthOfBlock) + diff_amount +"px";
		}
		else {
		rotatorDiv[0].style.left = "0px";
		guide_rotator_ndex = 0;
		}
	}
			alert(parseInt(rotatorDiv[0].style.left)+2);

 }*/
 
 	 function get_save_search_url(){
		var url = "";
		var str = "";
		// Without AJAX call
		if (jQuery("#refine_search").html()=="") {
			str = GGSearch.doSaveSearch();  
		}	
		// When AJAX call is made
		else   {
		   str = jQuery("#refine_search").html(); 
		   if (window.location.pathname.split("/")[1] == "recipients")
			   {
				   // Code to pack recipient details when it is 0
				   var stuff_code = str.split("personlist=0");
				   str = stuff_code[0] + "personlist="+window.location.pathname.split("/")[2]+stuff_code[1];
			   }
			  if (window.location.pathname.split("/")[1] == "occasions")
			   {
				   // Code to pack occasion details when it is 0
				   var stuff_code = str.split("occasionList=0");
				   str = stuff_code[0] + "occasionList="+window.location.pathname.split("/")[2]+stuff_code[1];
			   }
			 if (window.location.pathname.split("/")[1] == "categories")
			   {
				   // Code to pack category details when it is 0
				   var stuff_code = str.split("categories=");
				   str = stuff_code[0] + "categories="+window.location.pathname.split("/")[2]+stuff_code[1];
			   }       
		   }
		   result = str;
		   return result;
	 }

	 
 // ajax function call for Celebrity Picks pagenation
 function get_gifts_for_article_collage(event) {
		var search_url;
		var target = event.target;
		var value = target.value;
		if (target.nodeName == "IMG") {
		    if ((target.id) == "left_arrow"){
				value = parseInt(jQuery("#next_prev").val()) - 1;
			}
			else{
				value = parseInt(jQuery("#next_prev").val()) + 1;
			}
			if ( value	> jQuery("#collage_pagination")[0].options.length || value < 1) {
				return false;
				}
			jQuery("#next_prev").val(value);
		}
		data = {
		"page_no" :value,
		"art_id" : window.location.pathname.split("/")[3]
		};
		var get_url = window.location.pathname;
		jQuery.ajax({
		type : "GET" ,
		url  : get_url,
		dataType: "html", data:data,
		success: function(msg) {
		 jQuery("#article_gifts").html(msg);
		 },
	    complete : function () {
		}
		});
	return false;
	};

function check_mail_bronto(str){ 
	
	 var mailid=jQuery("#newsletter_name").val();
         var article_type= "";
	 url = str;
	 var value = validate(mailid);
	 if(url == "celebrity")
	 {
	 _url = "/articles/celebrity_newsletter"
         article_type=jQuery("#article_type").val();
	 }
	 else if(url == "editor")
	 {
	 _url = "/guides/newsletter"
         }
	 
	 if(value) {
	 		
		var data = {
			"email" : mailid,
			"type"  : "newsletter",
                        "article_type":article_type
		   };
		 jQuery("#nl_wait").show();
		jQuery.ajax({
		   type: "GET",
		   url: _url,
		   dataType: "html",data:data,

		   success: function(msg){
				if (msg == "Invalid") {
					alert("Sorry! You are not Subscribed.");
				}
				else{
					alert("Successfully Subscribed!");
				}
			},
			
			complete: function() {
				jQuery("#nl_wait").hide();
				jQuery("#newsletter_name").val("Enter Email Address");
				
			}
		});
	}
};
	

	
	
	/* Function for generating gifts from filtered gifts in CMS*/
	function urllink() {
		a=jQuery("#gifts_tags_filter").val().split('?');
		urls='/get_gifts?'+a[1];
        path=window.location.pathname;
        urls=path+'?'+a[1];
		location.href=urls;
    } 

/*To redirect the non members to register page */
function redirectToRegister()
{
location.href="/register";
}

	 /* This function is to close the save search popup after success message with some time delay*/
 function close_save_search_popup(){
 setTimeout("close_after_delay()",350); 
 }
 
 function close_after_delay(){
 parent.GiftGeniusBox_remove();
 }
 
 // js to open add reminder pop up
 function open_addReminder() {
 GiftGeniusBox_show('','/mystuff/add_reminder?GiftGeniusBox_iframe=true&height=335&width=370',null);
 return false;
 }
 
 // For admin save gift
 function save_gift()
 {
       var month = jQuery('#gift_gotd_at_2i').val();
       var day = jQuery('#gift_gotd_at_3i').val();
       var year = jQuery('#gift_gotd_at_1i').val();
	   if((month =="") && (day == "") && (year == ""))
	   {
			jQuery('.err_class').html('');
	   }
       else
       {
           if((month=="")|| (day=="") || (year==""))
           {
               jQuery('.err_class').html('<div id="errors" class="alert clearfix"><div class="whitecurvetop"></div><div class="errors_content">Invalid GOTD date</div><div class="whitecurvebottom"></div></div>');
               return false;
           }
		   else{
				jQuery('.err_class').html('');
		   }
       }
  
       return true;
       
 }
 
 // For Boutique gift
 
 function get_boutique_url(host){
	url = "http://"+host+"/boutique";
	jQuery('#gift_url_tracking').val('');
	if (jQuery('#gift_boutique_check').get(0).checked == true)
	{
		jQuery('#gift_url').val(url);
	}
	else{
		jQuery('#gift_url').val('');
	}
	
 }