/*
*******************************************************************
* CONTENT REPOSITIONING SCRIPT
*===============================
*
*Script Created by: Cornel Boudria May 25, 2004
*
*
********************************************************************
*/

var g_LocaleReference;
var g_PlacedContainerReference;
var runOnce = false;

var g_LocaleList = new Array();
var g_ContentList = new Array();
var g_LocaleContentPair = new Array();


function Initialize(lrTagName,crTagName)
{
var tempLocaleList = document.getElementsByTagName(lrTagName);
var tempContentList = document.getElementsByTagName(crTagName);
var n = 0;
var hold = "";

//FILL GLOBAL LOCALELIST ARRAY
for(x=0; x < tempLocaleList.length; x++)
{
 hold = tempLocaleList[x].id;
 if(hold != "") {g_LocaleList[n] = hold; n++;}
}
//->

//CLEAR DUMMY VARIABLES
hold = null;
hold = "";
n = 0;
//->

//FILL GLOBAL CONTENTLIST ARRAY
for(x=0; x < tempContentList.length; x++)
{
 hold = tempContentList[x].id;
 if(hold != "") {g_ContentList[n] = hold; n++;}
}
//->

var diff = 0;
/*
if(g_LocaleList.length == g_ContentList.length) {}
if(g_LocaleList.length > g_ContentList.length) {cnt=g_ContentList.length; diff = g_LocaleList.length - g_ContentList.length;}
if(g_LocaleList.length < g_ContentList.length) {cnt=g_LocaleList.length; diff = g_LocaleList.length - g_ContentList.length;}
*/
diff = g_LocaleList.length - g_ContentList.length;
SyncContentWithLocale(g_LocaleList.length,diff);
}

function SyncContentWithLocale(count,fDiff)
{

var MatchArray = new Array();
var matches = false; var MatchesCnt = 0;
 for(x=0; x < count; x++)
 {
  for(y=0; y < count-fDiff; y++) //(y=count - 1; y >= 0; y--)
  {
   if(g_LocaleList[x].substring(g_LocaleList[x].indexOf("_Locale"),0)==g_ContentList[y].substring(g_ContentList[y].indexOf("_Content"), 0))
   {
 //   alert("'" + g_LocaleList[x] + "'" + " at " + x + " matches " + "'" + g_ContentList[y] + "'" + " at " + y);
    MatchArray[MatchesCnt] = x + "," + y;  //alert(MatchArray[MatchesCnt]); //g_LocaleList[x];
    MatchesCnt++;    
   }
  }//-> END INNER FOR LOOP
 }//-> End OUT FOR LOOP

g_LocaleContentPair = MatchArray;

positionElements(g_LocaleContentPair);
}

function positionElements(oArray)
{

var tempL = 0;
var tempC = 0;
var dummy = new Array();
 for(x=0; x < oArray.length; x++)
 { 
  dummy = oArray[x].split(",");
  tempL = parseInt(dummy[0]);
  tempC = parseInt(dummy[1]);
 // alert("g_LocaleList: " + g_LocaleList[tempL] + "\ng_ContentList: " + g_ContentList[tempC]);
  runOnce = false;
  initLocaleRefContRef(g_LocaleList[tempL],g_ContentList[tempC]);
 }
}


function PlaceContainer(lr, car){

g_LocaleReference = lr;
g_PlacedContainerReference = car;


initLocaleRefContRef(g_LocaleReference, g_PlacedContainerReference);
}



function initLocaleRefContRef(LocaleRef,ContAreaRef){

//Padding Routine***********************************************
if(document.getElementById(LocaleRef).style.padding != ""){
var padStr = document.getElementById(LocaleRef).style.padding; padStr = padStr.split("px");
}
else {var padStr = new Array; padStr[0] = 0;}
//**************************************************************->
padStr[0] = parseInt(padStr[0]);
//Border Size Routine***********************************************

//--LEFT BORDER--
if(document.getElementById(LocaleRef).style.borderLeftWidth != ""){

var borderLeftWidth = document.getElementById(LocaleRef).style.borderLeftWidth;
borderLeftWidth = borderLeftWidth.split("px");
//borderLeftWidth = (borderLeftWidth.substring(borderLeftWidth.length,borderLeftWidth.length - 2) == "px")  borderLeftWidth.split("px") : ;
}
else {var borderLeftWidth = new Array; borderLeftWidth[0] = 0;}


//--RIGHT BORDER--

if(document.getElementById(LocaleRef).style.borderRightWidth != ""){
var borderRightWidth = document.getElementById(LocaleRef).style.borderRightWidth; borderRightWidth = borderRightWidth.split("px");
}
else {var borderRightWidth = new Array; borderRightWidth[0] = 0;}

var borderInt = parseInt(borderLeftWidth[0]) + parseInt(borderRightWidth[0]);


//alert(document.getElementById(LocaleRef).style.borderRightWidth);
//--TOP BORDER--



//--BOTTOM BORDER--
//**************************************************************->



//Content Container Properties
var top = getPageOffsetTop(document.getElementById(LocaleRef));
var left = getPageOffsetLeft(document.getElementById(LocaleRef));
var contentWidth = document.getElementById(LocaleRef).offsetWidth - borderInt - padStr[0];// - borderStr;

//->



//Locale Properties:
var localeHeight = document.getElementById(ContAreaRef).offsetHeight;
//->

//alert("Locale top, Left, height, width:: " + top + ", " + left + ", " + localeHeight + ", " + contentWidth);

//SET content properties:
document.getElementById(ContAreaRef).style.top = top + "px";
document.getElementById(ContAreaRef).style.left = left + "px";
document.getElementById(ContAreaRef).style.width = contentWidth + "px";

                                                   //document.getElementById(LocaleRef).offsetWidth - padStr[0] + "px";
//SET Locale Height:
document.getElementById(LocaleRef).style.height = localeHeight + "px";
                                            //document.getElementById(ContAreaRef).offsetHeight;


//Display Content Area:
document.getElementById(ContAreaRef).style.visibility = "visible";

//MOZILLA WYSIWYG - Resize Content and Location Reference Again to ensure Proper Sizing
if (runOnce == false) {runOnce = true; initLocaleRefContRef(LocaleRef,ContAreaRef);}
}

//*********************
//* UTILITY FUNCTIONS *
//*********************
//Following Code Courtesy of Brainjar.com
//------------------------------------------------->
function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the y coordinate of an element relative to the page.

  y = el.offsetTop;
  
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}
//------------------------------------------------->

function getViewportHeight() {

    // supported in Mozilla, Opera, and Safari
     if(window.innerHeight)
         return window.innerHeight;
	
    // supported in standards mode of IE, but not in any other mode
     if(window.document.documentElement.clientHeight)
         return document.documentElement.clientHeight;
	
    // supported in quirks mode, older versions of IE, and mac IE (anything else).
    return window.document.body.clientHeight;
}

function getViewportWidth() {

    // supported in Mozilla, Opera, and Safari
     if(window.innerWidth)
         return window.innerWidth;
	
    // supported in standards mode of IE, but not in any other mode
     if(window.document.documentElement.clientWidth)
         return document.documentElement.clientWidth;
	
    // supported in quirks mode, older versions of IE, and mac IE (anything else).
    return window.document.body.clientWidth;
}

//**************************
//* WINDOW RESIZE HOOK.....*
//**************************
//window.onresize = function() {if(g_LocaleReference!=""&&g_PlacedContainerReference!="") {runOnce = false; initLocaleRefContRef(g_LocaleReference, g_PlacedContainerReference);}}
window.onresize = function() {if(g_LocaleContentPair!="") {runOnce = false; positionElements(g_LocaleContentPair);}}
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->