	
	 function ctry(var1) {
                 var url = "/profiles/servlet/Lookups?page=COUNTRY&selCtry=ALL" ;

                 // 05/24/2004:Chandrika: openPlainWindow(url,500,400,100,100);
                tiLookupwin("COUNTRY", var1);
        }
	
	function state(var1) {
		if(stateDisabled) return;
		if(document.frm.txtCtry.value == "" || document.frm.txtCtry.value == "UNITED STATES"){
			var url = "/profiles/servlet/Lookups?page=COUNTRY&selCtry=ALL" ;
	        tiLookupwin("STATE", var1);
        }else{
        	alert("State fields could be selected only if the Country is United States");
			document.frm.txtCtry.focus();
        	return;
        }
    }
    
    function validRangeFields(minObj, maxObj,fieldName) {

	   if(minObj.value != "" && maxObj.value == ""){ 
	   	   alert("Please enter a valid number for " + fieldName + " end range");
	   	   maxObj.focus();
	   	   return false;  	
	   }

	   if(minObj.value == "" && maxObj.value != "")  {
	   	   alert("Please enter a valid number for " + fieldName + " start range");
	   	   minObj.focus();
	   	   return false;
	   }
	   	   
       
       if (minObj.value != "" || maxObj.value != "" ) {
       	   
	       if (isNumData(minObj) && isNumData(maxObj) ) {
	           
		       if(Math.round(minObj.value) < 0) {
				alert("Please enter a valid number for " + fieldName + " start range");
				minObj.focus();
				minObj.select();
				return false;
			   }
		
		       if(Math.round(maxObj.value) < 0) {
				alert("Please enter a valid number for " + fieldName + " end range");
				maxObj.focus();
				maxObj.select();
				return false;
			   }

	       	  var rangeFrom = Math.abs(minObj.value);
			  var rangeTo = Math.abs(maxObj.value);
		
		       if(rangeFrom > rangeTo ) {
				alert( fieldName + " end range should be greater than the start range");
				maxObj.focus();
				maxObj.select();
				return false;
			   }
			   
	       }
       
       }
       return true;
    }
    
    function county(var1){
		if(countyDisabled) return;
    	if(document.frm.txtCtry.value == "" || document.frm.txtCtry.value == "UNITED STATES"){
		//	var url = "/profiles/servlet/Lookups?page=COUNTY&selState=" +  document.frm.txtState.value;
		//	alert(url); 
			if (document.frm.txtState.value == "") {
				document.frm.txtCounty.vlaue='';
				alert("Select at least one State before selecting a County");
				return;
			}
	        tiLookupwin("COUNTY", var1);
	    }else{
	    	alert("County fields could be selected only if the Country is United States");
			document.frm.txtCtry.focus();
        	return;
	    }
    }
    
    function countyKeyDown(){
    	alert("Click on Lookup to select a County from the list");
     	return false;
    }
    
    function countyKeyUp(){
        alert("yes"); 
     	var currentValue = document.frm.txtCounty.value;
    	if (currentValue.length > 0)
    		document.frm.txtCounty.value = currentValue.substr(0,currentValue-1); 
    }
    
    function clearCountyField(){
    	document.frm.txtCounty.value="";
    }
    
    function valCounty(var1){
    	if(document.frm.txtCtry.value == "" || document.frm.txtCtry.value == "UNITED STATES"){
			//var url = "/profiles/servlet/Lookups?page=COUNTY&selState=" = +  document.frm.txtState.value;
	       // tiLookupwin("COUNTY", var1);
	    }else{
	    	alert("County fields could be selected only if the Country is United States");
	    	document.frm.txtCounty.vlaue='';
			document.frm.txtCtry.focus();
        	return;
	    }
    }
    
    function hsc(var1) {
			var url = "/profiles/servlet/Lookups?page=COUNTRY&selCtry=ALL" ;
	        tiLookupwin("HARMCODE", var1);
    }
    
    function sic(var1) {
			var url = "/profiles/servlet/Lookups?page=COUNTRY&selCtry=ALL" ;
	        tiLookupwin("SIC", var1);
    }
	
function fnOpenModal(){
    if(document.frm.searchresult.value=="0")
    window.showModalDialog("Your Search did not return any results. Please Adjust Your Search Criteria.");
}

function newPick(val, fieldname) {
           
	var len = document.frm.elements.length;

	for( i=0 ; i<len ; i++) {
  		var name = document.frm.elements[i].name;
    	var prevval = document.frm.elements[i].value;
        if (name == fieldname){
			if (prevval == '')
		  		document.frm.elements[i].value = val;
			else
				document.frm.elements[i].value = prevval + ' OR ' + val;
				break;
			}
	    }
	    
	    if(fieldname == "txtSIC"){
	    	document.frm.rdLookUp[1].checked = true;
	    }
	    if(fieldname == "txtHSCode"){
	    	document.frm.rdLookUp[2].checked = true;
	    }
}

function ZeroResult(){
	if(document.frm.searchresult.value=="0")
		alert("Your Search did not return any results. Please Adjust Your Search Criteria.");
}
	
//ADDED BY ILYA MARMUR 4/27/04
function getandor(place) {
	if (document.frm.elements[place].checked == true) {
		return true;
	}
	if (document.frm.elements[place+1].checked == true) {
		return false;
	}
}
	
function hscall(frm) {
  frm.action = "/profiles/servlet/Lookups?page=HS%20CODE&selHScode=ALL";
  frm.submit(frm);
}

function getHSCode() {
	//document.frm.submit.focus();
	var xx = document.frm.hscode.value;
             //            xx = xx.replace('%','*');
	  //window.location.href = "/profiles/servlet/Lookups?page=HS%20Code&selHScode=" + xx ;
            xx = xx.toUpperCase();
            myString = new String(xx);
            var len = myString.length;
            var i = 0;
            var badTextField = 'false';
            for (i=0; i<len; i++)
            {
              var a = myString.charCodeAt(i);
              if ((a < 65) || ( a > 90))
              {
                alert ("No special characters allowed");
                badTextField = 'true';
                break;
              }
            }

            if (badTextField == 'false')
            {
              alert (xx);
			  document.frm.action = "/profiles/servlet/Lookups?page=HS%20CODE&selHScode=" + xx ;
			  document.frm.submit(frm);

            }
}

//Changed this to accept whichlookup as a variable.  This allowed the second Country of Origin lookup
//to be sent via the url.  It had been hard coded as Country of Origin - AK 4/14/04
function getCountryofOrigin(frm, whichlookup) {
   var xx = frm.cntryvals.value;
   xx = xx.replace('%','*');
   frm.action = "/profiles/servlet/Lookups?page=" + whichlookup + "&selCtry=" + xx;
   frm.submit(frm);

}
		
//Changed this to accept whichlookup as a variable.  This allowed the second Country of Origin lookup
//to be sent via the url.  It had been hard coded as Country of Origin - AK 4/14/04
function ctryall(frm,whichlookup) {
  frm.action = "/profiles/servlet/Lookups?page=" + whichlookup + "&selCtry=ALL";
  frm.submit(frm);
}


function portarr() {
  	var url = "/profiles/servlet/Lookups?page=FGN%20FINAL%20DEST&selPArr=ALL" ;
	alert("in portarr");  

}
        
function portarrall(frm) {
         frm.action = "/profiles/servlet/Lookups?page=FGN%FINAL%20DEST&selPArr=ALL";
         frm.submit(frm);
}

//Changed this to accept whichlookup as a variable.  This allowed the second Port of Arrival lookup
//to be sent via the url.  It had been hard coded as Port of Arrival - AK 4/14/04
function getPortArr(frm, whichlookup) {
	var xx = frm.portArrVals.value;
    xx = xx.replace('%','*');
	frm.action = "/profiles/servlet/Lookups?page=" + whichlookup + "&selPArr=" + xx ;
	frm.submit(frm);
}

function portemb() {
	if(usportDisabled) return;
	var url = "/profiles/servlet/Lookups?page=FGN PORT OF LOAD&selEmb=ALL" ;
    tiLookupwin("USPORT","txtPortOfLoad");
}

/*  Changed portemball to accept another parameter.  This allows for Place of Receipt and Foreign Dest to use this function,
    as well as Port of Embarkation.  This function returns all ports, and is used after a user has searched for a specific port
	and then wants to views all ports again. AK - 4/6/04
*/
function portemball(frm, whichlookup) {
          frm.action = "/profiles/servlet/Lookups?page=" + whichlookup + "&selEmb=ALL" ;
          frm.submit(frm);
}

/* Changed getembarkation to accept another parameter: whichpage.  This allows for Place of Receipt, Foreign Dest, 
   and Port of Embarkation to use the search function on the lookup page. AK - 4/6/04
 */

function getembarkation(frm, whichpage) {
	var xx = frm.portEmbVals.value;
	xx = xx.replace('%','*');
	frm.action = "/profiles/servlet/Lookups?page=" + whichpage + "&selEmb=" + xx ;
	frm.submit(frm);

}


function tiLookupwin(var1, var2) {
   var w1 = "PIERS_" + var1;
   iFilterBy = "none";
   if(var1 == "COUNTRY") w1 = "PIERSTI_COUNTRY";
   if(var1 == "STATE"){
   	w1 = "PIERS_STATE";
   }
   if(var1 == "COUNTY")  { 
    	w1 = "TTT_ZIPCODES";
    	iFilterBy = document.frm.txtState.value;
   }
   var url="/profiles/jsp/profiles_lookup3.jsp?ipgBrowse=first&iqryTable="+w1+"&ifirstRec=1&ilastRec=25&itotalRec=0&ilookupFld="+var2+"&iWhere=none&iFilterBy=" + iFilterBy + "&iBuildtbl=0&rsfirstrec=1";
   openPlainWindow(url,600,600,100,100);
   
}   
  
function clearSearch(theForm){

	for(i=0; i < theForm.elements.length; i++){
		
		if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea"){
			theForm.elements[i].value = "";
			
		}else if(theForm.elements[i].type == "checkbox"){
			theForm.elements[i].disabled = false;
			theForm.elements[i].checked = false;
			
		}else if(theForm.elements[i].type == "select-one"){
			theForm.elements[i].options[0].selected = true;
			
		}
	}	
}

function isNumData(fieldName){
	var txt = trim(fieldName.value);
	txt = txt.toUpperCase();
	txt = replaceComma(txt);
	fieldName.value = txt;
	
	var arr = txt.split(' OR ');
	for(a=0; a < arr.length; a++){
		var val = trim(arr[a]);
		if (fieldName.name == "txtSIC") {
		    if (val.indexOf('*') >= 0 && val.length < 3) {
		    	alert("The SIC Code:" + val + " is not a valid wildcard search. Please enter at least two digits followed by the *.");
		    	fieldName.focus();
				//fieldName.select();
				return false;
		    }
		    val = val.replace("*","");
		}else if (fieldName.name == "txtZip") {
		    if (val.indexOf('*') >= 0 && val.length < 3) {
		    	alert("The Zip Code:" + val + " is not a valid wildcard search. Please enter at least two digits followed by the *.");
		    	fieldName.focus();
				//fieldName.select();
				return false;
		    }
		    val = val.replace("*","");
		}else if (fieldName.name == "txtHSCode") {
		    if (val.indexOf('*') >= 0 && val.length < 3) {
		    	alert("The HS Code:" + val + " is not a valid wildcard search. Please enter at least two digits followed by the *.");
		    	fieldName.focus();
				//fieldName.select();
				return false;
		    }
		    val = val.replace("*","");
		}
		if(isNaN(val)){
			if(fieldName.name == "txtSIC"){ 
				alert("The SIC Code:"+ val +" is not a valid SIC Code or a valid wildcard search. Please enter a valid 4 digit numeric SIC Code or at least two digits followed by the *.");
			}else if(fieldName.name == "txtHSCode"){
				alert("The HS Code:"+ val +" is not numeric. Please enter a valid numeric HS Code.");
			}else if(fieldName.name == "txtEstValFrom"){
				alert("Please enter a valid number for Estimated Value");
			}else if(fieldName.name == "txtEstValTo"){
				alert("Please enter a valid number for Estimated Value");
			}else if(fieldName.name == "txtZip"){ 
				alert("The Zip Code:"+ val +" is not a valid Zip Code or a valid wildcard search. Please enter a valid Zip Code or at least two digits followed by the *.");
			}else {
				alert("Please enter a valid number. ");
			}
			fieldName.focus();
			fieldName.select();
			return false;
		}
		
	}
	
	if(fieldName.name == "txtEstValFrom" || fieldName.name == "txtEstValTo"){
		if(Math.round(txt) < 0 || Math.round(txt) < 0){
			alert("Please enter a valid positive number for Estimated Value");
			fieldName.focus();
			fieldName.select();
			return false;
		}
		
		//document.frm.lstEstVal.selectedIndex = 0;
	}
	
	return true;
}

function valOther(){
	var val = document.frm.lstEstVal.options[document.frm.lstEstVal.options.selectedIndex].value;
	
	if(val != ""){
		document.frm.txtEstValFrom.value = "";
		document.frm.txtEstValTo.value = "";
	}
}