﻿

//Shows the search options on the top menu
function ShowSearchOptions(tableRowId)
{
    var row = document.getElementById(tableRowId);
    var topCapDiv = document.getElementById('TopSearchCap');
    var parentTable = document.getElementById('SearchTop');
    if (row != null)
    {
        row.className ="ShowSearchBy";
        topCapDiv.className = "TopSearchCap";
        parentTable.className="SearchBoxDisplay";
        
    }    
}

//Hides the search by row in search controls
function HideSearchByOptions(tableRowId)
{
    var row = document.getElementById(tableRowId);
    var topCapDiv = document.getElementById('TopSearchCap');
    var parentTable = document.getElementById('SearchTop');
    if (row != null)
    {
        row.className ="Hide";
        topCapDiv.className ="";
        parentTable.className="";
    }
}

function disableValidation(institutionRFVId)
{
    var institutionRFV = $get(institutionRFVId);
    ValidatorEnable(institutionRFV, false);
}

function InsitutionListSelectionChnaged(dropdownList,textbox) 
{
    var ddl = $get(dropdownList);
    var institutionTextBox = $get(textbox);
  
    if (ddl!=null)
    {
        var selectedIndex = ddl.selectedIndex;
        var selectedValue =ddl.options[selectedIndex].value;
        var otherInstitutionDiv = $get('_otherInstitutionDiv');

        if (selectedValue != 'other')
        {
            ValidatorEnable(institutionTextBox, false);
            otherInstitutionDiv.className = "DisplayNone";            
        }
        else {
            ValidatorEnable(institutionTextBox, true);
             otherInstitutionDiv.className = "Display";
             //institutionTextBox.disabled = false; 
        }
    }
}

function UserTypeSelectionChanged(radioListId, institutionDDLId,institutionRFVId, otherInstitutionRFVId)
{
    var radioList = ($get(radioListId)).getElementsByTagName("input");
    var institutionList = $get(institutionDDLId);
    var institutionRFV = $get(institutionRFVId);
    var otherInstitutionRFV = $get(otherInstitutionRFVId);
    var universityDiv = $get('_institutionDiv');

    var selectedOption;
    for (var i = 0; i < radioList.length; i++)
    {
        if (radioList[i].checked)
        {
            selectedOption = radioList[i].value;
        }
    }
    if (selectedOption == 'U')
    {
        universityDiv.className = "Display";
        ValidatorEnable(institutionRFV, true);
        var selectedOption = institutionList.options[institutionList.selectedIndex].value;

        if (selectedOption == 'other')
        {
            ValidatorEnable(otherInstitutionRFV, true);
        }
        else
        {
            ValidatorEnable(institutionRFV, false);
        }

    }
    else
    {
        if (institutionRFV != null)
        {
            ValidatorEnable(institutionRFV, false);
        }
        if (otherInstitutionRFV != null)
        {
            ValidatorEnable(otherInstitutionRFV, false);
        }
        universityDiv.className = "DisplayNone";
        
    }
}


function CheckTermsOfCondition(source, argument) {


    var checkBox = $get('_termsCheckbox');
    argument.IsValid=checkBox.checked;
}


function ShowHideShippingAddress(checkBoxId,shippingDivId,validatioSummaryId)
{
    var checkBox = document.getElementById(checkBoxId);
    var shippingDiv = document.getElementById(shippingDivId);
    var validationSummary = document.getElementById(validatioSummaryId);
    
    if (checkBox.checked)
    {
        shippingDiv.style.display = "None";
        ValidatorEnable(validationSummary, false);      
    }
    else
    {
        shippingDiv.style.display = "Inline";
        ValidatorEnable(validationSummary, true);
    }
}

// Add to Cart 

function MouseOverCart(cartButtonId)
{
    var button = document.getElementById(cartButtonId);
    if (button != null)
    {
        button.className ="MouseOverCart";
    }
}

function MouseOutCart(cartButtonId)
{
    var button = document.getElementById(cartButtonId);
    
    if (button !=null)
    {   
        button.className ="MouseOutCart";
    }
}

// end



function BlurSearchOptions(highlightDivId, blurDivId)
{
    var highlightDiv = $get(highlightDivId);
    var blurDiv = $get(blurDivId);

    highlightDiv.className = "";
    blurDiv.className = "BlurSearchSection";
}


//download vitalsource

function DownloadVitalSouceBookShelf(radioButtonListId, hyperlinkId)
{
    var radioList = (document.getElementById(radioButtonListId)).getElementsByTagName("input"); ;
    var link = document.getElementById(hyperlinkId);
    var selectedOption;
    for (var i = 0; i < radioList.length; i++)
    {
        if (radioList[i].checked)
        {
            selectedOption = radioList[i].value;
        }
    }
    if (selectedOption == 'mac')
    {
        link.href = "http://vitalsource.com/downloads/download_chooser/bookshelf?os=mac";
    }
    else
    {
        link.href = "http://vitalsource.com/downloads/download_chooser/bookshelf?os=windows";
    }
}


//

function ReferenceToGAnalytics()
{
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    
}

function TrackPage()
{
    try
    {
        var pageTracker = _gat._getTracker("UA-4078319-3");
        pageTracker._trackPageview();
    } catch (err)
    {
    }
}

function Track404ErrorPage()
{
    try
    {
        var pageTracker = _gat._getTracker("UA-4078319-3");
        pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);

    } catch (err)
    {
    }
}

function ShowSpecialChars(spanId)
{
    var span = document.getElementById(spanId);
    if (span.style.display == "none")
    {
        span.style.display = "inline";
    }
    else
    {
        span.style.display = "none";
    }
}

function ShowIsbnInformation(divId, show)
{
    var isbnDiv = $get(divId);
    if (show)
    {
        isbnDiv.style.display = "block";
    }
    else
    {
        isbnDiv.style.display = "none";
    }
}

function CheckBrowserCookieSettings()
{
    var cookieEnabled;
    var cookieInfoDiv = $get('cookieInfoDiv');
    if (typeof navigator.cookieEnabled == "undefined")
    {
        cookieEnabled = false;
    }
    else
    {
        cookieEnabled = (navigator.cookieEnabled) ? true : false;
    }

    if (cookieEnabled)
    {
        document.cookie = "cookieTest=1"
        cookieEnabled = (document.cookie.indexOf("cookieTest") != -1) ? true : false 
    }
    
    if (!cookieEnabled)
    {
        cookieInfoDiv.style.display = "block";  
    } 
    else
    {
        cookieInfoDiv.style.display = "none";
    }
}


function GetSSLImage()
{
    document.write(unescape("%3Cscript src='https://seal.verisign.com/getseal?host_name=www.myPearsonStore.com.au&amp;size=S&amp;use_flash=NO&amp;use_transparent=NO&amp;lang=en' type='text/javascript'%3E%3C/script%3E"));
}


// Jquery popup

var popupStatus = 0;

function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#AccountLogin").css({
			"opacity": "0.7"
		});
		$("#AccountLogin").fadeOut("slow");
		$("#RetrievePassword").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
	    $("#RetrievePassword").fadeOut("slow");

	    $("#AccountLogin").css({
			"opacity": "100"});
		$("#AccountLogin").fadeIn("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#RetrievePassword").height();
	var popupWidth = $("#RetrievePassword").width();
	//centering
	$("#RetrievePassword").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2
	});
	//only need force for IE6
	
	$("#AccountLogin").css({
		"height": windowHeight
	});
	
}

function showPopup()
{
    loadPopup();
    centerPopup();
}




//end