//Global Javascript page
GLOBAL_CLICKED = false;

//Coenie se functions
  function setCookie(name, value, expires, path, domain, secure) 
  {
    var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
    document.cookie = curCookie;
  }
  
  function getCookie(name) 
  {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    } else
      begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
      end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
  }
 
  function deleteCookie(name, path, domain) 
  {
    if (getCookie(name)) 
    {
      document.cookie = name + "=" + 
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }
 
  function readCookie(aName)
  {
    //alert(document.cookie);
    var start = document.cookie.indexOf(aName+"=");
    if (start == -1){return ''} 
    start = document.cookie.indexOf("=",start)+1;
    var end =  document.cookie.indexOf(";",start);
    if (end == -1){return ''}
    return unescape(document.cookie.substring(start,end));
  }

  function fixDate(date) 
  {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
      date.setTime(date.getTime() - skew);
  }
  
  function writeCookie(aName,aValue)
  {
    var exDate = new Date(2050,1,1,1,1,1,1);
    var start = document.cookies.indexOf(aName+"=");
    var end =  document.cookies.indexOf(";e",start)-1;
    if ((end == -1)||(start == -1))
    {
      document.cookies = document.cookies+''+aName+'='+aValue+';expires='+exDate+';';
    }
    else
    {
      s = document.cookies.substring(0,start)+
      aName+"="+aValue+";expires="+exDate+";"+                  
      document.cookies.substring(end,99999);
    }
  }
  
 
function out(obj,color){obj.style.backgroundColor = color;}
function over(obj,color){obj.style.backgroundColor = color;cursor(obj);}
function cursor(obj){obj.style.cursor = 'hand';}
function clicked(obj){if ((obj.cells[1].children[0])&&(!GLOBAL_CLICKED)){if (obj.cells[1].children[0].tagName == "A"){location.href = obj.cells[1].children[0].href;}}}
function clicked0(obj){if ((obj.cells[0].children[0])&&(!GLOBAL_CLICKED)){if (obj.cells[0].children[0].tagName == "A"){parent.content.location.href = obj.cells[0].children[0].href;}}}


function twodec(value) {
	tempValue = parseInt(value*100)/100;
	return tempValue;
}

function getProperties(obj,sep) { 
    var properties = ""; 
    for (var propName in obj) { 
   properties +=propName+"="+obj[propName]+sep;
    } 
    return properties; 
} 

function getPropertiesContainName(obj,sep,propname) 
{ 
    var properties = ""; 
	for (var propName in obj) 
	{ 
  	if (propName.toLowerCase().indexOf(propname)>-1)
		{
			properties +=propName+"="+obj[propName]+sep;
		}
  } 
    return properties; 
}

function getRadioValue(radioObject)
{
	var value = null
	for (var i=0;i < radioObject.length; i++)
	{
		if (radioObject[i].checked)
		{
			value = radioObject[i].value;
			break;
		}
	}
	return value;
}

var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;


function MM_preloadImages() { 
	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];}}
}

//Strips a numeric value of all illegal chars. Gunther Kruger.
function cleanNumericField(iVal) {
	var re = /\s|\W|\D/g;
	if ( iVal != '' ) {
		var tmpStr = iVal;
		tmpStr = tmpStr.replace(re, '');
		if ( tmpStr != '' ) {
			return parseInt(tmpStr);
		} else {
			return parseInt(0);
		}
	} else {
		return parseInt(0);
	}
}
///////////////////////////////////////////////////////////////////////////////
//Global vars
//////////////////////////////////////////////////////////////////////////////

// whitespace characters
var whitespace = " \t\n\r";
//All the ilegal characters in a email adress i think!




var ilegal = "!\"#$%&'()*+,/:;<=>?[\\]^`{|}~ "
//																																																																		|
//var ilegal = "!\"#$%&'()*+,/:;<=>?[\\]^`{|}~  "
var g_strFromDB = "";
// Check whether string s is empty.
function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or
// whitespace characters only.
function isWhitespace (s)
{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
function isEmail (s,canBeEmpty)
{   if (isEmpty(s))
       if (!canBeEmpty) return false;
       else return true;

    // is s whitespace?
    if (isWhitespace(s)) return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
   while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    //look for a dubble @
	 if (s.indexOf("@") != -1)
	 {
		if (s.indexOf("@",s.indexOf("@")+1) != -1)
		{
			return false;
		}
	 }
	 // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function test_path()
{
alert("it works!");
}

// checks for ilegal chars
function isLegal (s)
{   var i;

	//Well if the string is not a valid email adress then  add the @ sign
	if (isEmail(s)){ilegal1 = ilegal}else{ilegal1 = ilegal + "@"}
    // Search through string's characters one by one
    // until we find a ilegal character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (ilegal1.indexOf(c) != -1) return false;
    }

    // All characters are whitespace.
	 return true;
}


// Validate South African ID numbers. Thank you www.fraudsa.co.za ;-)
function isSAID (s) {
	var val1 = 0;
	var val2 = 0;
	var iLoop;
	var cTmp;
	var strAcc = new String(s);
	if (strAcc.length == 13) {
	  for (iLoop=0; iLoop<13; iLoop=iLoop+2) {
      cTmp = strAcc.charAt(iLoop);
      if (isNaN(cTmp)) {
        //window.alert("Please, enter a thirteen digit number.");
        return false;
      }
      val1 = val1 + eval(cTmp);
	  }
	  for (iLoop=1; iLoop<12; iLoop=iLoop+2) {
      cTmp = strAcc.charAt(iLoop);
      if (isNaN(cTmp)) {
        //window.alert("Please, enter a thirteen digit number.");
        return false;
      }
      cTmp = eval(cTmp) * 2;
      if (cTmp >= 10) {
        cTmp = (cTmp - 10) + 1;
      }
      val2 = val2 + cTmp;
	  }
	  var iTotal = ((val1 + val2) / 10);
	  cTmp = iTotal.toString(10);
	  var sTmp = ".";
	  var iValid = cTmp.indexOf(sTmp, 0);
	  if (iValid == -1) {
      //OpenValid(strAcc); //Just a popup saying yay.
      return true;
	  } else {
      //OpenInvalid(strAcc); //Just a popup saying nay.
      return false;
	  }
	} else {
    //window.alert("Please, enter a thirteen digit number.");
    return false;
  }
}

//Strips a numeric value of all illegal chars. Gunther Kruger.
function cleanNumericField(iVal) {
	var re = /\s|\W|\D/g;
	if ( iVal != '' ) {
		var tmpStr = iVal;
		tmpStr = tmpStr.replace(re, '');
		if ( tmpStr != '' ) {
			return parseInt(tmpStr);
		} else {
			return parseInt(0);
		}
	} else {
		return parseInt(0);
	}
}

function viewImage(obj,size) {
	window.open('showImage.cfm?imageName='+obj+'&size='+size,'imageWin','width=180,height=180,scrollbars=no,toolbars=no');
}
function openWin(url,w,h) {
	window.open(url,'pop','width='+w+',height='+h+',scrollbars=no,toolbars=no');
}

function frmValidation(frmObj) {
  //  Eta my bra. CFML changes the obj. Use '_CF_this' when calling this function instead of 'this' 
  //
  //  Form bits:
  //  <input type="text" param="[boolean],[number_of_validation_script],'[error_message]'">
  //  OR
  //  <input type="text" param="[boolean],'[custom_function_returning_boolean]','[error_message]'">
  //
  //  Ex.
  //  <input type="text" param="1,3,'Please enter your ID number.'">
  //
  with (frmObj) 
  {
    var functionArr = new Array(4);
    var frmObjItem;
	  
    functionArr[0] = 'isEmpty(frmObjItem.value)';
    functionArr[1] = '!isEmail(frmObjItem.value)';
    functionArr[2] = '!isLegal(frmObjItem.value)';
    functionArr[3] = '!isSAID(frmObjItem.value)';

    for (i=0;i<frmObj.length;i++) 
    {
	  	
      if (frmObj[i].attributes['param'] != undefined) 
      {
        tmpArr = frmObj[i].attributes['param'].nodeValue.split(',');
        if (tmpArr[0] == '1') 
        {
          frmObjItem = frmObj[i];
          if (isNaN(tmpArr[1])) 
          {
            if (eval(tmpArr[1].substr(1,tmpArr[1].length-2))) 
            {
              alert(tmpArr[2].substr(1,tmpArr[2].length-2));
              frmObjItem.focus();
              return false;
            }// if
          } 
          else 
          {
            if (eval(functionArr[tmpArr[1]])) 
            {
              alert(tmpArr[2].substr(1,tmpArr[2].length-2));
              frmObjItem.focus();
              return false;
            }// if
          } // isNaN
        }// if
      }// if
    }// for
  }// with
	return true;
}
 
function BreakItUp(biu_FormName, biu_FormField)
{
  biu_FormObj = eval("document."+biu_FormName);
  biu_FormFieldObj = eval("document."+biu_FormName+"."+biu_FormField);
  alert(biu_FormFieldObj.value);
  //Set the limit for field size.
  var FormLimit = 102399
  
  //Get the value of the large input object.
  var TempVar = new String
  TempVar = biu_FormFieldObj.value
  
  //If the length of the object is greater than the limit, break it
  //into multiple objects.
  if (TempVar.length > FormLimit)
  {
    biu_FormFieldObj.value = TempVar.substr(0, FormLimit)
    TempVar = TempVar.substr(FormLimit)
    
    while (TempVar.length > 0)
    {
      var objTEXTAREA = document.createElement("TEXTAREA")
      objTEXTAREA.name = biu_FormField
      objTEXTAREA.value = TempVar.substr(0, FormLimit)
      biu_FormObj.appendChild(objTEXTAREA)
      
      TempVar = TempVar.substr(FormLimit)
    }
  }
}

function popupMsg(msg)
{
  return showModalDialog("blankmsg.cfm?id="+msg,"","font-family:Verdana; font-size:12; dialogWidth:300px; dialogHeight:170px; status=0" )
}