function reqd(field, description){
	this.field = field;
	this.description = description;
}

//set up images for error marking
icon_warning = new Image();
icon_warning.src = "/images/icons/icon_warning.gif";
spacer = new Image();
spacer.src = "/images/spacer.gif";

function getDocObj(){
//for use with the content layer
	var docObj = new Object;
	
	if (is_ie || is_nav5up){
  		docObj = document;   
   	} else {
  		docObj = document.content580.document;
    }
	return docObj;
}

// Iterate through required array and build a list of any missing fields
function checkRequiredFields(array){
	var strError = "";
	var errWinHeight = 100;
	var message = "The information provided is incomplete. Please enter a valid telephone number before continuing."; 
	var img0ut;
	imgOut = "";
	var doc = getDocObj();
	var focusfield = null;
	
	// For every field in the array
	for (var i = 0; i < array.length; i++){
		if (isBlank(array[i].field)){
			strError += "<li> " + array[i].description + "</li>";
			errWinHeight += 15;
			
			if (focusfield == null){
				focusfield = array[i].field;
			}
		}
	}
	
	if (strError != ""){
		focusfield.focus();
		gel_error_page(message + "<p>", errWinHeight);
		return false;
	}
	return true;
}

// Iterate through required array and build a list of any missing fields
function checkRequiredFieldsConfirm(array){
	var strError = "";
	var errWinHeight = 100;
	var message = "The information provided is incomplete. Please enter a valid confirmation number before continuing."; 
	var img0ut;
	imgOut = "";
	var doc = getDocObj();
	var focusfield = null;
	
	// For every field in the array
	for (var i = 0; i < array.length; i++){
		if (isBlank(array[i].field)){
			strError += "<li> " + array[i].description + "</li>";
			errWinHeight += 15;
			
			if (focusfield == null){
				focusfield = array[i].field;
			}
		}
	}
	
	if (strError != ""){
		focusfield.focus();
		gel_error_page(message + "<p>", errWinHeight);
		return false;
	}
	return true;
}

function isBlank(element){
	var bRet = true;
	switch(element.type)
	{
		case "text":
		case "textarea":
		case "password":
				bRet = isEmpty(element.value);
				break;
		case "select-one":
		case "select-multiple":
				if (element.selectedIndex == -1){
						bRet = true;
				}else{
					if (isEmpty(element.options[element.selectedIndex].value) ||
							isEmpty(element.options[element.selectedIndex].text)){
						bRet = true;
					}else{
						bRet = false;
					}
				}
				break;
		case "radio":
				// Test a radio group
				for (var i = 0; i < element.length; i++){
					bRet = (bRet || element[i].checked);
				}
				break;
		case "checkbox":
				bRet != element.checked;
				break;
	}
	return bRet;
}

// Strings require an extra check to eliminate blanks
function isEmpty(str){
	// Is it really a text element?
	if (str == null){
		return false;
	}
	// Check whether string is empty.
	for (var intLoop = 0; intLoop < str.length; intLoop++){
		if (" " != str.charAt(intLoop)){
			return false;
		}
	}
	return true;
}

function checkNxx(field,length){
	var str = field.value;
	var strError = "";
	var errWinHeight = 65;
	var errWinTitle = "Incorrect Telephone Number";
	
		
	if (isEmpty(str)) return(true);
	var result = (str.length == length);
	var pattern=/[0-9a-zA-Z]\d\d/i;
	if (!(pattern.test(str)))
	{
		result=false;
	}
	if (result == false){
		field.focus();
		strError = "You must enter valid data in this field.  Please try again.<BR><BR>";
		gel_error_page(strError,errWinHeight,0,errWinTitle);
		field.value = "";
	}
	return result;
}

function checkNumeralLength(field,length){
	var str = field.value;
	var strError = "";
	var errWinHeight = 65;
	var errWinTitle = "Incorrect Telephone Number";
	
		
	if (isEmpty(str)) return(true);
	var result = (str.length == length);
	if (result == false){
		field.focus();
		strError = "You must enter " + length + " numerals in this field.  Please try again.<BR><BR>";
		gel_error_page(strError,errWinHeight,0,errWinTitle);
		field.value = "";
	}
	return result;
}

function checkConfirmLength(field,length){
	var str = field.value;
	var strError = "";
	var errWinHeight = 65;
	var errWinTitle = "Incorrect Confirmation Number";
	
		
	if (isEmpty(str)) return(true);
	var result = (str.length == length);
//	var pattern=/[0-9a-zA-Z]\[0-9a-zA-Z]\[0-9a-zA-Z]\[0-9a-zA-Z]\[0-9a-zA-Z]\[0-9a-zA-Z]\[0-9a-zA-Z]\[0-9a-zA-Z]/i;
	var pattern=/[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]/i;
	if (!(pattern.test(str)))
	{
		result=false;
	}
	if (result == false){
		field.focus();
		strError = "You have entered an invalid number.  Please re-enter your 8-character confirmation number. <BR><BR>";
		gel_error_page(strError,errWinHeight,0,errWinTitle);
		field.value = "";
	}
	return result;
}

function checkLength(field,length){
	var str = field.value;
	var strError = "";
	var errWinHeight = 65;
	var errWinTitle = "Incorrect Confirmation Number";
	
		
	if (isEmpty(str)) return(true);
	var result = (str.length == length);
	if (result == true && 
	    (str.charAt(0) == ' ' || str.charAt(length-1) == ' '))
	{
           result = false;
	}
	if (result == false){
		field.focus();
		if (result == null) {
			strError = "You have entered an invalid number.  Please re-enter your 8-character confirmation number. <BR><BR>";
		}
		else {
			strError = "You must enter " + length + " characters or numerals in this field.  Please try again.<BR><BR>";
		}
		gel_error_page(strError,errWinHeight,0,errWinTitle);
		field.value = "";
	}
	return result;
}

function checkInteger(field){
	var str = field.value;
	var strError = "";
	var errWinHeight = 65;
	var errWinTitle = "Incorrect Phone Number";
	
		
	if (isEmpty(str)) return(true);
	var pattern = /^\d*$/;
	var result = pattern.test(str);
	if (result == false){
		field.focus();
		if (result == null) {
			strError = "Only numerals are allowed in this field.  Please try again.<BR><BR>";
		}
		else {
			strError = "Only numerals are allowed in this field. Please try again.<BR><BR>";
		}
		gel_error_page(strError,errWinHeight,0,errWinTitle);
		field.value = "";
	}
	return result;
}


function gel_error_page(tMsg)
{
	//supports arg 1= text height in pixels, arg 2= scrollbars  1 or 0 
	//defaults: textHeight=175 (consequently winHeight=300), scrollbar= empty str

	if ((tMsg == "") || (tMsg == null))
	{
		tMsg="Error message not provided.";
	}
	var tStr="";
	var textHeight=185;
	var winTitle="Incomplete Form"
	if (arguments.length>1)
	{
		textHeight=arguments[1];
	}
	if (arguments.length>3)
	{
		winTitle=arguments[3];
	}
	
 tStr+='<html>\n';
 tStr+='<head>\n';
 tStr+='<title>BellSouth - ' + winTitle
 tStr+='</title>\n';
 tStr+='<script language="JavaScript" type="text/javascript" src="/scripts/sniffAPI.js"></script>\n';
 tStr+='</head>\n';
 
 tStr+='<BODY background="/images/popup_orange_bk.gif" onload="window.focus();">\n';
 
 tStr+='<table width="429" border="0" cellspacing="0" cellpadding="0" align="center">\n';
 
 tStr+='<tr>\n';
 tStr+='<td rowspan="3" colspan="2"><img src="/images/tl_orange_curv.gif" width="19" height="23" alt="" border="0"></td>\n';
 tStr+='<td bgcolor="#FF6600"><img src="/images/spacer.gif" height="1" width="391" border="0"></td>\n';
 tStr+='<td rowspan="3" colspan="2"><img src="/images/tr_orange_curv.gif" width="19" height="23" alt="" border="0"></td></tr>\n';
 
 tStr+='<tr>\n';
 tStr+='<td bgcolor="#FFDAC3" class="orangebold"><img src="/images/spacer.gif" height="18" width="1" border="0">Attention</td></tr>\n'; 
 
 tStr+='<tr>\n';
 tStr+='<td bgcolor="#FF6600"><img src="/images/spacer.gif" height="1" width="1" border="0"></td></tr>\n';  
 
 tStr+='<tr bgcolor="#FFFFFF">\n';
 tStr+='<td bgcolor="#FF6600"><img src="/images/spacer.gif" height="1" width="1" border="0"></td>\n';
 tStr+='<td bgcolor="#FFFFFF"><img src="/images/spacer.gif" height="1" width="18" border="0"></td>\n';
 tStr+='<td bgcolor="#FFFFFF">\n';
 tStr+='<table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#FFFFFF">\n';
 
 tStr+='<tr>\n';
 tStr+='<td valign="top"><br><img src="/images/icons/icon_warning.gif" width="23" height="21" border="0"></td>\n';
 tStr+='<td width="10">&nbsp;</td>\n';
 tStr+='<td><br><span class="bluebold">';
 tStr+=winTitle;
 tStr+='</span><br><br>\n';
 tStr+=tMsg+'\n';
 tStr+='</td></tr>\n';
 
 tStr+='<tr>\n';
 tStr+='<td align="center" colspan="3"><a href="javascript: window.close();"><img src="/images/buttons/btn_closewindow.gif" width="82" height="27" alt="Click here to Close Window" border="0"></a></td></tr>\n';
 tStr+='</table>\n';
 tStr+='</td>\n';
 
 tStr+='<td bgcolor="#FFFFFF"><img src="/images/spacer.gif" height="1" width="18" border="0"></td>\n';
 tStr+='<td bgcolor="#FF6600"><img src="/images/spacer.gif" height="1" width="1" border="0"></td></tr>\n';
 
 tStr+='<tr>\n';
 tStr+='<td rowspan="2" colspan="2"><img src="/images/bl_orange_curv.gif" width="19" height="11" alt="" border="0"></td>\n';
 tStr+='<td bgcolor="#FFFFFF"><img src="/images/spacer.gif" height="10" width="1" border="0"></td>\n';
 tStr+='<td rowspan="2" colspan="2"><img src="/images/br_orange_curv.gif" width="19" height="11" alt="" border="0"></td></tr>\n';
 
 tStr+='<tr>\n';
 tStr+='<td bgcolor="#FF6600"><img src="/images/spacer.gif" height="1" width="1" border="0"></td></tr>\n'; 
 tStr+='</table>\n';
 tStr+='</body>\n';
 tStr+='</html>\n';
	
	var winHeight=((parseInt(textHeight))+125);  //use parseInt to force textHeight to be numeric
	var sBars="";
	if (arguments.length>2)
	{
		if (arguments[2])
		{
			sBars=",scrollbars=yes,resizable=yes";
		}
	}
	
	var error_win=window.open('','blsErrorWin','width=450,height='+winHeight+sBars+',alwaysRaised=yes');
	error_win.document.open();
	error_win.document.writeln(tStr);
	error_win.focus();

}
