﻿//General Javascript Functions

//var bChange = false;

//function CheckSaveA(s)
//{
// if (bChange)
// {
//  if Confirm('Changes have been made to this page. Do you want to save them?')
//  {
//   Save();
//   window.location = s;
//  }
// } else
// {
//  window.location = s;
// }
//}
//function CheckSaveE(s)
//{
// if (bChange)
// {
//  if Confirm('Changes have been made to this page. Do you want to save them?')
//  {
//   Save();
//   eval(s);
//  }
// } else
// {
//  eval(s);
// }
//}


function Hide(c)
{
 var e = document.getElementById(c);
 if (e!=null)
 {
  e.style.display = 'none';
 }
}

function Show(c)
{
 document.getElementById(c).style.display = '';
}

function Logout()
{
  VAService.Logout(LoggedOut,OnErrorLO,OnErrorLO);
}

function LoggedOut(s)
{
 window.location = 'Default.aspx';
}

function getTop (inputObj)
{		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML'){
  		returnValue += inputObj.offsetTop;
  		if(document.all)returnValue+=inputObj.clientTop;
  	}
  } 
  return returnValue;
}


function getLeft (inputObj)
{	  
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if ((inputObj.tagName!='HTML') && (inputObj.tagName!='BODY'))
  	{
  		returnValue += inputObj.offsetLeft;
  		if(document.all)returnValue+=inputObj.clientLeft;
  	}
  }
  return returnValue;
}

function urlParam(name)
{
  //Returns a parameter from the current URL
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]").toUpperCase();
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href.toUpperCase());
  if(results == null) return ""; else return results[1];
}

function isPage(s)
{
 return window.location.href.toUpperCase().indexOf(s)>=0;
}

function DDInx(c)
{
 //Returns selected index of a dropdown
 return document.getElementById(c).selectedIndex;
}

function DDVal(c)
{
 //Returns selected value for a dropdown
 return document.getElementById(c).options[DDInx(c)].value;
}

function DDTxt(c)
{
 //Returns selected text for a dropdown
 return document.getElementById(c).options[DDInx(c)].text;
}


function OnTimeOut(val) 
{
  OnError(val);
}

function OnError(val) 
{
  alert('Error: ' + val.get_message() + '\r\n'+
        'Code: ' + val.get_statusCode() + '\r\n'+
        'Exception Type: ' + val.get_exceptionType() + '\r\n'+
        'Timeout: ' + val.get_timedOut()+"\r\n\r\n"+
        'Please close your browser and retry the section of the website which caused the problem.\r\nIf you continue to have problems, contact CAP Support on 0113 2222007 with the exact message shown here.');  
}

function OnErrorLO(s) 
{
 window.location = 'Default.aspx';
}

function FixPNG()
{
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])

  if ((version >= 5.5) && (document.body.filters)) 
  {
     for(var i=0; i<document.images.length; i++)
     {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
           var imgID = (img.id) ? "id='" + img.id + "' " : ""
           var imgClass = (img.className) ? "class='" + img.className + "' " : ""
           var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
           var imgStyle = "display:inline-block;" + img.style.cssText 
           if (img.align == "left") imgStyle = "float:left;" + imgStyle
           if (img.align == "right") imgStyle = "float:right;" + imgStyle
           if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
           var strNewHTML = "<span " + imgID + imgClass + imgTitle
           + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
           + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
           + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
           img.outerHTML = strNewHTML
           i = i-1
        }
     }
  }
}

function ShowTopic(aTopicID)
{
    var aURL = 'Help.aspx';
    if (aTopicID != 0)
        aURL = aURL + '?id=' + aTopicID;
    window.open(aURL, 'caphelp', 'channelmode = 0, directories = 0, location = 0, menubar = 0, resizable = 1, scrollbars =1, status = 1, titlebar = 1, toolbar = 0, width = 550, height = 500');
}

function SetTxt(o,s)
{
 document.getElementById(o).innerText=s;
}
function SetHTML(o,s)
{
 document.getElementById(o).innerHTML=s;
}
function SetValue(o,s)
{
 document.getElementById(o).value=s;
}
function GetValue(o)
{
 return document.getElementById(o).value;
}
function GetTxt(o)
{
 return document.getElementById(o).innerText;
}
function GetHTML(o)
{
 return document.getElementById(o).innerHTML;
}
function SetClass(o,s)
{
 document.getElementById(o).className=s;
}
function SetHref(o,s)
{
 var e = document.getElementById(o);
 if (e!=null)
 {
  e.href=s;
 }
}
