﻿// JScript File


var btnWhichButton; // the global variable

/* Open window*/
 var windowHandle = '';
 function popOpen(url,name,attributes)
 {
 
 windowHandle = window.open(url,name,attributes);
 }

function closeIt() {
  close();
}

function emailto(TextBox) 
{
	var field = TextBox;
	var doc = "mailto:"+field.value;
	window.location = doc;
}

function bla(TextBox) 
	{
	var field = TextBox;
	var valo = new String();
	var numere = new String("0123456789.");
	var chars = field.value.split(""); 
	for (i = 0; i < chars.length; i++)
		{
		if (numere.indexOf(chars[i]) != -1) 
			valo += chars[i];
		else
			alert("No non-numeric allowed!");
		}
	if(field.value != valo) field.value = valo; 
	}
	
	
<!--
	// This file contains the data validation JavaScript functions
	// It is included in the HTML pages with forms that need these
	// data validation routines.

// Mask Function

function mask(str,textbox,loc,delim){
	var locs = loc.split(','); 
	for (var i = 0; i <= locs.length; i++){
		for (var k = 0; k <= str.length; k++){
			if (k == locs[i]){
				if (str.substring(k, k+1) != delim){
					str = str.substring(0,k) + delim + str.substring(k,str.length)
					}
				}
			}
	}
	textbox.value = str
	}


function maskDate(str,textbox,loc,delim,ErrCaption){
	var locs = loc.split(','); 
	for (var i = 0; i <= locs.length; i++){
		for (var k = 0; k <= str.length; k++){
			if (k == locs[i]){
				if (str.substring(k, k+1) != delim){
					str = str.substring(0,k) + delim + str.substring(k,str.length)
					}
				}
			}
	}
	textbox.value =str;
	if (isDate(textbox,ErrCaption)==true)
		textbox.value =str;	
	
	
	}

// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";



/****************************************************************/

// PURPOSE:  Check to see if the string passed in is a valid time.
//	A valid time is defined as a string which is postfixed with either
//  "PM" or "AM".  Next it checks to see if there is a colon in the
//  string.  If there is, it makes sure that at least one digit preceeds
//  it and two proceed it.

	function IsTime(strTime)
	{
		var strTestTime = new String(strTime);
		strTestTime.toUpperCase();

		var bolTime = false;

		if (strTestTime.indexOf("PM",1) != -1 || strTestTime.indexOf("AM",1))
			bolTime = true;

		if (bolTime && strTestTime.indexOf(":",0) == 0)
			bolTime = false;

		var nColonPlace = strTestTime.indexOf(":",1);
		if (bolTime && ((parseInt(nColonPlace) + 5) < (strTestTime.length - 1) || (parseInt(nColonPlace) + 4) > (strTestTime.length - 1)))
			bolTime = false;


		return bolTime;
	}

/****************************************************************/

function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}

function replaceDate (s, fromStr, toStr)
{
	var new_s = s.value;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	
	if (new_s.charAt(0) > '1' && new_s.charAt(0) < '9')	
	new_s= '0'+new_s;
	
	if (new_s.charAt(2) > '0' && new_s.charAt(2) < '9')	
	new_s= new_s.slice(0,1)+'0'+new_s.slice(2,2-new_s.lenght);
	
	s.value= new_s;
}

/****************************************************************/

/* PURPOSE:  Since we are using the single tick mark as the
	string delimiter to construct our SQL queries, a string with
	a tick mark in it will cause a SQL error.  Therefore we replace
	all "'" with "''", which eliminates the possibility of a SQL error.
*/

function sqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}

/****************************************************************/

function makeSafe (i)
{
	i.value = sqlSafe (i.value);
}

/****************************************************************/

// 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;
}

/****************************************************************/

// isEmail (STRING s , Error Message Str)
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function PromptEmailErrorMsg(Field,strError)
{
	alert("You have entered an invalid eMail Address for " + strError + ".  Please make sure the email format is in email@url.com format.");
	Field.focus();
	Field.select();
}

function PromptErrorMsg(strError)
{
	alert( strError );
	return false;
}



function chkDeliveryMethod(f1,f2)
{
if(isEmpty(f1.value) && f2.value>0)
	{
	alert( 'you must enter a n html file name.' );
	f1.focus();
	f1.select();
	return false;
	}
}


function isEmail(eMail,str)

{   
	var s = new String(eMail.value);
	var goodemail=true;
	
	if (isEmpty(s)) return goodemail;
    // is s whitespace?
    if (isWhitespace(s)) return goodemail;
    
    // 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) != "@")) goodemail=false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) goodemail=false;
	
	if (goodemail == false){
		PromptEmailErrorMsg(eMail,str);		
		}
		
	return goodemail;	
}


		
/****************************************************************/

// Returns true if the string passed in is a valid number
//  (no alpha characters), else it displays an error message

function isNumber(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " is a required field and must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			objField.select();
			return false;
		}

	return true;
}

function ForceNumber(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) 
		{
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			objField.select();
			return false;
		}
	

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

	return true;
}
/****************************************************************/

// Returns true if the string passed in is a valid money
//  (no alpha characters except a decimal place), 
//   else it displays an error message

function ForceMoney(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.')) {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

	return true;
}


/****************************************************************/

// Right trims the string...  Useful for SQL datatypes of CHAR

function RTrim(strTrim)
{
	var str = new String(strTrim);
	var i = 0;
	var c = "";
	var endpos = 0

	for (i = str.length; i >= 0 && endpos == 0; i = i - 1) {
		c = str.charAt(i);
		if (whitespace.indexOf(c) == -1)
			endpos = i;
	}

	return str.substring(0,endpos+1);
}

/****************************************************************/

/* PURPOSE:  Returns true if the string is a valid date number.
	A method is passed in (1 = month, 2 = day).  If the string is
	nonnumeric, false is passed back.  If the day in the date string
	is greater than 31, false is returned.  If the month is greater
	than 12, an error is returned.
*/

function isDateNumber(strNum,method)
{
	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 2)
		if (parseInt(str) > 31)
			return false;
	if (method == 1)
		if (parseInt(str) > 12)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}

/****************************************************************/

// Displays an alert box with the passed in string...

function PromptDateErrorMsg(Field,strError)
{
	alert("You have entered an invalid date for " + strError + ".  Please make sure your date format is in MM/DD/YYYY format.");
	Field.focus();
	Field.select();
}

/****************************************************************/

/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

		MM/DD/YY, MM/DD/YYYY, M/D/YY, M/D/YYYY,
		MM-DD-YY, MM-DD-YYYY, M-D-YY, M-D-YYYY
*/

function ForceDate(strDate,strField)
{
	var str = new String(strDate.value);

	if (isWhitespace(str)) {
		PromptDateErrorMsg(strDate,strField);
		return false;
		// if the field is empty, just return true...
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),1)) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),2)) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


	if (i != 2 && i != 4) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	return true;
}


function isDate(strDate,strField)
{
	var str = new String(strDate.value);

	if (isWhitespace(str)) {
		return true;
		// if the field is empty, just return true...
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),1)) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),2)) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


	if (i != 2 && i != 4) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptDateErrorMsg(strDate,strField);
		return false;
	}

	return true;
}

/****************************************************************/

// This function determines if the string passed in is a valid
// US zip code.  It accepts either ##### or #####-####.  If the
// string is valid, it returns true, else false.

function isZipCode(strZip,str)
{
	var s = new String(strZip.value);
	var GoodZip = true;

	if (s.length != 5 && s.length != 10)
		// inappropriate length
		GoodZip = false;

	for (var i=0; i < s.length; i++)
		if ((s.charAt(i) < '0' || s.charAt(i) > '9') && s.charAt(i) != '-')
		 GoodZip = false;


	if (GoodZip == false){
		alert(str);
		strZip.focus();
		strZip.select();
		}
       
	   
	return GoodZip;
}

/****************************************************************/

// This function ensures that a field is less than or equal to the
// Length passed in.  You must call this function with the element
// name in your form (for example: "ForceLength(document.forms[0].txtElement)"
// as opposed to "ForceLength(document.forms[0].txtElement.value)"
// If the field's value is too large, an error message is displayed
// and false is returned, else true is returned.

function ForceLength(objField, nLength, strWarning)
{
	var strField = new String(objField.value);

	if (strField.length > nLength) {
		alert(strWarning);
		return false;
	} else
		return true;
}

   /****************************************************************/

      function ForceEntry(val, str) {
           var strInput = new String(val.value);

           if (isWhitespace(strInput)) {
                alert(str);
				val.focus();
		        val.select();
                return false;
           } else
                return true;

      }

/****************************************************************/

 function CheckPassword(val,val2, str) {
 
           var strInput = val.value;
			var strInput2 = val2.value;
			
           if (strInput==strInput2) {
               return true;
           } else
                alert(str);
				val2.focus();
		        val2.select();
                return false;

      }


      /****************************************************************/

      function ValidateData(Button) {
           var CanSubmit = false;
		 
		   
		   if (btnWhichButton.value=='Cancel') {
		   return true;
		   }
		   
           CanSubmit = ForceEntry(document.forms[0].fFirstName,"Please supply a first name.");
           if (CanSubmit)  CanSubmit = ForceEntry(document.forms[0].fLastName,"Please supply a last name.");
		   return CanSubmit;
      }

// -->

 function KeyDownHandler(btn)
    {
       // process only the Enter key
           if (event.keyCode == 13)
           {
                // cancel the default submit
                event.returnValue    =    false;
                event.cancel        =    true;
                var obj = document.getElementById(btn);
                obj.click();
            }
    }
    
    
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    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.opacity == (30/100)) { 
        opacity(id, 30, 100, millisec); 
    } else { 
        opacity(id, 100, 30, millisec); 
    } 
}


function buildDimmerDiv()
{
    document.write('<div id="dimmer" class="dimmer" style="width:'+ window.screen.width + 'px; height:' + window.screen.height +'px"></div>');
}
  
  
 function moveToEnd (el)
  {
  
    el.value=el.value+"\nThu 7/8/2003 RF: ";

   
  }
