// Copyright Paid On Results.


var PORisOpera = (navigator.userAgent.indexOf('Opera') != -1);
var PORisIE = (!PORisOpera && navigator.userAgent.indexOf('MSIE') != -1)

var ElementWidths = new Array;
var ElementHeights = new Array;

var porLeftPosition = new Array;
var porTopPosition = new Array;

var porMouseY = 0;
var porMouseX = 0;

var currentPage = 1;
var no_pages = 0;

var rowStates = new Array;

function DisplayFloatMenu (fieldName, menuDiv, offCallBack){

findObjectPos_POR(document.getElementById(fieldName));

scrollHeight = getScrollHeight_POR();

truePORMouseY = porMouseY;

if (PORisIE){
truePORMouseY += scrollHeight;
}

getPageHeight_POR();

myHeight = myHeight + scrollHeight;

leftPos = porMouseX;
topPos = truePORMouseY;

if ((topPos + parseInt(document.getElementById(menuDiv).style.height)) > myHeight){
topPos = truePORMouseY - parseInt(document.getElementById(menuDiv).style.height);
}

if ((leftPos + parseInt(document.getElementById(menuDiv).style.width)) > myWidth){
leftPos = porMouseX - parseInt(document.getElementById(menuDiv).style.width);
topPos = topPos;
}

document.getElementById(menuDiv).style.left = leftPos + "px";
document.getElementById(menuDiv).style.top = topPos + "px";
document.getElementById(menuDiv).style.visibility = "visible";

key = fieldName + menuDiv;

if (offCallBack == ''){
timeOutRecord[key] = setTimeout("menuOff('"+fieldName+"', '" + menuDiv +");",1000);
} else {
timeOutRecord[key] = setTimeout("menuOff('"+fieldName+"', '" + menuDiv +"',"+offCallBack+");",1000);
}

}

function ExtendedReport() {

findObjectPos_POR(document.getElementById('extReportLink'));

scrollHeight = getScrollHeight_POR();

truePORMouseY = porMouseY;

if (PORisIE){
truePORMouseY += scrollHeight;
}

getPageHeight_POR();

myHeight = myHeight + scrollHeight;

leftPos = porMouseX + 12;
topPos = truePORMouseY;

if ((topPos + parseInt(document.getElementById('extendedReportMenu').style.height)) > myHeight){
topPos = truePORMouseY - 12 - parseInt(document.getElementById('extendedReportMenu').style.height);
}

document.getElementById('extendedReportMenu').style.left = leftPos + "px";
document.getElementById('extendedReportMenu').style.top = topPos + "px";
document.getElementById('extendedReportMenu').style.visibility = "visible";

setTimeout("menuOff('"+'extReportLink'+"', '" + 'extendedReportMenu' +"');",1000);

}

function LoadExtendedReport(url) {
window.location = url;
}

function OverviewReport(session, period) {
window.location = "/cgi-bin/overview.pl?session=" + session + "&merchants=" + popupMenuMerchantID + "&quick_period=" + period;
}

function GetMerchantCreative(session, siteID) {
window.location = "/cgi-bin/pickup-links.pl?session="+session+"&site_id="+siteID;
}

function BackHome(session) {
window.location = "/cgi-bin/home.pl?session=" + session;
}


function CreativeReport(session, period) {
window.location = "/cgi-bin/creative.pl?session=" + session + "&merchants=" + popupMenuMerchantID + "&quick_period=" + period;
}

function MerchantWebsite(session){
window.open('/cgi-bin/visit-merchant.pl?session=' + session + '&site_id=' + popupMenuMerchantID);
}

function MerchantProfile(session, period) {
window.location = "/cgi-bin/view-merchant.pl?session=" + session + "&site_id=" + popupMenuMerchantID;
}

var maximumTableWidth = 0;

function setCustomiseBoxSize(tableWidth) {

if (document.getElementById('customiseBoxDiv')){

if (maximumTableWidth > 0){

findObjectPos_POR(document.getElementById('edgeMarkerImage'));

curleft = curleft + 10;

pageWidth = curleft - 180;

if (maximumTableWidth > pageWidth){
document.getElementById('customiseBoxDiv').align = "left";
document.getElementById('customiseBoxSize').style.width = (pageWidth - 16) + "px";
} else {
document.getElementById('customiseBoxDiv').align = "center";
document.getElementById('customiseBoxSize').style.width = (maximumTableWidth - 14) + "px";
}

document.getElementById('customiseBoxDiv').style.visibility = "visible";

setTableTools();

}

}

}

function setTableTools() { 

findObjectPos_POR(document.getElementById('edgeMarkerImage')); 

curleft = curleft + 10;

pageWidth = curleft - 180;

if (maximumTableWidth > pageWidth){
toolsPaddingWidth = (maximumTableWidth - pageWidth) + 7;
} else {
toolsPaddingWidth = 7;
} 

for (var x= 1; x <= 3; x++) {

fieldName = "tableToolsPadding" + x;

if (document.getElementById(fieldName)){ 
document.getElementById(fieldName).style.width = toolsPaddingWidth + "px";
}

}

}

function PageResize() {

try
{
CustomResize();
}
catch(err)
{

}

setCustomiseBoxSize();

}

function PageStartUp() {

try
{
CustomStartUp();
}
catch(err)
{

}

}

function ExportTableData(tableID, selectedFormat) {

eval("tableForm = document.tableForm"+tableID+";");

if (selectedFormat != ''){
for (i=0;i<tableForm.exportFormat.length;i++) {
if (tableForm.exportFormat[i].value == selectedFormat) {
tableForm.exportFormat[i].checked = true;
}
}
}

tableForm.action = "/cgi-bin/export-table.pl?session=" + tableForm.session.value;
tableForm.submit();

}

function CreateTableShadow(tableID) {

tableDivID = "tableID" + tableID;

if (! document.getElementById('tableShadow')){

if (navigator.appName == "Microsoft Internet Explorer"){
var shadowDIV = document.createElement('<div class="VEShadow2" name="tableShadow" id="tableShadow" style="height:1px;width:1px;position:absolute;visibility:hidden;left: 0px;top: 0px; opacity: .50;overflow:hidden;background-color:#999999;z-index:98;"></div>');
} else {
var shadowDIV = document.createElement('div');
shadowDIV.setAttribute('name', 'tableShadow');
shadowDIV.setAttribute('id', 'tableShadow');
shadowDIV.setAttribute('style', 'height:1px;width:1px;position:absolute;visibility:hidden;left: 0px;top: 0px; opacity: .50;overflow:hidden;background-color:#999999;z-index:98; -moz-opacity: 0.5;');
}

try
{
document.getElementsByTagName('body')[0].appendChild(shadowDIV);
}
catch(err)
{
// Do Nothing
}

}

if (document.getElementById('tableShadow')){

tableHeight = parseInt(document.getElementById(tableDivID).clientHeight) - 25;
tableWidth = parseInt(document.getElementById(tableDivID).clientWidth);

findObjectPos_POR(document.getElementById(tableDivID));

curtop = curtop + 25;

html = '<table border="0" cellpadding="0" cellspacing="0"><tr><Td width="7" align="left" valign="top" bgcolor="#999999"><img src="/images/curved/blue-TL-1px-999999.gif"></td><td bgcolor="#999999" align="left" style="color:#ffffff;padding:6px;" width="'+ (tableWidth - 14) +'">&nbsp;</td><Td width="7" align="right" bgcolor="#999999" valign="top"><img src="/images/curved/blue-TR-1px-999999.gif" width="7" height="7"></td></tr><tr><td></td><td><div style="width:10px;height:'+ (tableHeight - 7) +'px;">&nbsp;</div></td><td></td></tr></table>';

document.getElementById('tableShadow').innerHTML = html;

document.getElementById('tableShadow').style.width = tableWidth + "px";
document.getElementById('tableShadow').style.height = tableHeight + "px";
document.getElementById('tableShadow').style.left = curleft + "px";
document.getElementById('tableShadow').style.top = curtop + "px";
document.getElementById('tableShadow').style.visibility = "visible";

}

}

function TableExport(tableID) {

CreateTableShadow(tableID);

callingFieldName = "exportPrompt" + tableID;

tableDivID = "tableID" + tableID;
tableWidth = parseInt(document.getElementById(tableDivID).clientWidth);

findObjectPos_POR(document.getElementById(tableDivID));

curtop = curtop + 25;

holdingField = "exportTableHolder" + tableID;

paddingID = "tableToolsPadding" + tableID;
paddingDiff = parseInt(document.getElementById(paddingID).style.width) - 7; 

contentWidth = parseInt(document.getElementById(holdingField).clientWidth);

leftPos = (curleft + tableWidth) - paddingDiff - contentWidth - 2;
topPos = curtop;

document.getElementById(holdingField).style.zIndex = "99";
document.getElementById(holdingField).style.width = contentWidth + "px";
document.getElementById(holdingField).style.left = leftPos + "px";
document.getElementById(holdingField).style.top = topPos + "px";
document.getElementById(holdingField).style.visibility = "visible";

setTimeout("menuOff('"+callingFieldName+"', '" + holdingField +"', ShadowOff);",1000);

}

function TableSort(tableID) {

CreateTableShadow(tableID);

callingFieldName = "sortPrompt" + tableID;

tableDivID = "tableID" + tableID;
tableWidth = parseInt(document.getElementById(tableDivID).clientWidth);

findObjectPos_POR(document.getElementById(tableDivID));

curtop = curtop + 25;


holdingField = "sortTableHolder" + tableID;

paddingID = "tableToolsPadding" + tableID;
paddingDiff = parseInt(document.getElementById(paddingID).style.width) - 7;

leftPos = (curleft + tableWidth) - paddingDiff - parseInt(document.getElementById(holdingField).style.width) - 2;
topPos = curtop;

document.getElementById(holdingField).style.zIndex = "99";
document.getElementById(holdingField).style.left = leftPos + "px";
document.getElementById(holdingField).style.top = topPos + "px";
document.getElementById(holdingField).style.visibility = "visible";

setTimeout("menuOff('"+callingFieldName+"', '" + holdingField +"', ShadowOff);",1000);

}

function ShadowOff() {

if (document.getElementById('tableShadow')){
document.getElementById('tableShadow').style.width = "1px";
document.getElementById('tableShadow').style.height = "1px";
document.getElementById('tableShadow').style.left = "1px";
document.getElementById('tableShadow').style.top = "1px";
document.getElementById('tableShadow').style.visibility = "hidden";
}

}

function SelectTableSort(tableID, sortID) {

eval("scriptURL = document.tableForm"+tableID+".scriptURL.value;");

window.location = scriptURL + '&sortField=' + sortID;

}

function CustomiseTable(tableID) {

CreateTableShadow(tableID);

callingFieldName = "customisePrompt" + tableID;

tableDivID = "tableID" + tableID;
tableWidth = parseInt(document.getElementById(tableDivID).clientWidth);

findObjectPos_POR(document.getElementById(tableDivID));

curtop = curtop + 25;

holdingField = "customiseTableHolder" + tableID;

tableField = "customiseTable" + tableID;
customiseHeight = parseInt(document.getElementById(tableField).clientHeight);
document.getElementById(holdingField).style.height = customiseHeight + "px";

paddingID = "tableToolsPadding" + tableID;
paddingDiff = parseInt(document.getElementById(paddingID).style.width) - 7;

leftPos = (curleft + tableWidth) - paddingDiff - parseInt(document.getElementById(holdingField).style.width) - 2;
topPos = curtop;

document.getElementById(holdingField).style.left = leftPos + "px";
document.getElementById(holdingField).style.top = topPos + "px";
document.getElementById(holdingField).style.visibility = "visible";
document.getElementById(holdingField).style.zIndex = "99";

setTimeout("menuOff('"+callingFieldName+"', '" + holdingField +"', ShadowOff);",1000);

}

function SelectSavedTableLayout(tableID, layoutID, boxWidth, boxHeight) {

eval("scriptURL = document.tableForm"+tableID+".scriptURL.value;");

if (layoutID == 'new'){
eval("session = document.tableForm"+tableID+".session.value;");
eval("tableName = document.tableForm"+tableID+".table_name.value;");
eval("tableProfileID = document.tableForm"+tableID+".table_profile_id.value;");
var url = "/cgi-bin/customise-table.pl?session=" + session + "&table_name=" + tableName + "&table_profile_id=" + tableProfileID + "&scriptURL=" + scriptURL;
popwin(url,"", boxWidth, boxHeight, 'scroll');
return;
}


window.location = scriptURL + '&table_layout=' + layoutID;

}

function DoSimpleTableLayout(tableID) {

eval("tableColumns = parseInt(document.tableForm"+tableID+".tableColumns.value);");

tableFields = "";

for (var x= 1; x <= tableColumns; x++) {

fieldName = "c" + x;

eval("if (document.tableForm"+tableID+"."+fieldName+"){ if (document.tableForm"+tableID+"."+fieldName+".checked){if (tableFields != ''){tableFields += ',';}tableFields += "+x+";}}");

}

if (tableFields == ''){
alert('Please select at least one field to display.');
} else {

eval("scriptURL = document.tableForm"+tableID+".scriptURL.value;");

window.location = scriptURL + '&table_layout_simple=' + tableFields;

}

}


function ChangeSortField(sortField, scriptURL) {

window.location = scriptURL + '&sortField=' + sortField;

}

function MerchantSearch(searchValue, session){

if (typeof searchValue == ''){
CreateBrowseCreativeMenu('start', session);
} else {

if (searchValue != ''){
eval("rExp = /^" + searchValue + "/gi;");
}

var html = '<table border="0" cellpadding="5" cellspacing="0" width="100%">';

for (siteID in Merchants){

if (Merchants[siteID].search(rExp) < 0){
continue;
}

html += '<tr><Td align="left"><a href="/cgi-bin/pickup-links.pl?session=' + session +'&site_id=' + siteID + '" style="text-decoration:underline;">' + Merchants[siteID] + '</td></tr>';

}

html += '</table>';

document.getElementById('merchantList').innerHTML = html; 

}

}

function CreateBrowseCreativeMenu(movePage, session) {

if (movePage == 'next'){
currentPage = currentPage + 1;
} else if (movePage == 'back'){
currentPage = currentPage - 1;
} else if (movePage == 'start'){
currentPage = 1;
}

if (currentPage > no_pages){
currentPage = 1;
} else if (currentPage < 1){
currentPage = no_pages;
}

searchValue = document.browseMenu.keyword.value;

if (searchValue != ''){
eval("rExp = /^" + searchValue + "/gi;");
}

var html = '<table border="0" cellpadding="0" cellspacing="0" width="100%">';

var pos = 0;
var got_merchant = 0;

var show_from = ((currentPage * 14) - 14) + 1;
var show_to = (show_from + 14) - 1;

counter = 0;

if (document.browseMenu.sortMethod.value == 'name'){

for (siteID in Merchants){

got_merchant = 1;

if (searchValue != ''){
if (Merchants[siteID].search(rExp) < 0){
continue;
}
}

pos = pos + 1;
if (pos >= show_from && pos <= show_to){
html += '<div style="width:230px;border:1px solid #ffffff;color:#2F4598;text-decoration:none;padding:3px;height:14px;cursor:pointer;" name="bMenu'+counter+'" id="bMenu'+counter+'" onmouseover="javascript:HightLightBox('+counter+', 1, \'bMenu\');" onmouseout="javascript:HightLightBox('+counter+', 0, \'bMenu\');" onclick="javascript:GetMerchantCreative(\''+session+'\', \''+siteID+'\');">'+Merchants[siteID]+'</div>';
counter = counter + 1;
}
}

} else if (document.browseMenu.sortMethod.value == 'joined'){

for (var x= 0; x < dateJoined.length; x++) {

if (typeof Merchants[dateJoined[x]] == 'undefined'){
continue;
}

if (searchValue != ''){
if (Merchants[dateJoined[x]].search(rExp) < 0){
continue;
}
}

pos = pos + 1;
if (pos >= show_from && pos <= show_to){
html += '<div style="width:230px;border:1px solid #ffffff;color:#2F4598;text-decoration:none;padding:3px;height:14px;cursor:pointer;" name="bMenu'+counter+'" id="bMenu'+counter+'" onmouseover="javascript:HightLightBox('+counter+', 1, \'bMenu\');" onmouseout="javascript:HightLightBox('+counter+', 0, \'bMenu\');" onclick="javascript:GetMerchantCreative(\''+session+'\', \''+dateJoined[x]+'\');">'+Merchants[dateJoined[x]]+'</div>';
counter = counter + 1;
}
}

}

if (pos == 0){ 
if (got_merchant == 0){
html += '<tr><td  class="normlink" style="padding:5px;">You have yet to join any Merchant, please click Browse Merchant on the menu to visit our Merchant Directory</td></tr>';
} else {
html += '<tr><td  class="normlink" style="padding:5px;">Sorry no Merchants can be found, please refine your search.</td></tr>';
}
}

html += '</table>';

no_pages = Math.round(pos / 13);

if ((pos - (no_pages * 13)) > 0){
no_pages = no_pages + 1;
}

document.getElementById('merchantList').innerHTML = html; 

}



function startExport() {

findObjectPos_POR(document.getElementById('tableID1'));

leftPos = curleft - (parseInt(document.getElementById('exportDataLayer').style.width) - parseInt(document.getElementById('tableID1').clientWidth)) - 2;
topPos = curtop + parseInt(document.getElementById('exportTable').style.height);

document.getElementById('exportDataLayer').style.left = leftPos + "px";
document.getElementById('exportDataLayer').style.top = topPos + "px";
document.getElementById('exportDataLayer').style.visibility = "visible";

setTimeout("menuOff('"+'exportTable'+"', '" + 'exportDataLayer' +"');",1000);

try
{
CustomExportOn()
}
catch(err)
{

}

}


function ShowMenu(menuName, menuHTML, offsetLeft) {

if (offsetLeft == ''){
offsetLeft = 55;
}

//if (offsetRight == '' or typeof offsetRight == 'undefined'){
offsetRight = 0;
//}

findObjectPos_POR(document.getElementById(menuName));

leftPos = curleft + offsetLeft;
topPos = curtop - offsetRight;

getPageHeight_POR();

scrollHeight = getScrollHeight_POR();

myHeight = myHeight + scrollHeight;

if ((topPos + parseInt(document.getElementById(menuHTML).style.height)) > myHeight){
topPos = myHeight - 5 - parseInt(document.getElementById(menuHTML).style.height);
}

document.getElementById(menuHTML).style.left = leftPos + "px";
document.getElementById(menuHTML).style.top = topPos + "px";
document.getElementById(menuHTML).style.visibility = "visible";

setTimeout("menuOff('"+menuName+"', '" + menuHTML +"');",2000);

}

var mouseCursorInMenu = 0;

var timeOutRecord = new Array;

function menuOff(menuName, menuHTML, callback) {

key = menuName + menuHTML;

scrollHeight = getScrollHeight_POR();
scrollWidth = getScrollWidth_POR();

truePORMouseY = porMouseY;
truePORMouseX = porMouseX;

if (PORisIE){
truePORMouseY += scrollHeight;
truePORMouseX += scrollWidth;
}

findObjectPos_POR(document.getElementById(menuName));

curtopParent = curtop;
curleftParent = curleft;

findObjectPos_POR(document.getElementById(menuHTML));

boxTop = curtopParent;
boxRight = parseInt(document.getElementById(menuName).style.width) + curleftParent;
boxBottom = curtopParent + document.getElementById(menuName).clientHeight; 

if ((truePORMouseX >= curleftParent && truePORMouseX <= boxRight && truePORMouseY >= boxTop && truePORMouseY <= boxBottom) || mouseCursorInMenu == 1){
timeOutRecord[key] = setTimeout("menuOff('"+menuName+"', '" + menuHTML +"',"+ callback +");",1000); 
} else {

boxTop = curtop;
boxRight = parseInt(document.getElementById(menuHTML).style.width) + curleft;
boxBottom = curtop + document.getElementById(menuHTML).clientHeight;

if (truePORMouseX >= curleft && truePORMouseX <= boxRight && truePORMouseY >= boxTop && truePORMouseY <= boxBottom){
timeOutRecord[key] = setTimeout("menuOff('"+menuName+"', '" + menuHTML +"',"+ callback +");",1000);
} else {
document.getElementById(menuHTML).style.visibility = "hidden"; 
document.getElementById(menuHTML).style.top = "0px";
document.getElementById(menuHTML).style.left = "0px";

if (callback != '' && typeof callback != 'undefined'){
callback();
}

mouseCursorInMenu = 0;
}

}

if (document.getElementById(menuHTML).style.visibility == 'hidden'){

if (menuHTML == 'exportDataLayer'){
try
{
CustomExportOff()
}
catch(err)
{

}
}

}

}

function LogActiveMenu(mouseStatus) {
mouseCursorInMenu = mouseStatus;
}

function popwin(aPage, aTarget, w, h, var1, var2){
popup=window.open(aPage,aTarget,'status=yes,scrollbars=' +((var1=='scroll' || var2=='scroll')? 'yes' : 'no')+ ',resizable=' +((var1=='resize' || var2=='resize')? 'yes' : 'no')+ ',width='+w+',height='+h);
x = parseInt(window.screen.width) / 2 - (w/2);
y = parseInt(window.screen.height) / 2 - (h/2);
popup.moveTo(x,y);
if (popup.opener == null) popup.opener = self;
}

function addMouseReleaseEvent(fnc){

  if ( typeof document.addEventListener != "undefined" )
    document.addEventListener( "mouseup", fnc, false );
  else if ( typeof document.attachEvent != "undefined" ) {
    document.attachEvent( "onmouseup", fnc );
  }
  else {
    if ( window.onmouseup != null ) {
      var oldOnmouseup = window.onmouseup;
      window.onmouseup = function ( e ) {
        oldOnmouseup( e );
        window[fnc]();
      };
    }
    else 
      window.onmouseup = fnc;
  }

}

function addMouseDownEvent(fnc){

  if ( typeof document.addEventListener != "undefined" )
    document.addEventListener( "mousedown", fnc, false );
  else if ( typeof document.attachEvent != "undefined" ) {
    document.attachEvent( "onmousedown", fnc );
  }
  else {
    if ( window.onmousedown != null ) {
      var oldOnmousedown = window.onmousedown;
      window.onmousedown = function ( e ) {
        oldOnmousedown( e );
        window[fnc]();
      };
    }
    else 
      window.onmousedown = fnc;
  }

}

function addMouseMoveUpEvent(fnc){

  if ( typeof document.addEventListener != "undefined" )
    document.addEventListener( "mouseup", fnc, false );
  else if ( typeof document.attachEvent != "undefined" ) {
    document.attachEvent( "onmouseup", fnc );
  }
  else {
    if ( window.onmouseup != null ) {
      var oldOnmouseup = window.onmouseup;
      window.onmouseup = function ( e ) {
        oldOnmouseup( e );
        window[fnc]();
      };
    }
    else 
      window.onmouseup = fnc;
  }

}

function addMouseMoveEvent(fnc){

  if ( typeof document.addEventListener != "undefined" )
    document.addEventListener( "mousemove", fnc, false );
  else if ( typeof document.attachEvent != "undefined" ) {
    document.attachEvent( "onmousemove", fnc );
  }
  else {
    if ( window.onmousemove != null ) {
      var oldOnmousemove = window.onmousemove;
      window.onmousemove = function ( e ) {
        oldOnmousemove( e );
        window[fnc]();
      };
    }
    else 
      window.onmousemove = fnc;
  }

}

function porTrackMouse(e) {

if (!e) var e = window.event;

if (typeof e.pageY == 'number'){
porMouseY = e.pageY;
porMouseX = e.pageX;
} else{
porMouseY = e.clientY;
porMouseX = e.clientX;
}

}

function ResetTable(scriptURL, type, form){

var sort_field2 = "";
var table_layout = "";

if (type == 'layout'){
if (form.table_layout2){
var table_layout = form.table_layout2.value;
}
}

if (type == 'sort'){
if (form.sort_field2){
var sort_field2 = form.sort_field2.value;
}
}

if (table_layout == 'new'){
var url = document.optionform.custom_url.value + "&url=" + scriptURL;
popwin(url,"", 735, 440, 'scroll');
return;
}

window.location = scriptURL + '&table_layout=' + table_layout + '&sort_field=' + sort_field2;

}

var bottomReached  = 0;
var headerCount = 2;

function getPageHeight_POR() {

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

}

function getScrollWidth_POR()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 

function getScrollHeight_POR()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

var removeRow = new Array;

for (var tableID = 0; tableID < 5; tableID++) {
removeRow[tableID] = 0;
}

function porFloatHeader(){

getPageHeight_POR();
scrollHeight = getScrollHeight_POR();

for (var tableID = 1; tableID < 5; tableID++) {

tableName = "floatTable" + tableID;

if (! document.getElementById(tableName)){
continue;
}

findObjectPos_POR(document.getElementById(tableName));

if (((curtop+52) - scrollHeight) >= 0){

if (removeRow[tableID] > 0){

for (deleteRow=1; deleteRow<=headerCount; deleteRow++){
document.getElementById(tableName).deleteRow(removeRow[tableID]);
}

removeRow[tableID] = 0;

}

continue;
}

if (document.getElementById(tableName).clientHeight < (myHeight+50)){
continue;
}

tableTop = (scrollHeight - curtop);

rowCount = 2;
for (Pos=0; Pos<=tableTop; (Pos=Pos+22)){
if (Pos >= 22){
rowCount ++;
}
}

if (removeRow[tableID] > 0){

for (deleteRow=1; deleteRow<=headerCount; deleteRow++){
document.getElementById(tableName).deleteRow(removeRow[tableID]);
}

removeRow[tableID] = 0;

}

removeRow[tableID] = rowCount;

mytable = document.getElementById(tableName);

mytablebody = mytable.getElementsByTagName("tbody")[0];

if (mytablebody.getElementsByTagName("tr").length <= rowCount){
removeRow[tableID] = 0;
continue;
}

for (trCount=0; trCount<=(headerCount-1); trCount++){

myrow = mytablebody.getElementsByTagName("tr")[trCount];

if (myrow){

var x=document.getElementById(tableName).insertRow(rowCount);
rowCount ++;

for (tdPos=0; tdPos<=myrow.getElementsByTagName("td").length; tdPos++){
if (myrow.getElementsByTagName("td")[tdPos]){

mycel       = myrow.getElementsByTagName("td")[tdPos];

var rowtmp = x.insertCell(tdPos); 
rowtmp.colSpan= mycel.colSpan;
rowtmp.rowSpan= mycel.rowSpan;
rowtmp.width= mycel.width;

rowtmp.style.padding= mycel.style.padding;
rowtmp.bgColor= mycel.bgColor;

//if (headerCount == 3){

rowtmp.style.border= mycel.style.border;
rowtmp.style.borderBottom= mycel.style.borderBottom;
rowtmp.style.borderRight= mycel.style.borderRight;
rowtmp.style.borderLeft= mycel.style.borderLeft;
rowtmp.style.borderTop= mycel.style.borderTop;
rowtmp.style.backgroundColor= mycel.style.backgroundColor;

//}

if (mycel.innerHTML != ''){
//rowtmp.className= "test";
rowtmp.align = mycel.align;
rowtmp.vAlign = mycel.vAlign; 
rowtmp.innerHTML= mycel.innerHTML;
}

}
}

}

}



}

}

window.onscroll = porFloatHeader;

function GetRemoteData(Session, scriptURL, fieldName, fieldValue, updateField) {

if (fieldValue == ''){
return;
}

eval("formField = document.forms[0]."+updateField+";");

  var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

var url=scriptURL + "?session=" + Session + "&" + fieldName + "=" + fieldValue;

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            

var temp = new Array();
temp = self.xmlHttpReq.responseText.split('\n');

var count = 0;

for (var j = 0; j < temp.length; j++) {

if (! temp[j] == ""){

returnData = temp[j].split('|');

returnValue = returnData[0];
returnDisplay = returnData[1];



if (! doneAffiliates[returnValue]){
doneAffiliates[returnValue] = 1;
formField.options[formField.options.length] = new Option(returnDisplay, returnValue);
}

count = count + 1;

}

}

if (count == "0"){
alert('Sorry no data found.');
}

        }
    }

self.xmlHttpReq.open("GET", url , true) 
self.xmlHttpReq.send(null);

}

function ZoomLayer(fieldName) {

if (! ElementWidths[fieldName] || typeof ElementWidths[fieldName] == 'undefined'){
ElementHeights[fieldName] = document.getElementById(fieldName).clientHeight;
ElementWidths[fieldName] = document.getElementById(fieldName).clientWidth;
}

if (document.getElementById(fieldName).style.visibility == 'hidden'){
document.getElementById(fieldName).style.width = ElementWidths[fieldName] + "px";
document.getElementById(fieldName).style.height = 1 + "px";
LayerSwitch(fieldName, 'on');
setTimeout("expand('"+fieldName+"');",30);
} else {
setTimeout("unexpand('"+fieldName+"');",40);
}


}

function unexpand(fieldName) {

if (parseInt(document.getElementById(fieldName).style.height) > 0){

if ((parseInt(document.getElementById(fieldName).style.height)-30) > 0){
document.getElementById(fieldName).style.height = parseInt(document.getElementById(fieldName).style.height) - 30 + "px";
setTimeout("unexpand('"+fieldName+"');",40);
} else {
document.getElementById(fieldName).style.height = 0 + "px";
LayerSwitch(fieldName, 'off');
}

}

}

function expand(fieldName) {

if (parseInt(document.getElementById(fieldName).style.height) < ElementHeights[fieldName]){

if ((parseInt(document.getElementById(fieldName).style.height)+30) < ElementHeights[fieldName]){
document.getElementById(fieldName).style.height = parseInt(document.getElementById(fieldName).style.height) + 30 + "px";
setTimeout("expand('"+fieldName+"');",30);
} else {
document.getElementById(fieldName).style.height = parseInt(document.getElementById(fieldName).style.height) + (ElementHeights[fieldName] - parseInt(document.getElementById(fieldName).style.height)) + "px";
}

}

}

function findObjectPos_POR(obj) {
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
}

var selectedGraphID = 0;
var graphSelectedOptions = new Array;
var registerGraphCallBack = 0;

function CustomiseGraph(graphID, dynamicMenu) {

if (graphsEnabled[graphID] == '' || typeof graphsEnabled[graphID] == 'undefined'){
alert('Sorry this graph has not finished loading yet.');
return;
}

if (dynamicMenu == 1){
CreateDynamicMenu(graphID);
}

selectedGraphID = graphID;

linkKey = "linkOpt" + graphID;

findObjectPos_POR(document.getElementById(linkKey));

getPageHeight_POR();

scrollHeight = getScrollHeight_POR();

browserBottom = myHeight + scrollHeight;

testHeight = curtop + parseInt(document.getElementById('customiseGraphMenu').style.height);

if (testHeight > browserBottom){
topPos = curtop - (testHeight - browserBottom);
} else {
topPos = curtop;
}

testWidth = curleft + parseInt(document.getElementById(linkKey).style.width) + 5 + parseInt(document.getElementById('customiseGraphMenu').style.width);

if (testWidth > myWidth){
leftPos = curleft - (parseInt(document.getElementById('customiseGraphMenu').style.width) );
} else {
leftPos = curleft + parseInt(document.getElementById(linkKey).style.width) + 5;
}

for (i in graphSelectedOptions){
eval("if (document.opt"+i+"){document.opt"+i+".src = '/images/inv-5x5px.gif';}");
}

graphSelectedOptions = [];

dataURL = graphOptions[graphID].split('?');

queryString = dataURL[1].split('&');

for( var x = 0; x < queryString.length; x++ ){

queryPair = queryString[x].split('=');

if (queryPair[0] != 'session' && queryPair[0] != 'period' && queryPair[0] != 'graph_id'){

if (queryPair[0] == 'fields'){

fieldSelected = queryPair[1].split(',');

for( var f = 0; f < fieldSelected.length; f++ ){
eval("document.graphMenuForm.optGraphField"+fieldSelected[f]+".checked = true;");
}

} else {
eval("if (document.opt"+queryPair[1]+"){document.opt"+queryPair[1]+".src = '/images/12pt-tick.gif';graphSelectedOptions['"+queryPair[1]+"']=1;}");
}

}

}

document.getElementById('customiseGraphMenu').style.left = leftPos + "px";
document.getElementById('customiseGraphMenu').style.top = topPos + "px";
document.getElementById('customiseGraphMenu').style.visibility = "visible";

setTimeout("menuOff('"+linkKey+"', '" + 'customiseGraphMenu' +"');",1000);

}

function ChangeGraphFields() {

selectedFields = "";

for( var x = 0; x < document.graphMenuForm.elements.length; x++ ){

if (document.graphMenuForm.elements[x].attributes){

for( var y = 0; y < document.graphMenuForm.elements[x].attributes.length; y++ ){

if (document.graphMenuForm.elements[x].attributes[y].nodeName.toLowerCase() == 'name'){ 

if (document.graphMenuForm.elements[x].attributes[y].nodeValue.substring(0,13) == 'optGraphField'){

fieldName = document.graphMenuForm.elements[x].attributes[y].nodeValue;
fieldLength = document.graphMenuForm.elements[x].attributes[y].nodeValue.length;
fieldID = document.graphMenuForm.elements[x].attributes[y].nodeValue.substring(13,fieldLength);

eval("if (document.graphMenuForm."+fieldName+".checked){if (selectedFields != ''){selectedFields += ',';}selectedFields += "+fieldID+";}");

}

}

}

}

}

graphOptions[selectedGraphID] = ChangeGraphSetting(graphOptions[selectedGraphID], 'fields', selectedFields);

ReloadGraph(selectedGraphID);

}

function ChangeGraphOption(name, value, localGraphID) {

if (typeof localGraphID != 'undefined' && localGraphID != ''){
selectedGraphID = localGraphID;
}

graphOptions[selectedGraphID] = ChangeGraphSetting(graphOptions[selectedGraphID], name, value);

if (name == 'page'){
graphPageNumber[localGraphID] = value;
GraphNavOptions(localGraphID);
}

ReloadGraph(selectedGraphID);

}

var registerChangeGraphPlotValue = 0;
var registerChangeGraphType = 0;

function ChangeGraphPlotValue(plotName, plotCaption) {

document.getElementById('customiseGraphMenu').style.visibility = "hidden"; 
document.getElementById('customiseGraphMenu').style.top = "0px";
document.getElementById('customiseGraphMenu').style.left = "0px";

graphOptions[selectedGraphID] = ChangeGraphSetting(graphOptions[selectedGraphID], 'plot_value', plotName);
graphOptions[selectedGraphID] = ChangeGraphSetting(graphOptions[selectedGraphID], 'page', 1);

graphPageNumber[selectedGraphID] = 1;

GraphNavOptions(selectedGraphID);

graphDIV = "graphDiv" + selectedGraphID;

if (newGraphID[graphDIV] == "" || typeof newGraphID[graphDIV] == 'undefined'){
chartID = "chart" + selectedGraphID + "Id";
} else {
chartID = "chart" + newGraphID[graphDIV] + "Id";
}

var chartObj = getChartFromId(chartID);

chartObj.setDataURL(graphOptions[selectedGraphID]); 

captionID = "caption" + selectedGraphID;

if (document.getElementById(captionID)){
document.getElementById(captionID).innerHTML = plotCaption;
}

if (registerGraphCallBack){
graphChangeCallBack(selectedGraphID);
}

if (registerChangeGraphPlotValue){
onChangeGraphPlotValue(selectedGraphID);
}

}

function ReloadGraph(graphID) {

graphDIV = "graphDiv" + graphID;

if (newGraphID[graphDIV] == "" || typeof newGraphID[graphDIV] == 'undefined'){
chartID = "chart" + graphID + "Id";
} else {
chartID = "chart" + newGraphID[graphDIV] + "Id";
}

var chartObj = getChartFromId(chartID);

chartObj.setDataURL(graphOptions[graphID]); 

}

var newGraphID = new Array;
var newGraphsCreated = 5;

function ChangeGraphType(swfFile, optionID) {

graphFilename = "/graphs/" + swfFile + ".swf";

graphDIV = "graphDiv" + selectedGraphID;

if (newGraphID[graphDIV] == "" || typeof newGraphID[graphDIV] == 'undefined'){
newGraphID[graphDIV] = newGraphsCreated;
newGraphsCreated = newGraphsCreated + 1;
} else {
newGraphID[graphDIV] = newGraphID[graphDIV] + 1;
}

chartID = "chart" + newGraphID[graphDIV] + "Id";

document.getElementById('customiseGraphMenu').style.visibility = "hidden"; 
document.getElementById('customiseGraphMenu').style.top = "0px";
document.getElementById('customiseGraphMenu').style.left = "0px";

graphOptions[selectedGraphID] = ChangeGraphSetting(graphOptions[selectedGraphID], 'graph', swfFile);
graphOptions[selectedGraphID] = ChangeGraphSetting(graphOptions[selectedGraphID], 'page', 1);

graphPageNumber[selectedGraphID] = 1;

GraphNavOptions(selectedGraphID);

if (registerChangeGraphType){
onChangeGraphType(selectedGraphID);
}

graphWidth = parseInt(document.getElementById(graphDIV).style.width);
graphHeight = parseInt(document.getElementById(graphDIV).style.height);

var myChart = new FusionCharts(graphFilename, chartID, graphWidth, graphHeight, "0", "1"); 
myChart.setDataURL(graphOptions[selectedGraphID]);
myChart.setTransparent(true);
myChart.render(graphDIV);

}


function ChangeGraphSetting(currentURL, name, value) {

doneChange = 0;

url = currentURL.split('?');

queryString = url[1].split('&');

url[1] = "";

for (var i=0; i<queryString.length; i++) {

pair = queryString[i].split('=');

if (pair[0] == name){
pair[1] = value;
doneChange = 1;
}

if (url[1] == ""){
url[1] = pair[0] + "=" + pair[1];
} else {
url[1] += "&" + pair[0] + "=" + pair[1];
}

}

if (doneChange == 0){
if (url[1] == ""){
url[1] = name + "=" + value;
} else {
url[1] += "&" + name + "=" + value;
}
}

currentURL = url[0] + "?" + url[1];

return currentURL;

}

function PrintGraph() {

document.getElementById('customiseGraphMenu').style.visibility = "hidden"; 
document.getElementById('customiseGraphMenu').style.top = "0px";
document.getElementById('customiseGraphMenu').style.left = "0px";

graphDIV = "graphDiv" + selectedGraphID;

if (newGraphID[graphDIV] == "" || typeof newGraphID[graphDIV] == 'undefined'){
chartID = "chart" + selectedGraphID + "Id";
} else {
chartID = "chart" + newGraphID[graphDIV] + "Id";
}

var chartToPrint = getChartFromId(chartID);
chartToPrint.print();

}

function GetGraphSetting(graphID, findName) {

url = graphOptions[graphID].split('?');

queryString = url[1].split('&');

for (var i=0; i<queryString.length; i++) {

queryPair = queryString[i].split('=');

if (queryPair[0] == findName){
return queryPair[1];
}

}

}

function SaveGraphSettings(sessionID) {

document.getElementById('customiseGraphMenu').style.visibility = "hidden"; 
document.getElementById('customiseGraphMenu').style.top = "0px";
document.getElementById('customiseGraphMenu').style.left = "0px";

graphDiv = "graphDiv" + selectedGraphID;

graphMessage(graphDiv, "Saving your Settings", "60px-loading-ffffff.gif", 64, 60);

url = graphOptions[selectedGraphID].split('?');

queryString = url[1].split('&');

url = "/cgi-bin/graph-data/store-settings.pl?session=" + sessionID + "&graph_id=" + selectedGraphID + "&script_key=" + graphScriptKey;

for (var i=0; i<queryString.length; i++) {

queryPair = queryString[i].split('=');

if (queryPair[0] != 'session' && queryPair[0] != 'period' && queryPair[0] != 'graph_id'){
url += "&" + queryPair[0] + "=" + queryPair[1];
}

}

  var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {

if (self.xmlHttpReq.responseText == 'OK'){
graphMessage(graphDiv, "Your Settings have been Saved", "tick_25x25.jpg", 25, 25);
} else {
graphMessage(graphDiv, "Unable to save your settings", "cross_25x25.jpg", 25, 25);
}

setTimeout("hideGraphMessage();",2000);

        }
    }

self.xmlHttpReq.open("GET", url, true) 
self.xmlHttpReq.send(null);

}

function GetGraphType(graphID) {

url = graphOptions[graphID].split('?');

graphType = "";

queryString = url[1].split('&');

for (var i=0; i<queryString.length; i++) {

pair = queryString[i].split('=');

if (pair[0] == 'graph'){
graphType = pair[1];
break;
}

}

return graphType;

}

function hideGraphMessage() {
document.getElementById('saveSettingsBackground').style.left = 0 + "px";
document.getElementById('saveSettingsBackground').style.top = 0 + "px";
document.getElementById('saveSettingsBackground').style.visibility = "hidden";
document.getElementById('saveSettingsMessage').style.left = 0 + "px";
document.getElementById('saveSettingsMessage').style.top = 0 + "px";
document.getElementById('saveSettingsMessage').style.visibility = "hidden";
}

function graphMessage(graphDiv, msgText, imageFilename, imageWidth, imageHeight) {

if (! document.getElementById('saveSettingsMessage')){

var head = document.getElementsByTagName('body')[0];

if (navigator.appName == "Microsoft Internet Explorer"){
var imageOver = document.createElement('<div id="saveSettingsMessage" name="saveSettingsMessage" style="position:absolute;visibility:hidden;left:0px;top:0px;z-index:110;"></div>');
head.appendChild(imageOver);
} else {
var imageOver2 = document.createElement('div');
imageOver2.setAttribute('name', 'saveSettingsMessage');
imageOver2.setAttribute('id', 'saveSettingsMessage');
imageOver2.setAttribute('style', 'position:absolute;visibility:hidden;left:0px;top:0px;z-index:110;');
head.appendChild(imageOver2);
}

if (navigator.appName == "Microsoft Internet Explorer"){
var imageOver = document.createElement('<div id="saveSettingsBackground" name="saveSettingsBackground" style="position:absolute;visibility:hidden;left:0px;top:0px;z-index:109;background-color:#ffffff;border:1px solid #000000;"></div>');
head.appendChild(imageOver);
} else {
var imageOver2 = document.createElement('div');
imageOver2.setAttribute('name', 'saveSettingsBackground');
imageOver2.setAttribute('id', 'saveSettingsBackground');
imageOver2.setAttribute('style', 'position:absolute;visibility:hidden;left:0px;top:0px;z-index:109;background-color:#ffffff;border:1px solid #000000;');
head.appendChild(imageOver2);
}

if (! document.getElementById('saveSettingsMessage')){
return;
}

}

document.getElementById('saveSettingsMessage').innerHTML = '<Table border="0" cellpadding="0" cellspacing="0"><Tr><td align="center"><img src="/images/' + imageFilename +'" width="'+imageWidth+'" height="'+imageHeight+'"></td></tr><Tr><td><img src="/images/inv-5x5px.gif" width="4" height="5"></td></tr><tr><td class="blue_16" align="center"><strong>'+msgText+'</td></tr></table>';

findObjectPos_POR(document.getElementById(graphDiv));

document.getElementById('saveSettingsBackground').style.width = document.getElementById(graphDiv).style.width;
document.getElementById('saveSettingsBackground').style.height = (parseInt(document.getElementById(graphDiv).style.height) - 10) + "px";

document.getElementById('saveSettingsBackground').style.left = curleft + "px";
document.getElementById('saveSettingsBackground').style.top = curtop + "px";
document.getElementById('saveSettingsBackground').style.visibility = "visible";

leftPos = Math.round(curleft + ((document.getElementById(graphDiv).clientWidth - document.getElementById('saveSettingsMessage').clientWidth) / 2));
topPos = Math.round(curtop + (((document.getElementById(graphDiv).clientHeight - 10) - document.getElementById('saveSettingsMessage').clientHeight) / 2));

document.getElementById('saveSettingsMessage').style.left = leftPos + "px";
document.getElementById('saveSettingsMessage').style.top = topPos + "px";
document.getElementById('saveSettingsMessage').style.visibility = "visible";

}

function hideGraphMessage() {

document.getElementById('saveSettingsBackground').style.left = 0 + "px";
document.getElementById('saveSettingsBackground').style.top = 0 + "px";
document.getElementById('saveSettingsBackground').style.visibility = "hidden";

document.getElementById('saveSettingsMessage').style.left = 0 + "px";
document.getElementById('saveSettingsMessage').style.top = 0 + "px";
document.getElementById('saveSettingsMessage').style.visibility = "hidden";

}

function ExportGraphAsImage() {

document.getElementById('customiseGraphMenu').style.visibility = "hidden"; 
document.getElementById('customiseGraphMenu').style.top = "0px";
document.getElementById('customiseGraphMenu').style.left = "0px";

graphDIV = "graphDiv" + selectedGraphID;

if (newGraphID[graphDIV] == "" || typeof newGraphID[graphDIV] == 'undefined'){
chartID = "chart" + selectedGraphID + "Id";
} else {
chartID = "chart" + newGraphID[graphDIV] + "Id";
}

var chartToSave = getChartFromId(chartID);
chartToSave.saveAsImage();

}

var disablePageNavOnPie = 0;

function GraphNavOptions(graphID) {

if (graphMultiplePage[graphID] == 0){
return;
}

graphType = GetGraphSetting(graphID, 'graph');

fieldName = "graph" + graphID + "Nav";

htmlCode = "";

if (disablePageNavOnPie == 1 && (graphType == 'Pie3D' || graphType == 'Pie2D')){ 
htmlCode += 'Previous Graph';
htmlCode += '&nbsp;|&nbsp;';
htmlCode += 'Next Graph';
document.getElementById(fieldName).innerHTML = htmlCode;
return;
}

if (graphPageNumber[graphID] > 1){
backPageID = parseInt(graphPageNumber[graphID]) - 1;
htmlCode += '<a href="javascript:ChangeGraphOption(\'page\',\'' + backPageID +'\', \''+graphID+'\');" style="text-decoration:underline;">Previous Graph</a>';
} else {
htmlCode += 'Previous Graph';
}

htmlCode += '&nbsp;|&nbsp;';

if (graphPageNumber[graphID] < graphMultiplePage[graphID]){
nextPageID = parseInt(graphPageNumber[graphID]) + 1;
htmlCode += '<a href="javascript:ChangeGraphOption(\'page\',\'' + nextPageID +'\', \''+graphID+'\');" style="text-decoration:underline;">Next Graph</a>';
} else {
htmlCode += 'Next Graph';
}

document.getElementById(fieldName).innerHTML = htmlCode;

}

var graphsEnabled = new Array;

function FC_Rendered(DOMId){
DOMId = DOMId.substring(5,DOMId.length-2);
graphsEnabled[DOMId] = 1;
GraphNavOptions(DOMId);
}

function ShowTabStatus(statusMessage) {
document.getElementById('tab_status').innerText = statusMessage;
}

function LayerSwitch(fieldName, PosSwitch) {

if (PosSwitch == 'on' || PosSwitch == 'onfree'){
if (PosSwitch == 'onfree'){
position = "absolute";
PosSwitch = "visible";
} else {
position = "static";
PosSwitch = "visible";
}
} else {
position = "absolute";
PosSwitch = "hidden";
}

if(document.layers){
document.layers[fieldName].style.visibility = PosSwitch;
document.layers[fieldName].style.position = position;

if (PosSwitch == 'hidden'){
document.layers[fieldName].style.left = "0px";
document.layers[fieldName].style.top = "0px";
}

}
else if(document.getElementById) {
document.getElementById(fieldName).style.visibility = PosSwitch;
document.getElementById(fieldName).style.position = position;

if (PosSwitch == 'hidden'){
document.getElementById(fieldName).style.left = "0px";
document.getElementById(fieldName).style.top = "0px";
}

}
else if(document.all) {
document.all[fieldName].style.visibility = PosSwitch;
document.all[fieldName].style.position = position;

if (PosSwitch == 'hidden'){
document.all[fieldName].style.left = "0px";
document.all[fieldName].style.top = "0px";
}

}

}

function correctSubmitHandler(e)
{
	if (e && e.preventDefault)
		e.preventDefault();
	return false;
}

function addEvent(obj, evType, fn)
{
	if (obj.addEventListener)
	{
   		obj.addEventListener(evType, fn, false);
   		return true;
	}
	else if (obj.attachEvent)
	{
   		var r = obj.attachEvent("on"+evType, fn);
   		return r;
 	}
 	else
 	{
   		return false;
 	}
}

function FindMerchant(fieldName, searchText) {

eval("rExp = /^" + searchText + "/gi;");

selectBox = eval("document.optionform." + fieldName);

if (searchText.length < 3){
for (var j = 0; j < selectBox.options.length; j++) {
selectBox.options[j].selected = false;
}
return;
}

for (var j = 0; j < selectBox.options.length; j++) {

merchantID2 = selectBox.options[j].value;
merchantName2 = selectBox.options[j].text;

if (merchantName2.search(rExp) >= 0){
selectBox.options[j].selected = true;
} else {
selectBox.options[j].selected = false;
}

}

}

function AddMerchant(fromField, toField) {

selectedList = eval("document.optionform." + fromField);
realList = eval("document.optionform." + toField);

for (var j = 0; j < selectedList.options.length; j++) {
if (selectedList.options[j].selected){

entryID = selectedList.options[j].value;
entryName = selectedList.options[j].text;

addEntry = 1;

for (var x = 0; x < realList.options.length; x++) {
if (realList.options[x].value == entryID){
addEntry = 0;
}
}

if (addEntry){
realList.options[realList.options.length] = new Option(entryName, entryID);
selectedList.options[j].selected = false;
}

}
}

}

function RemoveSelection(fieldName, formName) {

if (! formName){
listName = eval("document.optionform." + fieldName);
} else {
listName = eval("document."+formName+"." + fieldName);
}

listedItems = new Array;

for (var j = 0; j < listName.length; j++) {
if (! listName.options[j].selected){
listedItems[listName.options[j].value] = listName.options[j].text;
}
}

listName.length = 0;

for (x in listedItems){
listName.options[listName.length] = new Option(listedItems[x], x);
}

}

function ReverseSelection(fieldName) {

listBox = eval("document.optionform." + fieldName + ".options");

for (var j = 0; j < listBox.length; j++) {

if (listBox[j].selected){
listBox[j].selected = false;
} else {
listBox[j].selected = true;
}

}

}

function getAbsX(elt) { return parseInt(elt.x) ? elt.x :
getAbsPos(elt,"Left"); };
function getAbsY(elt) { return parseInt(elt.y) ? elt.y :
getAbsPos(elt,"Top"); };
function getAbsPos(elt,which) {
iPos = 0;
while (elt != null) {
iPos += elt["offset" + which];
elt = elt.offsetParent;
}
return iPos;
}

function HightLightBox(itemID, status, divName, styleProp) {

if (divName == '' || typeof divName == 'undefined'){
fieldName = "item" + itemID;
} else {
fieldName = divName + itemID;
}

if (styleProp == 0){

if (status == 1){
document.getElementById(fieldName).style.borderTop = "1px solid #0872b9";
document.getElementById(fieldName).style.borderBottom = "1px solid #0872b9";
document.getElementById(fieldName).style.backgroundColor = "#f4f4f4";
} else {
document.getElementById(fieldName).style.borderTop = "1px solid #ffffff";
document.getElementById(fieldName).style.borderBottom = "1px solid #ffffff";
document.getElementById(fieldName).style.border = "1px solid #ffffff";
document.getElementById(fieldName).style.backgroundColor = "#ffffff";
}

} else {

if (status == 1){
document.getElementById(fieldName).style.border = "1px solid #0872b9";
document.getElementById(fieldName).style.backgroundColor = "#f4f4f4";
} else {
document.getElementById(fieldName).style.border = "1px solid #ffffff";
document.getElementById(fieldName).style.backgroundColor = "#ffffff";
}

}

}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

function doAJAX (url,method,contents,callback) {

var http = createXMLHTTPObject();

http.onreadystatechange = function() { if (http.readyState == 4) {callback(http);}}

http.open(method, url, true);

if (method == 'POST'){
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", contents.length);
http.setRequestHeader("Connection", "close");
}

if (contents == ''){
http.send(null);
} else {
http.send(contents);
}

}

function GetAffiliateGroup(Session, formName, groupID, uploadList) {

if (groupID == ''){
return;
}

listBox = eval("document." + formName + "."+uploadList+";");

  var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

var url="/cgi-bin/js-groups.pl?session=" + Session + "&group_id=" + groupID;

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            
var temp = new Array();
temp = self.xmlHttpReq.responseText.split('\n'); 

listedItems = new Array;

for (var j = 0; j < listBox.length; j++) {
listedItems[listBox.options[j].value] = 1;
}

var count = 0;

for (var j = 0; j < temp.length; j++) {

if (! temp[j] == ""){

returnData = temp[j].split('|');

affiliateID = returnData[0];
affiliateName = returnData[1];

displayName = affiliateID + " - " + affiliateName;

if (! listedItems[affiliateID]){
doneAffiliates[affiliateID] = 1;
listBox.options[listBox.options.length] = new Option(displayName, affiliateID);
}

count = count + 1;

}

}

if (count == "0"){
alert('Sorry there are no Affiliates in this group');
}

        }
    }

self.xmlHttpReq.open("GET", url , true) 
self.xmlHttpReq.send(null);

}

var doneAffiliates = new Array;

function SearchAffiliate(formName, Session) {

excludeClicks = 0;
excludeSales = 0;

if (! formName){
findValue = document.forms[0].find_aff.value;
listBox = document.forms[0].affiliates;
} else {
findValue = eval("document." + formName + ".find_aff.value;");
listBox = eval("document." + formName + ".affiliates;");
eval("if (document."+formName+".exclude_no_clicks){if (document."+formName+".exclude_no_clicks.checked){excludeClicks = 1;}}");
eval("if (document."+formName+".exclude_no_sales){if (document."+formName+".exclude_no_sales.checked){excludeSales = 1;}}");
eval("if (document."+formName+".search_active_only){excludeClicks = 1;excludeSales = 1;}");
}

  var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

var url="/cgi-bin/js-search.pl?session=" + Session + "&search=" + findValue + "&exclude_no_sales=" + excludeSales + "&exclude_no_clicks=" + excludeClicks;

findValue = "";

if (! formName){
document.forms[0].find_aff.value = "";
} else {
eval("document." + formName + ".find_aff.value = \"\";");
}

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            
var temp = new Array();
temp = self.xmlHttpReq.responseText.split('\n');

listedItems = new Array;

for (var j = 0; j < listBox.length; j++) {
listedItems[listBox.options[j].value] = 1;
}

var count = 0;

for (var j = 0; j < temp.length; j++) {

if (! temp[j] == ""){

returnData = temp[j].split('|');

affiliateID = returnData[0];
affiliateName = returnData[1];

displayName = affiliateID + " - " + affiliateName;

if (! listedItems[affiliateID]){
doneAffiliates[affiliateID] = 1;
listBox.options[listBox.options.length] = new Option(displayName, affiliateID);
}

count = count + 1;

}

}

if (count == "0"){
alert('Sorry No Matches');
}

        }
    }

self.xmlHttpReq.open("GET", url , true) 
self.xmlHttpReq.send(null);

}

function RegisterPositionPOR(obj, fieldName){

objHeight = obj.clientHeight;

if (PORisIE){

scrollHeight = getScrollHeight_POR();

objLeft = (porMouseX - window.event.offsetX);
objTop = (porMouseY - window.event.offsetY + scrollHeight);

//objTop += objHeight;

} else {

findObjectPos_POR(document.getElementById(fieldName));

objTop = curtop;
objLeft = curleft;

objTop += objHeight;

}

porLeftPosition[fieldName] = objLeft; 
porTopPosition[fieldName] = objTop; 

}

function showtip(current,e,text){

if (document.all||document.getElementById){
thetitle=text.split('<br>')
if (thetitle.length>1){
thetitles=''
for (i=0;i<thetitle.length;i++)
thetitles+=thetitle[i]
current.title=thetitles
}
else
current.title=text
}

else if (document.layers){
document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
document.tooltip.document.close()
document.tooltip.left=e.pageX+5
document.tooltip.top=e.pageY+5
document.tooltip.visibility="show"
}
}

function hidetip(){
if (document.layers)
document.tooltip.visibility="hidden"
}

function isblank(s)
{
  for(var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\\n') && (c != '\\t')) return false;
  }
  return true;
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

addMouseMoveEvent(porTrackMouse);

