/*
  Date Created: 22nd Apr 2009 - Pragyandipta Tripathy
  Last Modified: 24th Apr 2009 - Pragyandipta Tripathy

This javascript file contains all the common functions for all the common operations (Except the Ajax functions)
  Ajax functions are inside faq_ajax_tool.js file
  The content of the body is under faq_content.js file
		"section" - term used in the comments of this file. 
		A section is a div id (div) which will hold all the questions/answers of a category
*/


//Global Variables; Used in many functions.
var loaderFunc="";
var queData = "";
var anchor_list;
var anchVal = "";
var Static_Base = "http://www.oracle.com";
var Dynamic_Base = "/pls/web_prod-plq-dad";

//For scrolling
	var divheight = 0;
	var scroll_cnt = 0;
	var speed = 30;
	var smooth = 1;
	var motion;
//---------------------------------------------------------------------------------------------------------------------------------------
//Script to open all the links in new window except...Javascript calls
//var newwindow="_blank";
function hyperlinks()
{		
	if (!document.getElementsByTagName) return;
	var anchorAll = document.getElementsByTagName("a");
	for (var i=anchorAll.length-1; i>=0; i--) 
	{
		var anchor = anchorAll[i];
		if (anchor.href && anchor.href.indexOf("javascript:") == -1)
			anchor.target = "_blank";
	}
}

//Preload images
function loadimg()
{
	var pl_images=new Array();
	for (i=0;i<loadimg.arguments.length;i++)
	{
		pl_images[i]=new Image();
		pl_images[i].src=loadimg.arguments[i];
	}	
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*This function will handle the anchor links. It will pick the "anchor_list" variable from faq_content.js file
	Then it will pick the anchor link value from the address bar and will compare it with all the values of anchor_list,
	if it matchs it will go to that link
*/
function iniLoad(org,lan) //Called from "setPage()" which is in faq_ajax_tool.js. This is called after all the sections are loaded.
{
	for (var num=1; num<=5; num++) //For the 5 "setAnchors_" functions on faq_content.js file
	{
		var url_split=window.location.href.split("#");
		if (url_split[1])
		{
			loadimg("/images/hideshow_m.gif", "/images/hideshow_p.gif");
			var an = "setAnchors"+ num + "();";
			eval(an);

			anchVal = url_split[1].replace(/head/g,"");
			var anchor_list_split = anchor_list.split("@@");
			var anchor_sublist_split;

			for (var z=0; z< anchor_list_split.length-1; z++)
			{
				anchor_sublist_split = anchor_list_split[z].split(",");
				for (var y=1; y< anchor_sublist_split.length-1; y++)
					if(anchVal == anchor_sublist_split[y])	
					{
						showdata(anchor_sublist_split[0],org,lan);
						return false;
					}		
			}
		}
		else
		{
			anchVal = '0';
		}
	}
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*
	If the section is already open once, it will just show it if it is hidden and will hide it if it is shown
	If the section is never open before, it will show the preloder image and will call setLoaderFunction() function (Ajax) passing the section id (div id)
*/
function showdata(section,orgid,lang) //either called from the above function iniload() if anchore is present or if the user clicks on a section head
{
	var qaSection = document.getElementById(section);

	if (qaSection.innerHTML!="")
		if (navigator.appName=="Microsoft Internet Explorer")
			runEffect(section,"5");
		else
			runEffect(section,"700");
	else
	{
		qaSection.innerHTML="<img border=0 src=/education/faq/faq_loader.gif>";
		setLoaderFunction(section);
	}
}

function runEffect(qblock,speed)
{
	var selectedEffect = "blind";
	var options = {};
	$("#"+qblock).toggle(selectedEffect,options,speed);
};
//---------------------------------------------------------------------------------------------------------------------------------------
/*This Function will set the global variable "loaderFunc" first
  Then it will set the call1 variable the section id, appended with "a_". 
	E.g. If the section id is (1Q1A), call1 will be a_1Q1A(); and it will be evaluated (this function will be executed).
	Why we are appending it with "a" because in js, a function name can't start with a numeric value. (a is for attribute function)
	Go to faq_content.js for this function
*/
function setLoaderFunction(name)
{
    loaderFunc = name;
	var call1 = "a_"+ name + "();";
	eval(call1);
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*This function is for showing/hiding individual question/answer*/
function toggle(id) 
{ 
	var el = document.getElementById(id);
	if (el.style.display=="none") 
	{ 
		el.style.display="block"; 
		eval('document.images["I' + id + '"].src = ' + '"/images/hideshow_m.gif"');    
	} 
	else 
	{ 
		el.style.display="none";  
		eval('document.images["I' + id + '"].src = ' + '"/images/hideshow_p.gif"');    
	} 
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*This function is for showing/hiding all the questions/answers for a perticular section*/
function toggleall(open,thisBoxx)
{
	var allImg = document.getElementsByTagName("img");
	var allSpan = document.getElementsByTagName("dt");

	for (var j=0; j< allImg.length; j++)
		if (allImg[j].parentNode.parentNode.parentNode.id==thisBoxx)	//thisBoxx will have the section id. parentNode returns the parrent object of an element
			if (open)
				eval('allImg['+j+'].src = "/images/hideshow_m.gif"');    
			else
				eval('allImg['+j+'].src = "/images/hideshow_p.gif"');    
	
	for (var i=0; i< allSpan.length; i++)
		if (allSpan[i].parentNode.parentNode.id==thisBoxx)
			if (open)
				allSpan[i].style.display="block"; 
			else
				allSpan[i].style.display="none"; 
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*This function is used to build the content of the page*/
function boxTop(boxCode, stylecode) 
{
var topp ="<div class='box"+boxCode+"'><div class='box"+boxCode+"_lb'><div class='box"+boxCode+"_rb'><div class='box"+boxCode+"_bb'><div class='box"+boxCode+"_blc'><div class='box"+boxCode+"_brc'><div class='box"+boxCode+"_tb'><div class='box"+boxCode+"_tlc'><div class='box"+boxCode+"_trc'><div class='box"+boxCode+"_area'><div class='box"+boxCode+"_area2' style='margin-bottom:-"+stylecode+"'>";

var topp2 ='<div class="newRCbox'+boxCode+'" style="'+stylecode+'">';

if (navigator.userAgent.toLowerCase().indexOf("msie")!=-1) 
	return topp 
else 
	return topp2;
}

//---------------------------------------------------------------------------------------------------------------------------------------
/*This function is used to build the content of the faq page*/
function getTop(anc,que)
{
	queData =  "<div style='padding-top:10px;'><a name=Q"+anc+"></a> <a id='s_h' href=javascript:toggle('A"+anc+"');>";
	queData += "<img src='/images/hideshow_p.gif' name = 'IA"+anc+"' border='0' alt=''></a> ";
	queData += "<span style='vertical-align:top;'><a href=javascript:toggle('A"+anc+"');><strong>"+pri(que)+"</strong></a></span>";
	queData += "<dt id='A"+anc+"' style='display:none;' ><div style='padding:1px 6px 0px 6px;'>";
	queData += boxTop('2','padding:4px;');
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*This function is used to build the content of the faq page*/
function getT(anc,que)
{
	queData =  "<div><a name=Q"+anc+"></a> <a id='s_h' href=javascript:toggle('A"+anc+"');>";
	queData += "<img src='/images/hideshow_p.gif' name = 'IA"+anc+"' border='0' alt=''></a> ";
	queData += "<span style='vertical-align:top;'><a href=javascript:toggle('A"+anc+"');><strong>"+pri(que)+"</strong></a></span>";
	queData += "<dt id='A"+anc+"' style='display:none;' ><div style='padding:1px 6px 0px 6px;'>";
	queData += boxTop('2','padding:4px;');
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*This function is used to build the content of the page*/
function getBottom()
{
	if (navigator.userAgent.toLowerCase().indexOf("msie")!=-1)
		queData +=  "</div></div></div></div></div></div></div></div></div></div></div></div></dt></div>";
	else
		queData +=  "</div></div></dt></div>";
	return queData;
}
//---------------------------------------------------------------------------------------------------------------------------------------
/*This function will build and print the show all/hide all links for a section*/
function pri_sh(cont)
{
	return "<div style='text-align:right;margin-bottom:-15px;'><a href=javascript:toggleall(true,'"+cont+"');>"+pri('PE_FaqsShowAll')+"</a> | <a href=javascript:toggleall(false,'"+cont+"');>"+pri('PE_FaqsHideAll')+"</a></div>";
}



function pri_section(sect,att)
{
	var thisSec = boxTop('1');
	thisSec += "<a name='"+sect+"head' id='"+sect+"head'></a><h2><span class='contents'><a href=javascript:showdata('"+sect+"','"+p_org_id+"','"+p_lang+"');>"+pri(att)+"</a></span></h2>";
	thisSec += "<div id='"+sect+"' style='display:block; overflow:hidden;'></div>";
	thisSec += "</div></div></div></div></div></div></div></div></div></div>";
	return thisSec;
}
