// JQUERY 
/*  http://docs.jquery.com/Effects/slideToggle#speedcallback */

$(document).ready(function(){
  $("#ctl00_Footer1_linkLegal").click(function () {
		if(!$("#sliderContacts").is(":hidden"))
		{	
			setTimeout("$(\"#sliderTerms\").slideToggle(\"normal\",LoadTerms)", 400);
			$("#sliderContacts").slideToggle("normal",LoadContact);
		}
		else $("#sliderTerms").slideToggle("normal",LoadTerms);
  });
  
  $("#ctl00_Footer1_linkCustomerService").click(function () {
		if(!$("#sliderTerms").is(":hidden"))
		{
			setTimeout("$(\"#sliderContacts\").slideToggle(\"normal\",LoadContact)", 400);		
			$("#sliderTerms").slideToggle("normal",LoadTerms);			
		}
		else  $("#sliderContacts").slideToggle("normal",LoadContact);
  });
  
});

// Triggered in terms and contact
function CloseSliderContacts()
{	
    $("#sliderContacts").slideUp("normal");
}

function CloseSliderSubscription()
{	
    $("#sliderSubscriptions").slideUp("normal");
}

function CloseSliderTerm(){
    $("#sliderTerms").slideUp("normal");
}

function LoadTerms()
{
    if($("#sliderTerms").is(":hidden")) return;
    var country = document.getElementById('countryAbr');
    var targetUrl;
    if(country.value == "fr")
        targetUrl = "html/terms_f.html";
    else
        targetUrl = "html/terms_e.html";
    $.ajax({
      url: targetUrl,
      cache: false, // true/false
      success: function(html){
        $("#termsPlaceholder").replaceWith(html);
      }
    });
}

function LoadContact(){
		 
    if ($("#sliderContacts").is(":visible"))
    {
        if($("#contactPlaceholder").is(":hidden"))
        {
			InitializeContactControls();
            $("#contactPlaceholder").show();
        }
    }else{
        $("#contactPlaceholder").hide();
    }
    
}

function ShowOverImage(obj)
{
    obj.src = obj.src.replace('_off.gif', '_on.gif');
    obj.style.cursor = 'hand';
}

function ShowOutImage(obj)
{
    obj.src = obj.src.replace('_on.gif', '_off.gif');
}

// Use this method to show/hide a control
function ShowControl(control_id_as_string)
{
    var ctPlaceholder = document.getElementById(control_id_as_string);
    
    if(ctPlaceholder != null)
    {
        if(ctPlaceholder.style.display == '') //when the page loads, the display is not set
            ctPlaceholder.style.display = 'none';
            
        ctPlaceholder.style.display = ctPlaceholder.style.display == 'none' ? 'block' : 'none';
    //document.getElementById("ctl00_SubscriptionControl_lblMessage").innerHTML = "";	 
    }
}

function ShowControlSendToFriend(control_id_as_string,type,myname,myemail,product_name,product_id,product_other_id,product_image)
{
    var ctPlaceholder = document.getElementById(control_id_as_string);
    
    if(ctPlaceholder != null)
    {
        if(ctPlaceholder.style.display == '') 
            ctPlaceholder.style.display = 'none';
            
        ctPlaceholder.style.display = ctPlaceholder.style.display == 'none' ? 'block' : 'none';

        switch (type)
        {
            case 1://outfit details
                ctPlaceholder.style.top=100;
            break;
            case 2://product details
                ctPlaceholder.style.top=100;
            break;
        }
        document.getElementById("ctl00_MainContent_SendToFriendControl_sendtofriendSectionArrow").className = "arrow";
        document.getElementById("ctl00_MainContent_SendToFriendControl_imgWait").style.visibility="hidden";

        document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSend").style.display ='inline';
        document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSuccess").style.display ='none';
        document.getElementById("ctl00_MainContent_SendToFriendControl_lblMessage").innerHTML = "";	 

        if (document.getElementById("ctl00_MainContent_SendToFriendControl_hSession_MyName").value=="" && myname!="")
        {
            document.getElementById("ctl00_MainContent_SendToFriendControl_hSession_MyName").value = myname;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hSession_MyEmail").value = myemail;
        }
        document.getElementById("ctl00_MainContent_SendToFriendControl_hImageFilePath").value = product_image;

        document.getElementById("ctl00_MainContent_SendToFriendControl_txtYourName").value = document.getElementById("ctl00_MainContent_SendToFriendControl_hSession_MyName").value;//myname;	 
        document.getElementById("ctl00_MainContent_SendToFriendControl_txtYourEmail").value = document.getElementById("ctl00_MainContent_SendToFriendControl_hSession_MyEmail").value;//myemail;	 
        
        document.getElementById("ctl00_MainContent_SendToFriendControl_txtFriendsName").value = "";	 
        document.getElementById("ctl00_MainContent_SendToFriendControl_txtFriendsEmail").value = "";	 
        document.getElementById("ctl00_MainContent_SendToFriendControl_txtMessage").value = "";	 
        document.getElementById("ctl00_MainContent_SendToFriendControl_chkOpt").checked = false;	 
        
        document.getElementById("ctl00_MainContent_SendToFriendControl_hProductID").value = product_id;
        document.getElementById("ctl00_MainContent_SendToFriendControl_hProductName").value = product_name;
        document.getElementById("ctl00_MainContent_SendToFriendControl_hProduct_Other_ID").value = product_other_id;
        document.getElementById("ctl00_MainContent_SendToFriendControl_hType").value = type;
    }
}

function ShowControlSendToFriend_ShowHidePanels(switchtype,type,myname,myemail,product_name,product_id,product_other_id,product_image)
{
    document.getElementById("ctl00_MainContent_SendToFriendControl_lblMessage").innerHTML = "";	         
    switch(switchtype)
    {
        case "1":
			document.getElementById("ctl00_MainContent_SendToFriendControl_sendtofriendSectionArrow").className = "arrow";
            document.getElementById("ctl00_MainContent_SendToFriendControl_imgWait").style.visibility="hidden";
            document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSuccess").style.display ='none';
            document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSend").style.display ='inline';
            document.getElementById("ctl00_MainContent_SendToFriendControl_txtYourName").value = myname;
            document.getElementById("ctl00_MainContent_SendToFriendControl_txtYourEmail").value = myemail;
            document.getElementById("ctl00_MainContent_SendToFriendControl_txtFriendsName").value = "";
            document.getElementById("ctl00_MainContent_SendToFriendControl_txtFriendsEmail").value = "";
            document.getElementById("ctl00_MainContent_SendToFriendControl_txtMessage").value = "";
            document.getElementById("ctl00_MainContent_SendToFriendControl_chkOpt").checked = false;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hProductID").value = product_id;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hSession_MyName").value = myname;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hSession_MyEmail").value = myemail;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hProductName").innerText = product_name;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hProduct_Other_ID").value = product_other_id;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hType").innerText = type;
            document.getElementById("ctl00_MainContent_SendToFriendControl_hImageFilePath").value = product_image;
            break;
        case "2":			
            document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSend").style.display ='none';
            document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSuccess").style.display ='inline';
            break;
    }
return false;
}

function CloseSendToFriend(control_id_as_string)
{
    var ctPlaceholder = document.getElementById(control_id_as_string);
    
    if(ctPlaceholder != null)
    {
        document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSuccess").style.display ='none';
        document.getElementById("ctl00_MainContent_SendToFriendControl_pnlSend").style.display ='inline';
        ctPlaceholder.style.display = 'none';
    }
}

function CloseCustomPopUp(target_app_as_string)
{
	switch(target_app_as_string)
    {
        case 'stores':        
        	var ctPlaceholder = document.getElementById('findStorePlaceholder');
			if(ctPlaceholder != null)
				ctPlaceholder.style.display = 'none';
        break;
    }
}

function OpenCustomPopUp(target_app_as_string)
{
    switch(target_app_as_string)
    {
        case 'facebook':
        alert('show facebook popup');
        break;
        
        case 'stores':
        	var ctPlaceholder = document.getElementById('findStorePlaceholder');
			if(ctPlaceholder != null)
			{
				if(ctPlaceholder.style.display == '') 
					ctPlaceholder.style.display = 'none';
				if (ctPlaceholder.style.display == 'none')
				{
					ctPlaceholder.style.display = 'block';
					focusPostalCode();
				}
				else	ctPlaceholder.style.display = 'none';							
			}
        break;
    }
}

function LaunchRadio(RadioPath)
{
	window.open(RadioPath, 'Dynamite', "location=0,status=0,scrollbars=0,width=460,height=321");
}

// This function is called from our Flash menu
function GoToPage(page_as_string)
{
    var target = page_as_string;
    var url;
    
    switch(target)
    {
        case 'main':
        url = 'main.aspx';
        break;
        
        case 'collections':
        url = 'Outfits.aspx';
        break;
        
        case 'storelocator':        
        url = 'StoreLocator.aspx';
        break;
        
        case 'blog':
        url = 'dstyle.aspx';
        break;
        
        case 'subscribe':
        //ShowControl('subscribePlaceholder');
        url = 'subscription.aspx';
        break;
    }
    
    
    if(url != undefined)
    {
        window.location = url;
    }
}  