function createCookie(name, value, days) 
{
    if (days) 
    {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) 
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) 
{
    createCookie(name,"",-1);
}

//	These functions check/set our popup cookie.  The cookie just tells us whether
//	or not a user has been to our site, so we know whether or not to display the
//	popup window.

function been_here_before()
{
    return (readCookie("CC.POPUPALERT") != null);
}

function popup_begone()
{
    createCookie("CC.POPUPALERT", "Do not show popup.", 90);
}

//	This is the "main function".  Call this to display (or not) the popup
//	that hooks the user up with our pretty new site tutorial.

function popup_new_site_message()
{
    if (!been_here_before())
    {
	window_handle = window.open("/popup.html", "CCCPopup", "height=300, width=600" );
	popup_begone();
    }
}


function createCookie(name, value, days) 
{
    if (days) 
    {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) 
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) 
{
    createCookie(name,"",-1);
}

//	These functions check/set our popup cookie.  The cookie just tells us whether
//	or not a user has been to our site, so we know whether or not to display the
//	popup window.

function been_here_before()
{
    return (readCookie("CC.POPUPALERT") != null);
}

function popup_begone()
{
    createCookie("CC.POPUPALERT", "Do not show popup.", 90);
}

//	This is the "main function".  Call this to display (or not) the popup
//	that hooks the user up with our pretty new site tutorial.

function popup_new_site_message()
{
    if (!been_here_before())
    {
	window_handle = window.open("/popup.html", "CCCPopup", "height=300, width=600" );
	popup_begone();
    }
}

function cc3SiteSearch() {
	  
	  
	  if (document.sitesearch.searchbox.value!="") {    
		  window.location.href= window.location.protocol +"//"+ window.location.hostname + ":" + window.location.port + "/content/cc3/en/tools/search.html?hl=en&q=" + document.sitesearch.searchbox.value ;       
	  }
	  else {
	    alert("Please enter something to search.")
	    document.sitesearch.searchbox.focus();
	  }
	}
	
function cc3SearchSite(evt) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (evt) keycode = evt.which;
else return true;

if (keycode == 13)
{
	if (document.sitesearch.searchbox.value!="") {    
		window.location.href= window.location.protocol +"//"+ window.location.hostname + ":" + window.location.port + "/content/cc3/en/tools/search.html?hl=en&q=" + document.sitesearch.searchbox.value ;       
	}
	else {
		alert("Please enter something to search.")
		document.sitesearch.searchbox.focus();
	}
	return false;
}
else
	return true;
}

 function generate() {
        var ourl_company, isbn, issn, result
        ourl_company = escape(document.getElementById("ourl_company").value)
        isbn = escape(document.getElementById("isbn").value)
        issn = escape(document.getElementById("issn").value)
        result = "http://www.copyright.com/ccc/openurl.do"
        if (ourl_company != "") {
            result += "?ourl_company=" + ourl_company;
        }
        else {
            alert("You must specify your Company name.");
            return;
        }
        if (isbn != "") {
            result += "&isbn=" + isbn;
        }
        else {
            if (issn != "") {
                result += "&issn=" + issn;
            }
            else {
                alert("You must specify either an ISBN or an ISSN.");
                return;
            }
        }
        result += "&WT.mc_id=pub_" + ourl_company;
        document.getElementById("querystring").innerHTML = result
    }
	
	
function poptastic(url)
{
var newwindow;
	newwindow=window.open(url,'name','height=400,width=650');
	if (window.focus) {newwindow.focus()}
}


function toggle_vis(e,show,hide) {
    var s = document.getElementById(show);
	var h = document.getElementById(hide);
	var listings = e.parentNode;
	listings = listings.parentNode.getElementsByTagName("li");
	for (var i = 0; i < listings.length; i++) {
		listings[i].className="";
	}
	e.parentNode.className="active";
	if(s.style.display == 'none'){
		s.style.display = 'block';
		h.style.display = 'none';
	}  
}

	


