// JavaScripts for Local Calling Area Tool

// SUBMIT QUERYFORM -FOR SEE ALL NUMBERS
function submitform()
{
  document.queryform.submit();
}


// PRINT DIALOG 
function printResults() {
  if (window.print) {
    window.print()
  } else {
  	alert("We're sorry, your browser does not support this feature.");
  }
}

// QUIRKS


// POP UP
function newPop(A,B,X,Y,Z) { // url, name, width, height, full = 1

// width and height
windowWidth = (X < screen.width)?X:(screen.width * .8);
windowHeightTemp = (Y < screen.height)?Y:(screen.height * .8);
windowHeight = (Z == 1)?windowHeightTemp - 120:windowHeightTemp;

// specifications
winSpecsMini = "scrollbars=yes,resizable=yes,status=no,location=no,menubar=no,"+
"toolbar=no,width="+windowWidth+",height="+windowHeight;

winSpecsFull = "scrollbars=yes,resizable=yes,status=yes,location=yes,menubar=yes,"+
"toolbar=yes,width="+windowWidth+",height="+windowHeight;

winSpecs = (Z == 1)?winSpecsFull:winSpecsMini;

// launch
newWindow = window.open(A,B,winSpecs);
}

// AUTO TAB CODE 
function inputTab(obj,len,alpha,nextElement) {
var maxSize = 0 ;
var rExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

if (obj.value.length != maxSize) {
maxSize = obj.value.length;
if (alpha == 1) {
numTrue = rExp.test(obj.value);
}
if ((maxSize == len) && (numTrue)) {
nextElement.focus(); }
}
}	

// VALIDATION CODE 

function validation(W) {

	// Reset Display
	document.getElementById("areacode1label").className = "error-description-nutralization";
	document.getElementById("areacode2label").className = "error-description-nutralization";
	document.getElementById("areacode3label").className = "error-description-nutralization";
	document.getElementById("error-from").style.display = "none";
	document.getElementById("error-to").style.display = "none";
	document.getElementById("error-message").style.display = "none";
	// Variables
	var tval = "";
	var numregex = /^\d{3}$/;
	
	var val1 = document.getElementById('areacode1').value;
	var val2 = document.getElementById('exchange1').value;
	var val3 = document.getElementById('areacode2').value;
	var val4 = document.getElementById('exchange2').value;
	var val5 = document.getElementById('areacode3').value;
	var val6 = document.getElementById('exchange3').value;
	var val7 = document.getElementById('searchtype1').value;
	var val8 = document.getElementById('searchtype2').value;
	
	if((W == 1) && (val7 == "from")) { // test Calling From form
		// Form Validate and Arrow Display
		if (!numregex.test(val1) || !numregex.test(val2)) { 
			document.getElementById("error-message").style.display = "block";
			document.getElementById("areacode1label").className = "error-description";
			document.getElementById("error-from").style.display = "block";
			
			return false;
		} 
		else {
			document.getElementById("error-message").style.display = "none";
			document.getElementById("areacode1label").className = "error-description-nutralization";
			document.getElementById("error-from").style.display = "none";
			
			writeWait(); // added on 10/11/2004
			
			return true;
			
		}

	}

	if((W == 2) && (val8 == "fromto")) { // test Calling From/To form
		// Arrow and From To display part
		// Calling From
		if (!numregex.test(val3) || !numregex.test(val4)) { 
			document.getElementById("areacode2label").className = "error-description";
			document.getElementById("error-from").style.display = "block";
		} 
		else {
			document.getElementById("areacode2label").className = "error-description-nutralization";
			document.getElementById("error-from").style.display = "none";
	  	}
		// Calling To
		if (!numregex.test(val5) || !numregex.test(val6)) { 
			document.getElementById("areacode3label").className = "error-description";
			document.getElementById("error-to").style.display = "block";
		} 
		else {
			document.getElementById("areacode3label").className = "error-description-nutralization";
			document.getElementById("error-to").style.display = "none"
	  	}
		// Form Validate Part
		if (!numregex.test(val3) || !numregex.test(val4) || !numregex.test(val5) || !numregex.test(val6)) { 
		
	  		document.getElementById("error-message").style.display = "block";
	  		return false;
		} 
		else {
			document.getElementById("error-message").style.display = "none";
			
			writeWait(); // added on 10/11/2004
			
	  		return true;
		
	  	}
	
	}

}

// JavaScripts for Local Calling Area Tool

function writeWait() {
	// writes alert screen
	setTimeout('document.getElementById("waitScreenImage").src="common/images/progressBar.gif"', 100);
	document.getElementById("waitScreen").style.display = "block";
    document.getElementById("waitScreenImage").style.visibility = "visible";
    document.getElementById("waitScreenImage").style.display = "inline"; 
}
