﻿//----------------------------------------------------------
//--- Copyright 2009 Edulearn, All Rights Reserved.
//----------------------------------------------------------
//--- Edulearn, Inc. Site Wide Script File

// Register page load event.
//window.onload = onPageLoad;

function onPageLoad()
{
    saveReferrer();
}

function MM_openBrWindow(url, name, features)
{
	// If a course outline is being opened.
	if (name == "outline")
	{
	    // Outline Params.
		features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=620,height=580";
	}
	// If an IT demo video is being opened.
	else if (name == "itVideo")
	{
	    // IT Demo Video Params.
		features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=550,height=455";
	}
	// If an ITC demo video is being opened.
	else if (name == "itcVideo")
	{
	    // ITC Demo Video Params.
		features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=800,height=636";
	}
	// If a small sample clip is being opened.
	else if (name == "smallVideo")
	{
	    // Small Sample Clip Params.
		features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=660,height=520";
	}
	// If a medium sample clip is being opened.
	else if (name == "mediumVideo")
	{
	    // Medium Sample Clip Params.
		features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=822,height=640";
	}
	// If a large sample video is being opened.
	else if (name == "largeVideo")
	{
	    // Large Video Clip Params.
		features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1044,height=729";
	}
	// If a detail popup is being opened.
	else if (name == "detail")
	{
	    // Detail Params.
		features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=580,height=480";
	}
	// If a form is being opened.
	else if (name == "form")
	{	
		// If contact us form is being opened.
		if (url.indexOf("contact_us.php") > -1)
		{
			// Contact Form Params.
			features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=532,height=487";
			// Contact Form URL -- for testing.
			url = "http://www.edulearn.com/forms/contact_us.php";
		}
		// If email a friend form is being opened.
		else if (url.indexOf("email_friend.php") > -1)
		{
			// Email a Friend Form Params.
			features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=532,height=415";
			// Email a Friend Form URL -- for testing.
			url = "http://www.edulearn.com/forms/email_friend.php";
		}
		// If newsletter form is being opened.
		else if (url.indexOf("email_signup.php") > -1)
		{
			// Newsletter Form Params.
			features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=532,height=411";
		}
		// Append source page as query string to URL.
		url += "?sourcepage=" + window.location;
		// Append referrer as query string to URL.
		var referrer = getReferrer();
		if (referrer != "")
		{
			url += "&referrer=" + referrer;
		}
		// Remove invalid characters.
		url = url.replace("#", "");
	}
    // Open popup window.
    window.open(url, name, features);
}

function PreviousPage(returnURL)
{
    var prevURL = document.referrer;
    var thisHost = self.location.hostname;
    if (thisHost.indexOf(".") < thisHost.lastIndexOf("."))
    {
        var hostOffset = thisHost.indexOf(".") + 1;
        thisHost = thisHost.substr(hostOffset);
    }
    if (document.referrer && document.referrer != "")
    {
        // if (prevURL.substr(0, 23) == siteURL) // If referred within site.
        if (document.referrer.indexOf(prevURL) > -1)
        {
            // Send to previous page.
            history.go(-1);
        }
        else // If referred from external site.
        {
            // Send to supplied return url.
            window.location = "http://" + thisHost + returnURL;
        }
    }
    else // If page is accessed directly.
    {
        // Send to supplied return url.
        window.location = "http://" + thisHost + returnURL;
    }
}

function saveReferrer()
{
    var referrer = document.referrer;
    var thisHost = self.location.hostname;
    if (thisHost.indexOf(".") < thisHost.lastIndexOf("."))
    {
        var hostOffset = thisHost.indexOf(".") + 1;
        thisHost = thisHost.substr(hostOffset);
    }
    if (document.referrer && document.referrer != "")
    {
        // If just landed\referred from external site.
        if (document.referrer.indexOf(thisHost) == -1 &&
            document.cookie.indexOf("referrer=") == -1)
        {
            // Save referrer info for this user session only.
            var name = "referrer";
            var value = escape(referrer);
            document.cookie = name + "=" + value + "; path=/; domain=" + thisHost;
        }
    }
}

function getReferrer()
{
    var cname = "referrer";
    if (document.cookie.length > 0)
    {
        start = document.cookie.indexOf(cname + "=");
        if (start != -1)
        {
            start = start + cname.length + 1;
            end = document.cookie.indexOf(";", start);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(start, end));
        }
    }
    return "";
}

function prettyPhotoInit()
{
	$(document).ready(function()
	{
		$("a[rel^='prettyPhoto']").prettyPhoto();
	});
}