var referring_page = document.referrer;
var shopcartid = readCookie ("shopCartId"); //New 17OCT05-- Needs testing	
var prot1 = self.location.protocol;
var hostname1 = self.location.hostname;
var port1 = self.location.port;
var ptitle = document.title;
if (port1 == "") {port1 = "80"};
var selfurl = self.location.href; // The URL of the page itself, not matter it's in a frame or not
if (prot1 == "http") {
	var urlstring = selfurl.substring(7); //  => http://
} else {
	var urlstring = selfurl.substring(8); //  => https://
}
var url_arr = urlstring.split("/");
var navCode="";
var orgid;
var lang;
var arr_length = url_arr.length;
//last part of the URL -- it is for static pages URL
var page1 = url_arr[arr_length-1];
//last part of the URL -- it is for dynamic pages URL
var page_dot = page1.indexOf(".");
if (page_dot > 0) {
	var page = page1.substring(page_dot, -1);
}
var page_dir = url_arr[arr_length-2];

if (url_arr[1] == "global") {
	countrycode = url_arr[2];
	if (arr_length > 5) {
		site_section = url_arr[4];
		if (site_section == "certification") {
			navCode = "C";
		}
	} else {
		site_section = "General";
	}

	switch (countrycode) { //Set up orgid and lang for portal pages
	//English speaking Countries
		case "us":
			orgid = "1001";
			lang = "US";
			country_base = "http://www.oracle.com/global/us/education/";
		break;
		case "uk":
			orgid = "28";
			lang = "US";
			country_base = "http://www.oracle.com/global/uk/education/";
		break;
		case "ca-en":
			orgid = "46777";
			lang = "US";
			country_base = "http://www.oracle.com/global/ca-en/education/";
		break;
		case "au":
			orgid = "15947";
			lang = "US";
			country_base = "http://www.oracle.com/global/au/education/";
		break;
		case "in":
			orgid = "1080544";
			lang = "US";
			country_base = "http://www.oracle.com/global/in/education/";
		break;
		case "me":
			orgid = "44";
			lang = "US";
			country_base = "http://www.oracle.com/global/me/education/";
		break;
		case "ie":
			orgid = "27";
			lang = "US";
			country_base = "http://www.oracle.com/global/ie/education/";
		break;
		case "sg":
			orgid = "15946";
			lang = "US";
			country_base = "http://www.oracle.com/global/sg/education/";
		break;
		case "nz":
			orgid = "15944";
			lang = "US";
			country_base = "http://www.oracle.com/global/nz/education/";
		break;
		case "za":
			orgid = "30";
			lang = "US";
			country_base = "http://www.oracle.com/global/za/education/";
		break;
		case "be":
			orgid = "52";
			lang = "US";
			country_base = "http://www.oracle.com/global/be/education/";
		break;
		case "lu":
			orgid = "53";
			lang = "US";
			country_base = "http://www.oracle.com/global/lu/education/";
		break;
		case "ph":
			orgid = "15945";
			lang = "US";
			country_base = "http://www.oracle.com/global/ph/education/";
		break;
		case "hk":
			orgid = "15941";
			lang = "US";
			country_base = "http://www.oracle.com/global/hk/education/";
		break;
		case "th":
			orgid = "15949";
			lang = "US";
			country_base = "http://www.oracle.com/global/th/education/";
		break;
		case "my":
			orgid = "15943";
			lang = "US";
			country_base = "http://www.oracle.com/global/my/education/";
		break;
		case "id":
			orgid = "15942";
			lang = "US";
			country_base = "http://www.oracle.com/global/id/education/";
		break;
		case "vn":
			orgid = "15950";
			lang = "US";
			country_base = "http://www.oracle.com/global/vn/education/";
		break;
		case "hr":
			orgid = "13";
			lang = "HR";
			country_base = "http://www.oracle.com/global/hr/education/";
		break;
		case "il":
			orgid = "16";
			lang = "HE";
			country_base = "http://www.oracle.com/global/il/education/";
		break;
		case "ss":
			orgid = "68";
			lang = "US";
			country_base = "http://www.oracle.com/global/ss/education/";
		break;
		case "eg":
			orgid = "42";
			lang = "US";
			country_base = "http://www.oracle.com/global/eg/education/";
		break;
		case "ao-en":
			orgid = "47";
			lang = "US";
			country_base = "http://www.oracle.com/global/ao-en/education/";
		break;
//German speaking countries
		case "de":
			orgid = "34";
			lang = "D";
			country_base = "http://www.oracle.com/global/de/education/";
		break;
		case "ch-de":
			orgid = "29";
			lang = "D";
			country_base = "http://www.oracle.com/global/ch-de/education/";
		break;
		case "at":
			orgid = "26";
			lang = "D";
			country_base = "http://www.oracle.com/global/at/education/";
		break;
//French speaking countries
		case "fr":
			orgid = "38";
			lang = "F";
			country_base = "http://www.oracle.com/global/fr/education/";
		break;
		case "ch-fr":
			orgid = "29";
			lang = "F";
			country_base = "http://www.oracle.com/global/ch-fr/education/";
		break;
		case "ca-fr":
			orgid = "46777";
			lang = "FRC";
			country_base = "http://www.oracle.com/global/ca-fr/education/";
		break;
		case "ao-fr":
			orgid = "47";
			lang = "F";
			country_base = "http://www.oracle.com/global/ao-fr/education/";
		break;
// Latin Spanish speaking countries		
		case "mx":
			orgid = "189915";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/mx/education/";
		break;
		case "ar":
			orgid = "14515";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/ar/education/";
		break;
		case "pr":
			orgid = "1000254";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/pr/education/";
		break;
		case "ve":
			orgid = "1000255";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/ve/education/";
		break;
		case "cr":
			orgid = "1000257";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/cr/education/";
		break;
		case "co":
			orgid = "1000258";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/co/education/";
		break;
		case "cl":
			orgid = "1000261";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/cl/education/";
		break;
		case "pe":
			orgid = "1000263";
			lang = "ESA";
			country_base = "http://www.oracle.com/global/pe/education/";
		break;
		
//Individual countries with own language
		case "jp":
			orgid = "70";
			lang = "JA";
			country_base = "http://www.oracle.com/global/jp/education/";
		break;
		case "cn":
			orgid = "1243197";
			lang = "ZHS";
			country_base = "http://www.oracle.com/global/cn/education/";
		break;
        case "cz": 
        	orgid = "9";
        	lang = "CS";
			country_base = "http://www.oracle.com/global/cz/education/";
        break;
		case "dk":
			orgid = "36";
			lang = "DK";
			country_base = "http://www.oracle.com/global/dk/education/";
		break;
		case "es":
			orgid = "51";
			lang = "E";
			country_base = "http://www.oracle.com/global/es/education/";
		break;
		case "fi":
			orgid = "39";
			lang = "SF";
			country_base = "http://www.oracle.com/global/fi/education/";
		break;
		case "sk":
			orgid ="11";
			lang="SK";
			country_base = "http://www.oracle.com/global/sk/education/";
		break;
		case "it":
			orgid = "32";
			lang = "I";
			country_base = "http://www.oracle.com/global/it/education/";
		break;
		case "kr":
			orgid = "15";
			lang = "KO";
			country_base = "http://www.oracle.com/global/kr/education/";
		break;
		case "nl":
			orgid = "41";
			lang = "NL";
			country_base = "http://www.oracle.com/global/nl/education/";
		break;	
		case "no":
			orgid = "37";
			lang = "N";
			country_base = "http://www.oracle.com/global/no/education/";
		break;	
		case "pt":
			orgid = "35";
			lang = "PT";
			country_base = "http://www.oracle.com/global/pt/education/";
		break;
		case "pl":
			orgid = "10";
			lang = "PL";
			country_base = "http://www.oracle.com/global/pl/education/";
		break;
		case "br":
			orgid = "378219";
			lang ="PTB";
			country_base = "http://www.oracle.com/global/br/education/";
		break;
		case "ro":
			orgid = "54";
			lang = "RO";
			country_base = "http://www.oracle.com/global/ro/education/";
		break;	
		case "se":
			orgid = "40";
			lang = "S";
			country_base = "http://www.oracle.com/global/se/education/";
		break;	
		case "tw":
			orgid = "17";
			lang = "ZHT";
			country_base = "http://www.oracle.com/global/tw/education/";
		break;
		case "hu":
			orgid = "8";
			lang = "HU";
			country_base = "http://www.oracle.com/global/hu/education/";
		break;
		case "si":
			orgid = "12";
			lang = "SL";
			country_base = "http://www.oracle.com/global/si/education/";
		break;
		case "tr":
			orgid = "18";
			lang = "TR";
			country_base = "http://www.oracle.com/global/tr/education/";
		break;
		case "ee":
			orgid = "57";
			lang = "ET";
			country_base = "http://www.oracle.com/global/ee/education/";
		break;
		case "lt":
			orgid = "59";
			lang = "LT";
			country_base = "http://www.oracle.com/global/lt/education/";
		break;
		case "lv":
			orgid = "58";
			lang = "LV";
			country_base = "http://www.oracle.com/global/lv/education/";
		break;
	}
} else {
//	site_section = "No Category";
	if (url_arr[1] == "cgi-bin") {
		if ((url_arr[2] == "shopcart") || (url_arr[2] == "checkout")) {
			site_section = "Shopping Cart";
		}
	}
}

if (orgid) {
	document.cookie = 'p_org_id='+orgid+'; domain=.oracle.com; path=/';
	document.cookie = 'p_lang='+lang+'; domain=.oracle.com; path=/';
}

// These variables are all initialized for dynamic/midtier pages.  
dynamic_base = prot1+"//"+hostname1;
static_base = prot1+"//"+hostname1;
config_base = prot1+"//"+hostname1;
dad_pathname = "/pls/web_prod-plq-dad";
ocom_base = "http://www.oracle.com";

switch (hostname1) { 
	//Set variables based on environment/host
	case "www.oracle.com":
		dynamic_base = prot1+"//education.oracle.com"; //Needs to be changed to Production only for Portal pages
    	static_base = prot1+"//www.oracle.com"; //Needs to be changed to Production only for Portal pages
    	config_base = prot1+"//education.oracle.com"; //Needs to be changed to Production only for Portal pages
		environment_code = "OUP"
	break;
	case "education-dev.oracle.com":
		environment_code = "OUD"
	break;
	case "education-dev.us.oracle.com":
		environment_code = "OUD"
	break;
	case "education-uat.oracle.com":
		environment_code = "OUU"
	break;
	case "education-stage.oracle.com":
		environment_code = "OUS"
	break;
	case "education.oracle.com":
		environment_code = "OUP"
	break;
}
function readCookie (CookieName) 
{
  var CookieString = document.cookie;
  var CookieSet = CookieString.split(';');
  var SetSize = CookieSet.length;
  var CookiePieces;
  var ReturnValue = "";

  for (var i = 0; ((i < SetSize) && (ReturnValue == "")); i++)
  {
    CookiePieces = CookieSet[i].split ('=');

    if (CookiePieces[0].substring (0,1) == ' ') {
		CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
    }

    if (CookiePieces[0] == CookieName) {
		ReturnValue = CookiePieces[1];
    }

  }
return ReturnValue;
}


function restart() { 
		window.location.reload();
		win.close();
}

function NetCall(country) {
      win = window.open("http://education.oracle.com/education/netcall/talk_to_us_"+country+".html",'netcall',"width=440,height=320,menubar=no,location=no");
}

function SetCookie (name,value,expires) {
  document.cookie = name + "=" + escape (value) +
                    ((expires) ? "; expires=" + expires.toGMTString() : "") +
                    "; path=/; domain=.oracle.com";
}
