// Global variables and constants
var qt = String.fromCharCode(34);
var cr = String.fromCharCode(10);
var bs = String.fromCharCode(47);

function opacity(id, opacStart, opacEnd, millisec) { 
	var speed = Math.round(millisec / 100); 
	var timer = 0; 
	
	//determine the direction for the blending, if start and end are the same nothing happens 
	if(opacStart > opacEnd) { 
		for(i = opacStart; i >= opacEnd; i--) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} else if(opacStart < opacEnd) { 
		for(i = opacStart; i <= opacEnd; i++) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} 
}

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")"; 
}
	
function shiftOpacity(id, millisec) { 
		//if an element is invisible, make it visible, else make it ivisible 
		if(document.getElementById(id).style.display == 'none') { 
		opacity(id, 100, 0, 0); 
		document.getElementById(id).style.display = 'block';
        opacity(id, 0, 100, millisec); 
		} else { 
				opacity(id, 100, 0, millisec); 
				document.getElementById(id).style.display = 'none';
		} 
}

function openCentered(szURL, ynResizeable, ynScroll, ynStatus, ynLocation, ynToolbar, nWidth, nHeight)
{
var x = screen.availWidth
var y = screen.availHeight
var spaceSx = (x - nWidth)/2
var spaceUp = (y - nHeight)/2
window.open(szURL,
            "",
			"scrollbars=" + ynScroll + 
			", resizable=" + ynResizeable + 
			", left=" + spaceSx + 
			", top=" + spaceUp + 
			", width=" + nWidth + 
			", height=" + nHeight + 
			", status=" + ynStatus + 
			", location=" + ynLocation + 
			", toolbar=" + ynToolbar);
}

function isNumeric(PI_szText, PI_bInteger) {
	var ValidChars = "-0123456789.";

	if (PI_bInteger) {
		ValidChars = "-0123456789";
	}

	var szChar			= "";
	var isNumber		= true;
	var nMinusCount = 0;
	var nDotCount		= 0;

	for (i = 0; i < PI_szText.length && isNumber == true; i++) { 
		szChar = PI_szText.charAt(i);
		if (szChar == "-") {
			nMinusCount = nMinusCount + 1
		} 
		if (nMinusCount > 1) {
			isNumber = false;
		}
		if (szChar == ".") {
			nDotCount = nDotCount + 1
		} 
		if (nDotCount > 1) {
			isNumber = false;
		}
		if (ValidChars.indexOf(szChar) == -1) {
			isNumber = false;
		}
	}
	return isNumber;
}


	    function validate_email(field) {
		  var bValidEmail = true; 
		  
		  if ( field.indexOf(";") != -1 ) {
		    var aszField = field.split(";");
			for ( nInc = 0; nInc < aszField.length; nInc++ ) {
			  with (aszField[nInc]) {
			    if (aszField[nInc] != "") {
                  apos = indexOf("@")
                  dotpos = lastIndexOf(".")
                  if (apos < 1 || dotpos - apos < 2) {
			        bValidEmail = false
			      }
				}
			  }
            } 
		  } else {
		    with (field) {
              apos = indexOf("@")
              dotpos = lastIndexOf(".")
              if (apos < 1 || dotpos - apos < 2) {
			    bValidEmail = false
			  }
			}
		  }
		  
          return bValidEmail;
		}
function getPageParameters(PI_szGetString) {       
  var aszParameters      = PI_szGetString.split("?");
  var myParamKey         = "";
  var myKeys             = new Array();
  var myValues           = new Array();
  var aszTemp            = "";
  var szSearchString     = "";

  // There are parameters
  if (aszParameters.length > 1) {
    if (aszParameters[1].indexOf("%26") != -1) {
      szSearchString = "%26";
    }
	if (aszParameters[1].indexOf("&") != -1) {
      szSearchString = "&";
    }

    // If there is a & then there are one or more parameters
    if (aszParameters[1].indexOf(szSearchString) != 0) {
      aszParameters = aszParameters[1].split(szSearchString);
      for (i=0;i<aszParameters.length;i++) {
        aszTemp = aszParameters[i].split("=");
        if (aszTemp.length == 2) {
		  aszParameterNames[aszParameterNames.length] = aszTemp[0];
		  aszParameterValues[aszParameterValues.length] = aszTemp[1];
        }
      }
	// There is only one parameter
    } else { 
	  aszTemp = aszParameters[1].split("=");
      aszParameterNames[aszParameterNames.length] = aszTemp[0];
	  aszParameterValues[aszParameterValues.length] = aszTemp[1];
    }
  }
}

function getParameterValue(PI_szParameterName, PI_szReturnParameterIfNotFound){
  var szReturnString = PI_szReturnParameterIfNotFound;
  for (i=0;i<aszParameterNames.length;i++) {
    if (aszParameterNames[i].toLowerCase() == PI_szParameterName.toLowerCase()) {
	  szReturnString = aszParameterValues[i];
	}
  }
  return szReturnString;
}

function MM_swapImgRestore()
  {
    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_findObj(n, d)
  {
    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);
	
	return x;
  }

function MM_swapImage() 
  {
    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];
		}
  }


function openCentered(szURL, ynResizeable, ynScroll, ynStatus, ynLocation, ynToolbar, nHeight, nWidth)
{
var x = screen.availWidth
var y = screen.availHeight
var spaceSx = (x - nWidth)/2
var spaceUp = (y - nHeight)/2
window.open(szURL,
            "",
			"scrollbars=" + ynScroll + 
			", resizable=" + ynResizeable + 
			", left=" + spaceSx + 
			", top=" + spaceUp + 
			", width=" + nWidth + 
			", height=" + nHeight + 
			", status=" + ynStatus + 
			", location=" + ynLocation + 
			", toolbar=" + ynToolbar);
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
