﻿//global vars
var itemPreferences;
var diamondPreferences;
var userPreferences;
var bandPreferences;
var currentlySelectedItem;
var currentDiamond;
var currentPicNumber=0;
var currentThumbselectedLi;
var disableZoom=true;
var isOptionalComponentSelected = false;
var itemShippingTime=15;

function UserPreference() {
  this.CountryId = 0;
  this.CurrencyId = 0;
  this.CurrencyCode = '';
  
}

function ItemPreferences(){
    this.MetalId = 0;
    this.ItemId = 0;
    this.RecentItems='';
}

function DiamondPreference() {
    this.ShapeId=0;
    this.MinCarat=0;
    this.MaxCarat=0;
    
    this.Colors='';
    this.Clarities='';
    this.Certs='';
    
    this.MinPrice=0;
    this.MaxPrice=0;
    this.MinP
    this.Cuts='';
    this.Polishes='';
    this.Symms='';
    this.Flos='';
    
    this.MinRatio=0;
    this.MaxRatio=0;
    
    this.ResultsPerPage=0;
    this.CurrentPageNumber=1;
    
    this.ShowAdvanced=false;
    this.ShowPairs = false;    
}

function BandPreference()
{
    this.DepthId = 0;
    this.WidthId = 0;
    this.RingSizeName = '';
}

function ElementProperties()
{
    this.ElementId = 0;
    this.AttributeId = 0;
    this.OtherAttributeId=0; //when one attribute is shown, but works on 2, like EGL / EGL USA
    this.Element = null,
    this.IsSelected = false;
}

function CurrentDiamond()
{
    this.Row = null;
    this.ClassName = '';
    this.Diamond = null;
}
var CompVar = new Array(); //stores the components and variations in a key/value pair

function InitUserPreferences(userPrefs)
{
    var ups = eval('(' + userPrefs+ ')'); 
    
    userPreferences = new UserPreference;
    userPreferences.CountryId = ups.CountryId;
    userPreferences.CurrencyId = ups.CurrencyId;
    userPreferences.CurrencyCode = ups.CurrencyCode;
    GetCookie();
}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}

// JavaScript Document

function tabSwitch(new_tab, new_content) {
	
	document.getElementById('content_1').style.display = 'none';
	document.getElementById('content_2').style.display = 'none';
	document.getElementById('content_3').style.display = 'none';		
	document.getElementById(new_content).style.display = 'block';	
	

	document.getElementById('tab_1').className = '';
	document.getElementById('tab_2').className = '';
	document.getElementById('tab_3').className = '';		
	document.getElementById(new_tab).className = 'active';		

}

// Ties a set of tabs and content id's together, and switches between them
// <div id='tab_1'> and <div id="content_1"> for example
// Usage: tabswitch(1, 4, 'tab', 'panel') would switch on tab_1 and panel_1

function tabSwitch_2(active, number, tab_prefix, content_prefix) {
	
	var isVideoTab = false;
	if (document.getElementById('content_2').style.display == 'block')
	    isVideoTab = true;
	    
	for (var i=1; i < number+1; i++) {
	  document.getElementById(content_prefix+i).style.display = 'none';
	  document.getElementById(tab_prefix+i).className = '';
	}
	document.getElementById(content_prefix+active).style.display = 'block';
	document.getElementById(tab_prefix+active).className = 'active';	
	
	//show and hide the content for the video and images
	//tab_prefix + active
	var elementId = tab_prefix + active;        
		
	//image gallery
	if (elementId == 'tab_1')
	{
	    // reset defaul value for the video    
        ResetVideoValue();        
        //show image gallery
        $("#bigPicture").removeClass("HiddenDiv");      
        //enable the zoom again       
        $("#image_zoom").removeClass("HiddenDiv");           
        //hide icon gallery
        //document.getElementById('liPhotoGallery').style.display = 'none';
        ResetImageGalleryStatus();
        swapPanelIcons('imgPhotoGallery','../images/icon-images-hover.png');
        $("#imgPhotoGallery").addClass("IconSelected");
        //show zoom icons
        var firstThumb = document.getElementById('thumb_0');
       
        if (firstThumb != null && firstThumb.Zoom != null && firstThumb.Zoom != undefined && firstThumb.style.display != 'none')
        {
            if (disableZoom)
            {
                document.getElementById('liZoomIn').style.display = 'block';
                document.getElementById('liZoomOut').style.display = 'none';  
            }else
            {
                document.getElementById('liZoomIn').style.display = 'none';
                document.getElementById('liZoomOut').style.display = 'block';  
            }    
            document.getElementById('image_zoom').style.cursor = 'pointer';
            document.getElementById('image_zoom').setAttribute('onclick','CheckZoom();');            
        }else
        {
            document.getElementById('liZoomIn').style.display = 'none';
            document.getElementById('liZoomOut').style.display = 'none';  
            document.getElementById('image_zoom').style.cursor = '';
            document.getElementById('image_zoom').removeAttribute('onclick');
        }
	    //i need to draw the gallery icons	     
        document.getElementById('liHandVideo').style.display = 'none';
        document.getElementById('liHandBracVideo').style.display = 'none';        
        document.getElementById('li360Video').style.display = 'none';
	    //get videos and draw gallery icons
	    document.getElementById('lblPictureReferenceText').style.display='inline'; 
	    GetVideos();
	    
        
	}else //video
	{	
	    document.getElementById('lblPictureReferenceText').style.display='none'; 
	     //hide image content
	    $("#bigPicture").addClass("HiddenDiv");  
	    //remove everything for the zoom	    
	    $("#image_zoom").addClass("HiddenDiv");  	  
	    //show icon gallery
        document.getElementById('liPhotoGallery').style.display = 'block';
        //hide zoom icons
        document.getElementById('liZoomIn').style.display = 'none';
        document.getElementById('liZoomOut').style.display = 'none';       
        //if i'm already in the video tab i'm not doing nothing
        if (!isVideoTab)
            $("[id*=thumbVideo_]").removeClass("thumbnail_selected");
	}
	
	
}

function SelectCurrentCurrency(element)
{
     if (element != null)
    {       
        var DefaultCurrencyId = element.getAttribute('DefaultCurrencyId');      
        //select the currency from the selected country
        $("#ctl00_Header_ucHeader_ucCountry_ddlHeaderCurrency").val(DefaultCurrencyId);   
             
    }
}

function CleanTxtDiscounCode()
{
    $("#lblDiscountError").text("");
}
//check if the discountCode is valid
function CheckDiscountCode()
{    
    var txtValue = $("#ctl00_CenterContentPlaceHolder_txtDiscountCode").val();
    $("#lblDiscountError").text("");
    txtValue = $.trim(txtValue);    
    if ( txtValue == '')
    {
        $("#lblDiscountError").text("Please insert an offer code.");
        return;
    }
    
    Website.WebServices.WebService.CheckDiscountCode(txtValue,GetCookie(),
         function(success)
         {
            
            var discountCode = eval('(' + success + ')');
            if(discountCode.SingleObject!=null && !discountCode.SingleObject.HasBeenUsed)
            {
                document.location.href = document.location.href;
            }
            else if((discountCode.SingleObject!=null && discountCode.SingleObject.HasBeenUsed) ||
            (discountCode.SingleObject==null || discountCode.SingleObject==undefined))
            {
                document.getElementById('lblDiscountError').innerHTML = 'This code is not valid or has already been used';
            }
         }, 
         function(error)
         {           
         });
}

function ResetImageGalleryStatus()
{
    swapPanelIconsOut('imgPhotoGallery','../images/icon-images.png');
        $("#imgPhotoGallery").removeClass("IconSelected");
    swapPanelIconsOut('imgHandBracVideo','../images/icon-hand-model-bracelet.png');
        $("#imgHandBracVideo").removeClass("IconSelected");
    swapPanelIconsOut('imgHandVideo','../images/icon-hand-model.png');
        $("#imgHandVideo").removeClass("IconSelected");
    swapPanelIconsOut('img360Video','../images/icon-360-video.png');
        $("#img360Video").removeClass("IconSelected");
    
}

function ResetContactUsBtn()
{
    swapPanelIconsOut('imgChat','../images/btn-livechat.png');
        $("#imgChat").removeClass("IconSelected");
    swapPanelIconsOut('imgCallmeBack','../images/btn-callmeback.png');
        $("#imgCallmeBack").removeClass("IconSelected");
    swapPanelIconsOut('imgSchedule','../images/btn-schedule.png');
        $("#imgSchedule").removeClass("IconSelected");
    swapPanelIconsOut('imgEmailUs','../images/btn-emailus.png');
        $("#imgEmailUs").removeClass("IconSelected");
}

function SelectContactBtn(id,path)
{   
    swapPanelIcons(id,path);
    $("#" + id + "").addClass("IconSelected");
}

//get all the countries
function GetCountries()
{  
    Website.WebServices.WebService.GetCountries(
         function(success)
         {
            var countries = eval('(' + success + ')');   
                         
            for (i=0; i<countries.ObjectCollection.length; i++) {
                //coutries for delivery form
                addOptionCountries(document.aspnetForm.ddlDeliveryCountry, countries.ObjectCollection[i]);

                //countries for billing form
                addOptionCountries(document.aspnetForm.ddlBillingCountry, countries.ObjectCollection[i]);
                
            }              
         },
         function(error)
         {           
         });
}

function addOptionCountries(selectBox, country)
{    
    var optn = document.createElement('option');
    optn.text = country.Name;
    optn.value = country.Id;    
    selectBox.options.add(optn);
}


//Get querystring
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function getUrlRewrite()
{
    var url =location.pathname.replace('/','');
	
    if (document.getElementById('ctl00_UrlRewrite').value != '' )
    {
        url = document.getElementById('ctl00_UrlRewrite').value;
    }
    return url;
}

function ShowHideLanguage()
{
    var arrow;
    if (document.getElementById('divLanguageOptionsContent').style.display == 'none')
    {
        //show
        document.getElementById('divLanguageOptionsContent').style.display = 'block';
        $("#divLanguageContent").removeClass("language");
        $("#divLanguageContent").addClass("language_open");        
        arrow = document.getElementById('imgArrowLanguage');
        arrow.setAttribute('src','../images/arrow-up.gif');
        arrow.setAttribute('alt','Close');
        arrow.setAttribute('title','Close');
                
    }
    else
    {
        //hide
        document.getElementById('divLanguageOptionsContent').style.display = 'none';
        $("#divLanguageContent").removeClass("language_open");
        $("#divLanguageContent").addClass("language");        
        arrow = document.getElementById('imgArrowLanguage');
        arrow.setAttribute('src','../images/arrow-down.gif');
        arrow.setAttribute('alt','Open');
        arrow.setAttribute('title','Open');
    }
}

//show/hide the subMenu
function ShowHideSubMenu(){
    $(".carousel_container").animate({"height": "toggle"}, { duration: 1000 });
}

function RemoveAttribute(obj, id)
{
    var returnValue = obj.replace(id + ',', ' ');
    return returnValue;
}

function AddAttribute(obj, id)
{
    var returnValue = obj + id + ', ';
    return  returnValue;
}

function UpdateClass(props)
{
    var currentClasses = props.Element.className.split(' ');
    if(currentClasses[1].indexOf('_selected')>0)
        //this is a selected class, remove the word _selected from the class name
        currentClasses[1] = currentClasses[1].replace('_selected',' ');
    else
        //this is not a selected class, kindly be adding the word 'selected' to the end of the class name
        currentClasses[1] += '_selected';

    props.Element.className = currentClasses[0] + ' ' + currentClasses[1];
}


function GetElementProperties(el)
{
    var elProperties = new ElementProperties();
    
    elProperties.Element = el;
    elProperties.ElementId = el.getAttribute("Id");
    
    var styleClass = el.className.split(' ')[1];
    if(styleClass.indexOf('_selected')>0)
        elProperties.IsSelected = 1;
    else
        elProperties.IsSelected = 0;
        
    elProperties.AttributeId = elProperties.ElementId.substring(4); //xxx_ removed!
    return elProperties;
}

 // reset defaul value for the video  
function ResetVideoValue()
{
    //hide div that contains 'image video'
    $("#containerVideo").addClass("HiddenDiv");
    //stop 'image video'
    Stop();
    StopMove();
    //hide container flash
    $("#containerFlash").addClass("HiddenDiv");
    document.getElementById('containerFlash').innerHTML = '';
    //hide err video msg
    $("#NoVideo").addClass("HiddenDiv");        
}

///formats an amount to contain commas
function FormatAmount(nStr)
{
    nStr += '';
	var x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) 
	    {
		    x1 = x1.replace(rgx, '$1' + ',' + '$2');
	    }
	return x1 + x2;
}
//sets a cookie if its not been set yet
function SetCookie()
{
    if(GetCookie()==null && GetCookie()==undefined)
    {
        Website.WebServices.WebService.GetCookie(
        function(result)
        {
            var exdate=new Date();
            exdate.setDate(exdate.getDate() + 30);
            var cky = '77dyId=' + escape(result) + "; expires="+exdate.toUTCString();
            document.cookie=cky;
        },
        function(error)
        {
            //oops!
        });   
    }
}
function GetCookie()
{
    return ReadCookie('77dyId');
}

function ReadCookie(name)
{
  name += '=';
  var parts = document.cookie.split(/;\s*/);
  for (var i = 0; i < parts.length; i++)
  {
    var part = parts[i];
    if (part.indexOf(name) == 0)
      return part.substring(name.length)
  }
  return null;
}

//for chrome i need to repaint the slider
function RepaintSlider()
{   
    if (diamondPreferences != null && diamondPreferences != undefined && diamondPreferences.ShapeId != 1)
    {
        var slider = $find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderRatio'); 
        if(slider!=null && slider!=undefined)
            slider.repaint();  
    }
}

function CheckTnCAccept()
{
    if(document.getElementById('chkTermsAndConditions').checked)
    {
          window.location = './checkout.aspx';
    }
    else
    {
        alert('Please read and accept our terms and conditions');
    }
}

function ResetMethodPayment(id)
{
       
    $("#cardDiv").removeClass('payment_method_select_selected');
    $("#phoneDiv").removeClass('payment_method_select_selected');
    $("#bankDiv").removeClass('payment_method_select_selected');
    $("#paypalDiv").removeClass('payment_method_select_selected');
    $("#p4lDiv").removeClass('payment_method_select_selected');
   
    $("[id=" + id + "]").addClass('payment_method_select_selected');
    
}

function RemoveZoom(zoom)
{   
    disableZoom = true;
    //there is no zoom for that item
    if (zoom)
    {
        document.getElementById('liZoomIn').style.display = 'none';
        document.getElementById('liZoomOut').style.display = 'none';
    }else
    {
        document.getElementById('liZoomIn').style.display = 'block';
        document.getElementById('liZoomOut').style.display = 'none';
    }
    $('.cloud-zoom').CloudZoom({destroy:true});
}

function EnableZoom()
{
    disableZoom = false;
    document.getElementById('liZoomIn').style.display = 'none';
    document.getElementById('liZoomOut').style.display = 'block';
    $('.cloud-zoom').CloudZoom();
}

function CheckZoom()
{
    if (disableZoom)
    {
        disableZoom = false;
        document.getElementById('liZoomIn').style.display = 'none';
        document.getElementById('liZoomOut').style.display = 'block';
        $('.cloud-zoom').CloudZoom();
    }else
    {
        disableZoom = true;
        document.getElementById('liZoomIn').style.display = 'block';
        document.getElementById('liZoomOut').style.display = 'none';
        $('.cloud-zoom').CloudZoom({destroy:true});
    }
}

function ShowCustomizationOptions(elId)
{
    document.getElementById(elId).style.display = 'block';
}

function HideCustomizationOptions(elId)
{
    document.getElementById(elId).style.display = 'none';
}

function ChangeImage(path , itemId)
{
    document.getElementById('ctl00_Header_ucTopNav_subMenuImg_' + itemId).setAttribute('src',path);
}

function ResetImage(path , itemId)
{
    document.getElementById('ctl00_Header_ucTopNav_subMenuImg_' + itemId).setAttribute('src',path);
}

function SelectTd(el,trId)
{   
    //remove the class in all the tds inside the tr
    $("tr#" + trId + " td").removeClass('diamond_control_select_bg_selected').addClass('diamond_control_select_bg');
    $("[id=" + el.id + "]").addClass('diamond_control_select_bg_selected').removeClass('diamond_control_select_bg');
}

function SelectVideoThumb(el)
{
    $("[id*=thumbVideo_]").removeClass("thumbnail_selected");
    $("[id="+ el.getAttribute('id') +"]").addClass("thumbnail_selected");
}
function UpdateRingSize(el,shopBagCode)
{    
    var attrId= el.value;
    var name = el.text;
   
     if (attrId != -1)
     {  
         Website.WebServices.WebService.UpdateShoppingBag(shopBagCode, GetCookie(), attrId,name,
         function(success)
         {
              
         },
         function(error)
         {        
         });
     }
}

function doPopup(url)
{
    window.open(url, '_blank', 'left=100,top=100,width=980,height=860,scrollbars=yes');
	
}

function doCustomPopup(url,width,height,scrollbars)
{
    if (scrollbars == null)
        scrollbars = 'no';
        
    window.open(url, '_blank', 'left=100,top=100,width=' + width + ',height=' + height + ',scrollbars=' + scrollbars+ ',resizable=yes');
	
}

function swapPanelIcons(id,path)
{
    var img =document.getElementById(id);
    
    if($(img).hasClass("IconSelected"))
        return;
    
    img.setAttribute('src',path);
}

function swapPanelIconsOut(id,path)
{
    var img =document.getElementById(id);  
    
    img.setAttribute('src',path);
}
function addSubMenuOpacity(id,el)
{   
    if($(el).hasClass("sub_menu_item_image_selected"))
        return;
      
    $("[id=" + id + "]").css('opacity','0.4').css('filter','alpha(opacity = 40)');
}
function removeSubMenuOpacity(id,el)
{   
     if($(el).hasClass("sub_menu_item_image_selected"))
        return;
        
    $("[id=" + id + "]").css('opacity','1.0').css('filter','alpha(opacity = 100)');
}

function addLandingPageOpacity(el)
{           
    $("[id=" + el.getAttribute("Id") + "]").css('opacity','0.4').css('filter','alpha(opacity = 40)');
}
function removeLandingPageOpacity(el)
{   
    $("[id=" + el.getAttribute("Id") + "]").css('opacity','1.0').css('filter','alpha(opacity = 100)');
}

function ShowHideFields(prefix,id)
{        
    $("[id*=" + prefix + "]").css('display','none');    
    $("[id=" + id + "]").css('display','block');
}

function RemoveAddClass(prefix,id,className)
{
    $("[id*=" + prefix + "]").removeClass(className);    
    $("[id=" + id + "]").addClass(className);
}

function DisableAddToShoppingBag()
{
    document.getElementById('ctl00_CenterContentPlaceHolder_ucOrderInfoControl_btnAddToShoppingBag').onclick = function()
    {
        //cant do no clickin'
    }
}

function EnableAddToShoppingBag()
{
    document.getElementById('ctl00_CenterContentPlaceHolder_ucOrderInfoControl_btnAddToShoppingBag').onclick = function()
    {
        //removes the shopping bag :D
        AddToShoppingBag();
        return false;
    }
}

function ValidateCheckout()
{
    var validate= ($('#aspnetForm').validationEngine({returnIsValid:true}));
    //disable checkout button
    if(validate)
    {
        document.getElementById('ctl00_CenterContentPlaceHolder_btnProceedPayment').style.display = 'none';
        document.getElementById('btnFakeProceedPayment').style.display = 'block';
        //calling transactionScript
        //get the amount
        var amount = document.getElementById('ctl00_CenterContentPlaceHolder_lblTotalOrder').innerHTML;
        amount = amount.substring(1,amount.length).replace(',','');
        //payment method
        var paymentMethod;
        var track;
        if(document.getElementById('ctl00_CenterContentPlaceHolder_rbCard').checked)
        {
            paymentMethod = 'Credit Card Selected';
            track=true;
        }
        else if(document.getElementById('ctl00_CenterContentPlaceHolder_rbPhone').checked)
        {
            paymentMethod = 'Phone Selected';
            track=false;
        }
        else if(document.getElementById('ctl00_CenterContentPlaceHolder_rbBank').checked)
        {
            paymentMethod = 'Bank Transfer Selected';
            track=false;
        }
        else if(document.getElementById('ctl00_CenterContentPlaceHolder_rbPayPal').checked)
        {
            paymentMethod = 'PayPal Selected';
            track=true;
        }
        else if(document.getElementById('ctl00_CenterContentPlaceHolder_rbPay4Later').checked)
        {
            paymentMethod = 'Finance Selected';
            track=true;
        }

        TrackTransaction(paymentMethod , amount, null);
        GATracking(paymentMethod,track);
    }
    
    return validate;
}

function ValidateCreditCardPage()
{
    var validate= ($('#aspnetForm').validationEngine({returnIsValid:true}));
    
    if(validate)
    {
        document.getElementById('ctl00_CenterContentPlaceHolder_btnProceedPayment').style.display = 'none';
        document.getElementById('btnFakeProceedPayment').style.display = 'block';
    }
    
    return validate;
}
//calling 77Transaction script
function TrackTransaction(desc,value,orderId)
{   
    //checkout
    if(orderId == null)
        fn77TTransaction(desc, 'value=' + value);   
    else //confirmation
        fn77TTransaction(desc, 'value=' + value + '&orderid=' + orderId);   
}

function GATracking(method,track)
{
    //tracking only for creditcard and paypal
    if (track)
    {
        var pageTracker = _gat._getTracker("UA-1909966-4");
        pageTracker._setAllowHash(false); pageTracker._setAllowLinker(true);
        pageTracker._trackPageview("/ProceedToPayment/" + method);
    }
}
function ShowHideFinanceInfo()
{ 
    var arrow= document.getElementById('imgArrowFinanceInfo');
    if (document.getElementById('financeInfoContainer').style.display == 'none')
    {
        document.getElementById('financeInfoContainer').style.display = 'inline';
        arrow.src = '../images/arrow-up.gif';
        document.getElementById('fincance_container').style.backgroundImage='url(\'../images/blank_bg_big.jpg\')';
        document.getElementById('fincance_container').style.height = '200px';
    }else
    {
        document.getElementById('financeInfoContainer').style.display = 'none';    
        document.getElementById('fincance_container').style.backgroundImage='url(\'../images/blank_bg.jpg\')';
        document.getElementById('fincance_container').style.height = '45px';
        arrow.src = '../images/arrow-down.gif';
    }
}
function HideFinanceInfo()
{
    var arrow= document.getElementById('imgArrowFinanceInfo');
    document.getElementById('financeInfoContainer').style.display = 'none';    
    document.getElementById('fincance_container').style.backgroundImage='url(\'../images/blank_bg.jpg\')';
    document.getElementById('fincance_container').style.height = '45px';
    arrow.src = '../images/arrow-down.gif';
}
function ChangeDiamondView(type,updateResults)
{   
    var oldView = diamondPreferences.DiamondView;
    
    //orderInfoContainer
    document.getElementById('divOrderInfoContainer').style.paddingTop = '0px';
    //advanced results box
    document.getElementById('tblDiamondAdvancedResults').style.display = 'block';
    //carat slider container
    document.getElementById('tblCaratSliderContainer').style.display = 'block';
    //price slider container
    document.getElementById('tblPriceSliderContainer').style.display = 'block';
    
    //tab styles
    $("[id*=liDiamondOption_]").removeClass('diamond_menu_item_selected');
    $("[id*=liDiamondOption_]").addClass('diamond_menu_item');
    $("#liDiamondOption_"+type).removeClass('diamond_menu_item');
    $("#liDiamondOption_"+type).addClass('diamond_menu_item_selected');
    $("[id*=lnkDiamondOption_]").removeClass('link_main_menu_selected');
    $("[id*=lnkDiamondOption_]").addClass('link_main_menu');
    $("#lnkDiamondOption_"+type).removeClass('link_main_menu');
    $("#lnkDiamondOption_"+type).addClass('link_main_menu_selected');    

    diamondPreferences.DiamondView = type;
    if (type!=3)
    {
         //remove the ratios from other shapes
        diamondPreferences.MinRatio = 1.00; //reset ratios here - diamond preferences should have it already
        diamondPreferences.MaxRatio = 5.00;//reset ratios here        
    }
    UpdateDiamondPreference(diamondPreferences);
    
    if (type==1) //Simplified
    {   //orderInfo has to be more padding top        
        document.getElementById('divOrderInfoContainer').style.paddingTop = '10px';
        document.getElementById('contentDiamondControl').style.display = 'none';
        document.getElementById('tblDiamondAdvancedResults').style.display = 'none';
        document.getElementById('tblCaratSliderContainer').style.display = 'none';
        document.getElementById('tblPriceSliderContainer').style.display = 'none';
        document.getElementById('tblSimpleCarat').style.display = 'block';
        //close advanced options
        if (document.getElementById('diamond_control_advanced_container').style.display == 'block')
        {
            document.getElementById('diamond_control_advanced_container').style.display = 'none';                
		}        		
		updateResults=SelectSimplifiedCarat();
    }else if (type==2) //regular
    {
        document.getElementById('tblCaratSliderContainer').style.display = 'block';
        document.getElementById('contentDiamondControl').style.display = 'block';       
        //close advanced options
        if (document.getElementById('diamond_control_advanced_container').style.display == 'block')
        {
            document.getElementById('diamond_control_advanced_container').style.display = 'none';               
		}    
		document.getElementById('tblSimpleCarat').style.display = 'none';
		//i need to do redraw the sliders 
        RedrawSliderPrice();
        RedrawSliderCarat();
		if (oldView!=type)
		{
		    //reset the values for the slider
		    OnCaratSliderLoad($find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderCarat'),null);		   
		}
		//reset price slider
		OnPriceSliderLoad($find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderPrice'),null);
    }else if (type==3) //advanced
    {
        document.getElementById('tblCaratSliderContainer').style.display = 'block';
        document.getElementById('contentDiamondControl').style.display = 'block';
        //force to expand advanced options
        if (document.getElementById('diamond_control_advanced_container').style.display != 'block')
        {
            document.getElementById('diamond_control_advanced_container').style.display = 'block';            	    
		}
		document.getElementById('tblSimpleCarat').style.display = 'none';
		//i need to do redraw the sliders 
        RedrawSliderPrice();
        RedrawSliderCarat();
		if (oldView!=type)
		{
		    //reset the values for the slider
		    OnCaratSliderLoad($find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderCarat'),null);		    
		}
		//reset price slider
		OnPriceSliderLoad($find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderPrice'),null);		
		OnRatioSliderLoad($find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderRatio'),null);
		RedrawSliderRatio();
    }      
    if(updateResults && (oldView!=type))
        UpdateResults(false);       
  
}

function RedrawSliderPrice()
{
    var slider = $find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderPrice'); 
    if(slider!=null && slider!=undefined)
        slider.repaint();
}
function RedrawSliderCarat()
{
    var slider = $find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderCarat'); 
    if(slider!=null && slider!=undefined)
        slider.repaint();
}
function RedrawSliderRatio()
{
    var slider = $find('ctl00_CenterContentPlaceHolder_DiamondsFilter_SliderRatio'); 
    if(slider!=null && slider!=undefined)
        slider.repaint();
}
function SelectSimplifiedCarat()
{ 
    //highlights if it is possible 
    $("[id*=simpCarat_]").removeClass('diamond_control_select_bg_selected');
    $("[id*=simpCarat_]").addClass('diamond_control_select_bg');
    
    if(diamondPreferences.MinCarat>=0.20 && diamondPreferences.MaxCarat <=0.29)
	{
	    $("[id=simpCarat_.20]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.20]").addClass('diamond_control_select_bg_selected');
	}else if(diamondPreferences.MinCarat>=0.30 && diamondPreferences.MaxCarat <=0.39)
	{
	    $("[id=simpCarat_.30]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.30]").addClass('diamond_control_select_bg_selected');
	}else if(diamondPreferences.MinCarat>=0.40 && diamondPreferences.MaxCarat <=0.49)
	{
	   $("[id=simpCarat_.40]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.40]").addClass('diamond_control_select_bg_selected');
	}else if(diamondPreferences.MinCarat>=0.50 && diamondPreferences.MaxCarat <=0.59)
	{
	    $("[id=simpCarat_.50]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.50]").addClass('diamond_control_select_bg_selected');
	}else if(diamondPreferences.MinCarat>=0.60 && diamondPreferences.MaxCarat <=0.69)
	{
	    $("[id=simpCarat_.60]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.60]").addClass('diamond_control_select_bg_selected');
	}else if(diamondPreferences.MinCarat>=0.70 && diamondPreferences.MaxCarat <=0.79)
	{
	   $("[id=simpCarat_.70]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.70]").addClass('diamond_control_select_bg_selected');
	}
	else if(diamondPreferences.MinCarat>=0.80 && diamondPreferences.MaxCarat <=0.89)
	{
	   $("[id=simpCarat_.80]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.80]").addClass('diamond_control_select_bg_selected');
	}
	else if(diamondPreferences.MinCarat>=0.90 && diamondPreferences.MaxCarat <=0.99)
	{
	   $("[id=simpCarat_.90]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_.90]").addClass('diamond_control_select_bg_selected');
	}
	else if(diamondPreferences.MinCarat>=1.00 && diamondPreferences.MaxCarat <=1.24)
	{
	    $("[id=simpCarat_1]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_1]").addClass('diamond_control_select_bg_selected');
	}
	else if(diamondPreferences.MinCarat>=1.25 && diamondPreferences.MaxCarat <=1.49)
	{
	    $("[id=simpCarat_1.25]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_1.25]").addClass('diamond_control_select_bg_selected');
	}
	else if(diamondPreferences.MinCarat>=1.50 && diamondPreferences.MaxCarat <=1.99)
	{
	    $("[id=simpCarat_1.50]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_1.50]").addClass('diamond_control_select_bg_selected');
	}
	else if(diamondPreferences.MinCarat>=2.00)
	{
	    $("[id=simpCarat_2.00]").removeClass('diamond_control_select_bg');
        $("[id=simpCarat_2.00]").addClass('diamond_control_select_bg_selected');
	}
	else  //checking just the minCarat
	{
	    if(diamondPreferences.MinCarat>=0.20 && diamondPreferences.MinCarat <=0.29)
	    {
	        $("[id=simpCarat_.20]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.20]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.20,0.30);
            return false;
	    }else if(diamondPreferences.MinCarat>=0.30 && diamondPreferences.MinCarat <=0.39)
	    {
	        $("[id=simpCarat_.30]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.30]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.30,0.40);
            return false;
	    }else if(diamondPreferences.MinCarat>=0.40 && diamondPreferences.MinCarat <=0.49)
	    {
	       $("[id=simpCarat_.40]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.40]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.40,0.50);
            return false;
	    }else if(diamondPreferences.MinCarat>=0.50 && diamondPreferences.MinCarat <=0.59)
	    {
	        $("[id=simpCarat_.50]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.50]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.50,0.60);
            return false;
	    }else if(diamondPreferences.MinCarat>=0.60 && diamondPreferences.MinCarat <=0.69)
	    {
	        $("[id=simpCarat_.60]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.60]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.60,0.70);
            return false;
	    }else if(diamondPreferences.MinCarat>=0.70 && diamondPreferences.MinCarat <=0.79)
	    {
	       $("[id=simpCarat_.70]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.70]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.70,0.80);
            return false;
	    }
	    else if(diamondPreferences.MinCarat>=0.80 && diamondPreferences.MinCarat <=0.89)
	    {
	       $("[id=simpCarat_.80]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.80]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.80,0.90);
            return false;
	    }
	    else if(diamondPreferences.MinCarat>=0.90 && diamondPreferences.MinCarat <=0.99)
	    {
	       $("[id=simpCarat_.90]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.90]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.90,1.00);
            return false;
	    }
	    else if(diamondPreferences.MinCarat>=1.00 && diamondPreferences.MinCarat <=1.24)
	    {
	        $("[id=simpCarat_1]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_1]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(1.00,1.25);
            return false;
	    }
	    else if(diamondPreferences.MinCarat>=1.25 && diamondPreferences.MinCarat <=1.49)
	    {
	        $("[id=simpCarat_1.25]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_1.25]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(1.25,1.50);
            return false;
	    }
	    else if(diamondPreferences.MinCarat>=1.50 && diamondPreferences.MinCarat <=1.99)
	    {
	        $("[id=simpCarat_1.50]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_1.50]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(1.50,2.00);
            return false;
	    }
	    else if(diamondPreferences.MinCarat>=2.00)
	    {
	        $("[id=simpCarat_2.00]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_2.00]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(2.00,30.00);
            return false;
	    }else //no matching select the first one
	    {
	        $("[id=simpCarat_.20]").removeClass('diamond_control_select_bg');
            $("[id=simpCarat_.20]").addClass('diamond_control_select_bg_selected');
            UpdateDiamPrefByCarat(0.20,0.30);
            return false;
	    }
	}
	return true;
}
function validatePriceGuarantee()
{
    var isValid =$('#form1').validationEngine({returnIsValid:true});
    if(isValid)
        document.getElementById('divLoading').style.display='block';
    return isValid;
}

function showLanguageFromIntPage()
{
    if(window.location.pathname=='/') //home page
    {
	    if(getQuerystring('c')!='')
	    {
             var arrow;  
            //show
            document.getElementById('divLanguageOptionsContent').style.display = 'block';
            $("#divLanguageContent").removeClass("language");
            $("#divLanguageContent").addClass("language_open");        
            arrow = document.getElementById('imgArrowLanguage');
            arrow.setAttribute('src','../images/arrow-up.gif');
            arrow.setAttribute('alt','Close');
            arrow.setAttribute('title','Close');
	    }
    }
}


document.activePopup = new Array;
function openAppointment(){	
 document.activePopup.push(window.open('../AppointmentPopup.aspx', '_blank', 'left=100,top=100,width=550,height=450,scrollbars=no,resizable=yes')); 
}

function closePopup(){	
for(var x=0;x<document.activePopup.length;x++)
	document.activePopup[x].close();
}

function openMoreInfo(){	
 document.activePopup.push(window.open('../RequestMoreInfo.aspx', '_blank', 'left=100,top=100,width=550,height=450,scrollbars=no,resizable=yes')); 
}

function closeMoreInfo(){	
for(var x=0;x<document.activePopup.length;x++)
	document.activePopup[x].close();
}

var sldCurrent=1;

function sliderOffer()
{
    var totWidth=0;
    var positions = new Array();	
    $('#slides .slide').each(function(i){		
        /* Traverse through all the slides and store their accumulative widths in totWidth */		
        positions[i]= totWidth;
        totWidth += $(this).width();		
    });
	
    $('#slides').width(totWidth);

    /* Change the cotnainer div's width to the exact width of all the slides combined */
    $('#menuOffer ul li a').click(function(e,keepScroll){
            /* On a thumbnail click */            
            $('li.menuItem').removeClass('act').addClass('inact');
            $(this).parent().addClass('act');	         
            $("[id*=imgSliderOffer_]").attr('src',function(index, attr){ return attr=attr.replace('_hover.png', '.png'); return attr; });   
            $("img",this).attr('src',$("img",this).attr('src').replace(".png", "_hover.png"));
            var pos = $(this).parent().prevAll('.menuItem').length;			
            $('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
            /* Start the sliding animation */			
            e.preventDefault();
            /* Prevent the default action of the link */		
            // start from the one selected
//            var selected = 0;
//            selected = $("img",this).attr('count');            
//            if ((sldCurrent%$('#menuOffer ul li a').length + 1) != selected)   
//                sldCurrent =  selected - 1;              
           
			if(!keepScroll) clearInterval(itvl);
    });
		
    $('#menuOffer ul li.menuItem:first').addClass('act').siblings().addClass('inact');		 
    
    function autoAdvance()
    {
        if(sldCurrent==-1) return false;
                
        $('#menuOffer ul li a').eq(sldCurrent%$('#menuOffer ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
        sldCurrent++;
    }
    // The number of seconds that the slider will auto-advance in:	
    var changeEvery = 4;
    var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);
    //#end offer slider stuff
}

function AttachFb()
{
    var trg = document.getElementById('fbHolder');
    if(trg!=null)
    {
        if(userPreferences.CountryId==276)
        {
            trg.innerHTML = '<iframe src=\"//www.facebook.com/plugins/like.php?href=http://www.facebook.com/pages/77Diamonds/348268231851218&amp;send=false&amp;layout=button_count&amp;width=200&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21\"scrolling=\"no\" frameborder=\"0\" style=\"border: none; overflow: hidden; padding-left: 5px;width: 80px; height: 21px;" allowtransparency=\"true\"></iframe>';
        }
        else
        {
            trg.innerHTML = '<iframe src=\"//www.facebook.com/plugins/like.php?href=http://www.facebook.com/77Diamonds&amp;send=false&amp;layout=button_count&amp;width=200&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21\"scrolling=\"no\" frameborder=\"0\" style=\"border: none; overflow: hidden; padding-left: 5px;width: 80px; height: 21px;" allowtransparency=\"true\"></iframe>';
        }
    }
}


