firstrun = false;
ok2check = 1;

function checkState(sel){

	for (j=0; j<sel.options.length; j++) {
	
		if (sel.options[j].selected) {
		
			  if (sel.options[j].value.indexOf("Non-US") != -1){
				
				 theProvinceField = document.forms[0].province.value;
				 theProvince = prompt("Please enter the name of the Non-US province of your company headquarters",theProvinceField);
				
				 
				 //provMatch = theProvince.match(badpat);
				 
				 if (theProvince != null){
				 //	if (provMatch){
				 //	astpat = /\*/g;
				 //	theProvince = theProvince.replace(badpat,'*');
				 //	theProvince = theProvince.replace(astpat,'');
				 //	}
				 document.forms[0].province.value = theProvince;
				 sel.options[j].value = theProvince + " (Non-US)";
				 sel.options[j].text = theProvince + " (Non-US)";
				 }
			  }
			  return;
			
		}
		
	}
		
}


function insertOldSchool(theSel, newText, newValue)
{
 
  theSel.focus();
  var selLength = theSel.length;
 
  if (theSel.length == 0) {
    var newOpt1 = new Option(newText, newValue);
    theSel.options[0] = newOpt1;
    theSel.selectedIndex = 0;
  } else if (theSel.selectedIndex != -1) {
    
    var selText = new Array();
    var selValues = new Array();
    var selIsSel = new Array();
    var newCount = -1;
    var newSelected = -1;
    var i;


	var selLength = theSel.length;

    var newOpt = new Option(newText, newValue);
    theSel.options[selLength] = newOpt;
    theSel.selectedIndex = selLength;
     
  }

}





function addItem(theListName,theButtonID,theInstruction){


firstrun = false;

altButtonID = theButtonID;
if (theButtonID.indexOf('del') == -1){
theButtonID = 'del' + theButtonID;
}else{
theButtonID = theButtonID;
}


 theList = eval("document.forms['sdform'].elements['" + theListName + "']");
 
 if (theList.options[0]){ 
	 if (theList.options[0].value.indexOf("Click +") != -1){
		theList.options[0] = null;
	 }
 }
 

 theListLength = theList.length;
 
 thisBrand = prompt(theInstruction);
 
 if (thisBrand != "" && thisBrand != null){
  document.getElementById(theButtonID).src = "/images/button-sd-remove-1.gif";

  if (theList.selectedIndex == -1){
  	if (theListLength != 0) { 		
  		theList.options[theListLength-1].selected = true;
  	}
  }
  

 insertOldSchool(theList, thisBrand, thisBrand);
 manageList(theList,altButtonID);
 }
 


}

function delItem(theListName,theButtonID){

if (theButtonID == 'delbrand'){
	proceed = confirm("IMPORTANT: Clicking \"OK\" will remove this subsidiary's listing and data from the Supplier Directory.  If you simply wish to rename this subsidiary, please press \"Cancel\" and do so on its subsidiary page.");
}else{
	proceed = true;
}

	if (proceed){
	 theList = eval("document.forms['sdform'].elements['" + theListName + "']");
	 theList.focus();
	  
	 theListLength = theList.length;
	 
		for(i = 0; i<=theListLength; i++){
		
			if (theList.options[i]){
			
				if (theList.options[i].selected){
							
					theList.options[i] = null;
					
					if (theList.length >= 1){
						if (i > 0){
						theList.options[i-1].selected = true;
						}else{
						theList.options[i].selected = true;
						}
					}
				
				break;
				}
			}
			
		}
	manageList(theList,theButtonID);
	}

}



selIndex = 0;

function manageList(theListObj,buttonID,direction){

if (buttonID.indexOf('del') == -1){
delButton = 'del' + buttonID;
}else{
delButton = buttonID;
}
upButton = buttonID + 'up';
downButton = buttonID + 'down';

upButtonOff = "/images/bttn-up-0.gif"; 
downButtonOff = "/images/bttn-down-0.gif"; 
upButtonOn = "/images/bttn-up-1.gif"; 
downButtonOn = "/images/bttn-down-1.gif"; 


noselection = true;


//alert(firstrun);


listObjLength = theListObj.length;

if (listObjLength > 0 && firstrun == true){
	if(theListObj.options[0].value.indexOf('+ ADD') == -1){
	theListObj.options[0].selected = true;
	}
}

if (!firstrun){
theListObj.focus();
}

	if (listObjLength == 0){
		document.getElementById(delButton).src = "/images/button-sd-remove-0.gif";	
	}else{
		
		if (theListObj.options[0].value.indexOf('+ ADD') != -1){
			document.getElementById(delButton).src = "/images/button-sd-remove-0.gif";
		}else{
			for(i = 0; i<=listObjLength; i++){
				if (theListObj.options[i].selected){	
					if (direction != null){
					selIndex = direction ? i - 1 : i + 1;
					theListObj.options[selIndex].selected = true;
					theListObj.options[i].selected = false;
					}else{
					selIndex = i;
					}
					document.getElementById(delButton).src = "/images/button-sd-remove-1.gif";
					noselection = false;
					break;
				}
			}
			if (noselection){
				document.getElementById(delButton).src = "/images/button-sd-remove-0.gif";			
			}
		}
	}
	
	if (buttonID.indexOf('del') == -1){
		
		if (listObjLength < 2 || noselection){
			document.getElementById(upButton).src = upButtonOff;
			document.getElementById(downButton).src = downButtonOff;
		}else{
			if (selIndex == 0){
				document.getElementById(upButton).src = upButtonOff;
				document.getElementById(downButton).src = downButtonOn;
			}else if (selIndex == listObjLength-1){
				document.getElementById(upButton).src = upButtonOn;
				document.getElementById(downButton).src = downButtonOff;			
			}else{
				document.getElementById(upButton).src = upButtonOn;
				document.getElementById(downButton).src = downButtonOn;			
			}
		}
	
	}

	 if (direction != null){
	 theListObj.blur();
	 }
}


/*
function manageList(theListObj,buttonID){


noselection = true;

listObjLength = theListObj.length;

if (listObjLength > 0 && firstrun == true){
	if(theListObj.options[0].value.indexOf('+ ADD') == -1){
	theListObj.options[0].selected = true;
	}
}

if (!firstrun){
theListObj.focus();
}

	if (listObjLength == 0){
		document.getElementById(buttonID).src = "/images/button-sd-remove-0.gif";	
	}else{
		
		if (theListObj.options[0].value.indexOf('+ ADD') != -1){
			document.getElementById(buttonID).src = "/images/button-sd-remove-0.gif";
		}else{
			for(i = 0; i<=listObjLength; i++){
				if (theListObj.options[i].selected){								
					document.getElementById(buttonID).src = "/images/button-sd-remove-1.gif";
					noselection = false;
					break;
				}
			}
			if (noselection){
				document.getElementById(buttonID).src = "/images/button-sd-remove-0.gif";			
			}
		}
	}
	 theListObj.blur();
}

*/

function showExecForm(){
	initExecForm();
	document.getElementById("execdiv").style.visibility = "visible";
}

function addExec(){
theList = new Object();
theList = document.forms["sdform"].elements["execs[]"];
	if (theList.length > 0){
	theList.options[0].selected = "true";
	}
theList.focus();
exectitles = "";
	if (theList.options[0]){
		if (theList.options[0].value.indexOf("Click +") != -1){
		theList.length = 0;
		}
	} 
	execname1 = document.forms[0].execlname.value + ', ' + document.forms[0].execfname.value; 
	execname2 = document.forms[0].execfname.value + ' ' + document.forms[0].execlname.value;

	for (i=1;i<=26;i++) {
		thisCheckbox = new Object();
		thisCheckbox = eval("document.forms[0].exectitle"+i+"");
		if (thisCheckbox.checked) {
		exectitles += thisCheckbox.value;
		exectitles += ", ";
		}
	}

exectitles += document.forms[0].customtitles.value;
lastChar = exectitles.substring(exectitles.length-2,exectitles.length);
if (lastChar == ", "){
exectitles = exectitles.substring(0,exectitles.length-2);
}

execLength = document.forms["sdform"].elements["execs[]"].length;
execEntry1 = execname1 + " - " + exectitles;
execEntry2 = execname2 + " - " + exectitles;

 if (execname2.length > 2){
 insertOldSchool(theList, execEntry2, execEntry1);
 }
 

document.getElementById("execdiv").style.visibility = "hidden";

manageList(theList,"exec");


}

function initExecForm(){
document.forms[0].execlname.value = "";
document.forms[0].execfname.value = "";
document.forms[0].customtitles.value = "";
	for (i=1;i<=26;i++) {
		thisCheckbox = new Object();
		thisCheckbox = eval("document.forms[0].exectitle"+i+"");
		if (thisCheckbox.checked) {
		thisCheckbox.checked = false;
		}
	}
}



var formObject = new Object();


/******* PREP FORM ********/

function prepForm(category,theForm,entryType){

	
formObject = theForm;

if (category != 'aliases'){
	if (checkForm(category,entryType)){
	//alert("form checked");
	}else{
	//alert("form checked");
	return false; 	
	}
}


listWidgets = new Array('execs[]','brands[]');

	switch (category.toLowerCase()){
	
	case "airlines":
	listWidgets.push('hubs[]','alliances[]','stations[]');
	break;
	
	case "payment":
	listWidgets.push('networks[]','card_issuers[]','keyproducts[]');
	break;

	case "tech":
	listWidgets.push('keyproducts[]');
	break;
	
	case "tmc":
	listWidgets.push('network_affiliations[]');
	break;	
	
	case "aliases":
	listWidgets.length = 0;
	listWidgets.push('aliases[]');
	break;
	
	}
	
	for(w = 0;w<listWidgets.length;w++){
	thisWidget = new Object;
	thisWidgetName = listWidgets[w];
	
	thisWidget = document.forms["sdform"].elements[thisWidgetName];

		for(var i = 0;i < thisWidget.length;i++){
			if (thisWidget.options[i].value != "" && thisWidget.options[i].value.indexOf('+ ADD') == -1){
				thisWidget.options[i].selected = true;
			}
		}

	}
	
	return true;
}

function getSector(sel){
	for (j=0; j<sel.options.length; j++) {
		if (sel.options[j].selected) {
		  theSectorName = sel.options[j].value;
		  query = window.location.search;
		  newCat = 'category=' + theSectorName;
		  newQuery = query.replace(/category=[^&$]+/i,newCat);
		  window.location.href = "/supplier-directory/supplier-directory.php" + newQuery;
		  return;
			}
		}
}



function initAllLists(){

firstrun = true;

if (document.forms["sdform"].elements["brands[]"] != null){

	if (document.forms["sdform"].elements["aliases[]"]){
		aliasList = document.forms["sdform"].elements["aliases[]"];
		manageList(aliasList,"delalias");
	}else{
	
		
		if (document.forms["sdform"].elements["hubs[]"]){
		theHubList = document.forms["sdform"].elements["hubs[]"];
		manageList(theHubList,"hub");
		}
		if (document.forms["sdform"].elements["stations[]"]){
		theStationsList = document.forms["sdform"].elements["stations[]"];
		manageList(theStationsList,"station");
		}
		if (document.forms["sdform"].elements["alliances[]"]){
		theAllianceList = document.forms["sdform"].elements["alliances[]"];
		manageList(theAllianceList,"alliances");
		}
		if (document.forms["sdform"].elements["networks[]"]){
		theNetworksList = document.forms["sdform"].elements["networks[]"];
		manageList(theNetworksList,"network");
		}
		if (document.forms["sdform"].elements["card_issuers[]"]){
		CardIssuersList = document.forms["sdform"].elements["card_issuers[]"];
		manageList(CardIssuersList,"issuers");
		}
		if (document.forms["sdform"].elements["keyproducts[]"]){
		KeyProductsList = document.forms["sdform"].elements["keyproducts[]"];
		manageList(KeyProductsList,"products");
		}
		if (document.forms["sdform"].elements["network_affiliations[]"]){
		NWaffilList = document.forms["sdform"].elements["network_affiliations[]"];
		manageList(NWaffilList,"network");
		}
		
		theExecList = document.forms["sdform"].elements["execs[]"];
		theBrandsList = document.forms["sdform"].elements["brands[]"];
		
		manageList(theExecList,"exec");
		manageList(theBrandsList,"brand");
		
	}

}

firstrun = false;



}


function popupConfirmMsg(msg) { 
document.returnValue = confirm(msg);
}


alertHead = '<div style="float:left;"><b style="color: #6528CB;">ALERT:</b> The company name you entered...</div><div class="closebox"><a href="Javascript:closeMssg()" style="text-decoration: none; color: #6528CB;">X</a></div><br><br>';

function checkCompanyName(thisCompany,thisCat,coType){
	
	cotext = coType == 'p' ? 'parent company' : 'subsidiary';
	
	if (thisCompany.length > 2){
	
		var xmlhttp =  new XMLHttpRequest();
		xmlhttp.open('POST', '/supplier-directory/includes/checkCompanyName.php', true);

		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200){
				  resultcode = xmlhttp.responseXML.getElementsByTagName('result')[0].firstChild.data;
				  
				  if (resultcode == 1){
						  
					append = '';
					if(xmlhttp.responseXML.getElementsByTagName('companyid')[0].firstChild.data != null){
					append += '<br><br><div align="center"><b>';
						arrayLength = xmlhttp.responseXML.getElementsByTagName('companyid').length;
						
						for (i = 0; i < arrayLength; i++){
							if(xmlhttp.responseXML.getElementsByTagName('companyid')[i].firstChild.data != null){
							thisCo = xmlhttp.responseXML.getElementsByTagName('companyid')[i].firstChild.data;
							append = (append + '<a href="/supplier-directory/index.php?category=' + thisCat + '&company=' + thisCo + '&type=' + coType + '&action=display" style="color: #0055C8;">' + thisCo + '</a>');
							append = (append + '<br>');
							}
						}
					append += '</b></div><br><br>';
					SDmssg(alertHead + "<b><div align=\"center\" style=\"font-size: 14px; color: #6528CB;\">" + thisCompany + "</div></b><br> may already have a <i>" + cotext + "</i> entry in the <span style=\"color: #0055C8; font-style: oblique;\">Supplier Directory</span>.  Please review the companies below to rule out a match.  If your company is shown, click the link to review or edit the data we have.  Otherwise, please close this message box and continue to register your company with our directory . " + append);
		
					}
							
				  }
					
				}else{
				//alert(xmlhttp.status);
				}
			}
		}
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send('company=' + thisCompany + '&category=' + thisCat + '&entry_type=' + coType);
	}

}

function SDmssg(Mssg){	
	mssgbox = document.getElementById('messagebox');
	mssgbox.innerHTML = Mssg;
	mssgbox.style.visibility = 'visible';	
}

function closeMssg(){
	mssgbox = document.getElementById('messagebox');
	mssgbox.style.visibility = 'hidden';		
}



function checkForm(sectorName,entryType){
		
	if (ok2check){

		if (!checkAdmin()){
		return false;
		}
		
		
		if (!checkProfile()){
		return false;
		}
		
		if (sectorName != "TMC"){
			if (!checkFinancial()){
			return false;
			}
		}		
		
		if (sectorName == "Airlines"){
			if (!checkAirSector()){
			return false;
			}
		}

		if (sectorName == "Payment"){
			if (!checkPaymentSector()){
			return false;
			}
		}		
	

		if (sectorName == "Tech"){
			if (!checkTechSector()){
			return false;
			}
		}
	

		if (sectorName == "Lodging"){
			if (!checkLodgingSector()){
			return false;
			}
		}
		
		if (sectorName == "Rental"){
			if (!checkRentalSector(entryType)){
			return false;
			}
		}
		
		if (sectorName == "TMC"){
			if (!checkTMCSector(entryType)){
			return false;
			}
		}
		
		return true;
		
	}else{
	
		return true;
	
	}
	
}

badpat = /[^a-zA-Z'\.&\,\-\(\) ]/g;
badpat2 = /[^a-zA-Z'\-\(\) ]/g;
badpat3 = /[^a-zA-Z0-9'\.&\,\-\(\) ]/g;
webpat = /([a-z]{0,}[:\/]+)?([^\/]+)(\/)?(.+)?$/i;
webpat2 = /[^\/:\=\?\&\%a-zA-Z0-9\._\-]/g;
webxpat = /\.[a-z]{2,6}\/?$/i;
tpat = /^(.+)$/i;
epat = /^[\._'\-\w]+@[_'\-\w]+\.([\._'\-\w]+\.)?([a-z]{2,6})$/i;
alphapat = /^[\.'\-\w\s]+$/i;
alphanumpat = /[^\.'\-\w\s0-9]+$/i;
stockpat = /[^A-Z0-9\-\s]/gi;
textpat = /[^\.'\"\><\?=\/:$\#\@\!\&\%\(\)\-\,\w\s0-9]/gi;
numpat = /[^0-9]/g;
numpat2 = /[^0-9,]/g;
floatpat = /[^0-9,\.\-]/g;
yearpat = /[^0-9]/g;
phonepat = /[^A-Z0-9\-\s\(\)]/;


stdErrorAppend = "These characters have been replaced with an asterisk (*) wherever they occur for easy correction. ";

hqcitymssg = "City Headquarters";
provmssg = "Non-US State/Province";
hqstateprovmssg = "State/Province Headquarters";
hqcountrymssg = "Country Headquarters";
webmssg = "Website Address";
empmssg = "# Employees";
comssg = "Company Name";
passmssg = "Passengers";
ddmssg = "Daily Departures";
fleetmssg = "Fleet";
destmssg = "Destinations";
addinfomssg = "Additional Info";
revmssg = "Gross Revenue";
q1mssg = "Q1";
q2mssg = "Q2";
q3mssg = "Q3";
q4mssg = "Q4";
symbmssg = "Stock Symbol";
exchmssg = "Exchange";
ownermssg = "Owners";
yearmssg = "Year Founded";
merchantmssg = "Accepting merchants";
othermssg = "Additional info";
othercardmssg = "Card Types: Other";
wwpropmssg = "Wordwide Properties";
wwroomsmssg = "Wordwide Rooms";
rprmssg = "Revenue Per Available Room";
adrmssg = "Average Daily Rate";
occmssg = "Occupancy";
wwlocmssg = "Wordlwide Locations";
fleetsmssg = "Fleet";
totalwwlocmssg = "Total Worldwide Locations";
totalfleetmssg = "Total Fleet";
srglobalfamssg = "Self-reported Global Sales (franchises and affiliates)";
srglobalolmssg = "Self-reported Global Sales (owned locations only)";
arcusbtnmssg = "ARC-verified U.S. Sales (BTN)";
arcustwmssg = "ARC-verified U.S. Sales (TW)";
natservemssg = "Nations served";
emssg = "Email Contact";
fnmssg = "First Name";
lnmssg = "Last Name";
phonemssg = "Phone Number";


function checkAdmin(){
	
	
	if (formObject.fname != null){
		if(!dataCheck(formObject.fname,badpat3,fnmssg,1,2,0)){
			return false;
		}
		if(!dataCheck(formObject.lname,badpat3,lnmssg,1,2,0)){
			return false;
		}			
		if(!dataCheck(formObject.phone,phonepat,phonemssg,1,10,0)){
			return false;
		}		
	}
	
	return true;
}


function checkProfile(){

	
	if (!superuser){
		if (!reqWidget('execs[]','executive')){
			return false;
		}
	}
		
	if(formObject.company){
		if(!dataCheck(formObject.company,badpat3,comssg,1,2,0)){
			return false;
		}
	}
	
	if(!dataCheck(formObject.yearfounded,yearpat,yearmssg,1,4,0)){
		return false;	
	}	
	
	if(!dataCheck(formObject.hqcity,badpat3,hqcitymssg,1,2,0)){
		return false;	
	}
	
	if(formObject.hqstateprov.options[0].selected == true){
		thisMssg = getError(3,hqstateprovmssg,0,null);
		alert(thisMssg); 		
		return false;	
	}
	
	if(formObject.hqcountry.options[0].selected == true){
		thisMssg = getError(3,hqcountrymssg,0,null);
		alert(thisMssg); 		
		return false;	
	}
	
	if(!webClean(formObject.website)){
		return false;
	}
	
	if(!dataCheck(formObject.employees,numpat,empmssg,1,1,1)){
		return false;	
	}	
	
	return true;

}


function checkFinancial(){

	if (superuser){
	
		if(!dataCheck(formObject.total_revenue,floatpat,revmssg,0,0,0)){
			return false;	
		}
	
		if(!dataCheck(formObject.q1,floatpat,q1mssg,0,0,0)){
			return false;	
		}
		
		if(!dataCheck(formObject.q2,floatpat,q2mssg,0,0,0)){
			return false;	
		}
		
		if(!dataCheck(formObject.q3,floatpat,q3mssg,0,0,0)){
			return false;	
		}
		
		if(!dataCheck(formObject.q4,floatpat,q4mssg,0,0,0)){
			return false;	
		}
	
	}
	
	if(!dataCheck(formObject.exchange1,stockpat,exchmssg,0,0,0)){
		return false;	
	}
	
	if(!dataCheck(formObject.symbol1,stockpat,symbmssg,0,0,0)){
		return false;	
	}

	if(!dataCheck(formObject.exchange2,stockpat,exchmssg,0,0,0)){
		return false;	
	}
	
	if(!dataCheck(formObject.symbol2,stockpat,symbmssg,0,0,0)){
		return false;	
	}

	if(!dataCheck(formObject.exchange3,stockpat,exchmssg,0,0,0)){
		return false;	
	}
	
	if(!dataCheck(formObject.symbol3,stockpat,symbmssg,0,0,0)){
		return false;	
	}
	return true;
	
}


function checkAirSector(){

	if (!superuser){
		if (!reqWidget('hubs[]','major hub')){
			return false;
		}
		if (!reqWidget('stations[]','major station')){
			return false;
		}
		if (!reqWidget('alliances[]','alliance')){
			return false;
		}
	}
	
	if(!dataCheck(formObject.passengers,floatpat,passmssg,1,1,1)){
		return false;	
	}
	if(!dataCheck(formObject.daily_departures,numpat,ddmssg,1,1,1)){
		return false;	
	}
	if(!dataCheck(formObject.fleet,numpat,fleetmssg,1,1,1)){
		return false;	
	}
	if(!dataCheck(formObject.total_destinations,numpat,destmssg,1,1,1)){
		return false;	
	}	
	if(!dataCheck(formObject.extrainfo,textpat,addinfomssg,1,0,0)){
		return false;	
	}	
	
	return true;
}

function checkPaymentSector(){

	if (!superuser){
		if (!reqWidget('networks[]','network')){
			return false;
		}
		cardtypeslength = formObject.elements["cardtypes[]"].length;
		
		checkedBoxes = 0;
		for (c = 0; c < cardtypeslength; c++){
			thisBoxState = formObject.elements["cardtypes[]"][c].checked;
			if (thisBoxState == true){
			checkedBoxes = 1;
			break
			}
		}
		if (!checkedBoxes){
		alert('Please indicate at least 1 card type issued');
		return false;
		}
	}
		
		
	if(!dataCheck(formObject.accepting_merchants,floatpat,merchantmssg,0,0,1)){
		return false;	
	}
	if(!dataCheck(formObject.extrainfo,textpat,othermssg,0,0,0)){
		return false;	
	}
	if(!dataCheck(formObject.cardtypesother,badpat2,othercardmssg,0,0,0)){
		return false;	
	}
	
	return true;
}


function checkTechSector(){
	
	if(!dataCheck(formObject.extrainfo,textpat,othermssg,0,0,0)){
		return false;
	}
	
	return true;
}

function checkLodgingSector(){

	if(!dataCheck(formObject.wwproperties,numpat2,wwpropmssg,0,0,1)){
		return false;	
	}
	if(!dataCheck(formObject.wwrooms,numpat2,wwroomsmssg,0,0,1)){
		return false;	
	}	
	if(!dataCheck(formObject.extrainfo,textpat,addinfomssg,0,0,0)){
		return false;	
	}		
	
	if (superuser){
		if(!dataCheck(formObject.avgdailyrate,floatpat,adrmssg,0,1,1)){
			return false;	
		}	
		if(!dataCheck(formObject.revperroom,floatpat,rprmssg,0,1,1)){
			return false;	
		}	
		if(!dataCheck(formObject.occupancy,floatpat,occmssg,0,1,0)){
			return false;	
		}	
	}
			
	return true;
}


function checkRentalSector(entryType){

	if (entryType == 's'){
		// subsidiary fields
		if(!dataCheck(formObject.wwlocations,numpat2,wwlocmssg,1,1,1)){
			return false;	
		}
		if(!dataCheck(formObject.fleet,numpat2,fleetsmssg,1,1,1)){
			return false;	
		}	
		if(!dataCheck(formObject.extrainfo,textpat,addinfomssg,0,0,0)){
			return false;	
		}		
	}else{
		// parent fields
		if(!dataCheck(formObject.totalwwlocations,numpat2,totalwwlocmssg,1,1,1)){
			return false;	
		}
		if(!dataCheck(formObject.totalfleet,numpat2,totalfleetmssg,1,1,1)){
			return false;	
		}	
		if(!dataCheck(formObject.extrainfo,textpat,addinfomssg,0,0,0)){
			return false;	
		}	
	}	
			
	return true;
}


function checkTMCSector(){
	
	if (superuser){
		if(!dataCheck(formObject.arcussalesbtn,floatpat,addinfomssg,0,1,1)){
			return false;	
		}		
		if(!dataCheck(formObject.arcussalestw,floatpat,adrmssg,0,1,1)){
			return false;	
		}	
	}
	
	if(!dataCheck(formObject.srglobalsalesfa,floatpat,srglobalfamssg,0,1,1)){
		return false;	
	}
		
	if(!dataCheck(formObject.srglobalsalesol,floatpat,srglobalolmssg,0,1,1)){
		return false;	
	}	
	
	if(!dataCheck(formObject.nations_served, numpat2,natservemssg,0,1,1)){
		return false;	
	}
		
	if(!dataCheck(formObject.extrainfo,textpat,othermssg,0,0,0)){
		return false;	
	}	
			
	return true;
}

function dataCheck(theElement,thePattern,theMssg,checkString,strMin,kComma){

		if (superuser){
		checkString = 0;
		}
		
	 	theString = theElement.value;
		
		if (kComma){
			killCommas(theElement);
		}
		
		if (checkString){	 	
			if (theString.length < strMin){	
				thisMssg = getError(2,theMssg,0);
				alert(thisMssg); 		
				return false;
			} 	
		}
			
		result = theString.match(thePattern);	
		if (result){	
			theElement.value = theString.replace(thePattern,'*');
			thisMssg = getError(1,theMssg,1);
			alert(thisMssg);		
		}
	
	return result != null ? false : true;
}

function getError(errType,errInc,errAppend){
	if(errType == 1){
	mssgString = "The data you entered for " + errInc + " appears to contain some problem characters. ";
		if (errAppend){
		mssgString = mssgString + ' ' + stdErrorAppend;
		}
		return mssgString;
	}else if (errType == 2){
		mssgString = "The data you entered for " + errInc + " appears to be empty or too short to be valid. Please check this field for errors then resubmit.";
		return mssgString;
	}else if (errType == 3){
		mssgString = "The selection you made for " + errInc + " is invalid.  Please enter a valid selection.";
		return mssgString;	
	}
}


function killCommas(theElement){
	strvalue = theElement.value;
	theElement.value = strvalue.replace(/,/g,'');
}

function webClean(theElement){
	strvalue = theElement.value;
	
	if (strvalue.length != 0){
		strMatches = webpat.exec(strvalue);

		domainroot = strMatches[2];
		
		tldresult = domainroot.match(webxpat);
		slash = strMatches[3] != null ? '/' : '';
		remainder = strMatches[4] != null ? strMatches[4] : '';
		
		theElement.value = strMatches[2] + slash + remainder;
		if (tldresult == null){
			alert("The website address you entered does not appear to be valid.  Please check your entry for errors.  Enter primary domains and subdomains only without directories.  If you do not have a website, please leave this field empty");	
			return false;
		}
		
	}else{
			if(!superuser){
			alert("A website address is required.  Please enter a website address.");	
			return false;	
			}
	}
	
	if(!dataCheck(theElement,webpat2,webmssg,0,0,0)){
		return false;	
	}
	
	return true;
		
}

function makeUC(theElement){
	strvalue = theElement.value;
	theElement.value = strvalue.toUpperCase();
}


function showhide(divId,mssg){
	if (mssg){
		if (document.sdform.listed.checked == true){
		radioObj = document.sdform.elements.dedicated_page;
		radioObj[1].checked = true;
 		alert(mssg);
		}
	}else{
		theDivObject =  eval("document.getElementById('"+divId+"')");
		divStyle = theDivObject.style.display; 
		theDivObject.style.display = (divStyle == 'block') ? 'none' : 'block';
		if (divId == 'entryprefs'){
		ok2check = (divStyle == 'block') ? 0 : 1;
		}	
		if (divId == "stockdiv"){
		theOwnersObject = document.getElementById('ownersdiv');
		ownersStyle = theOwnersObject.style.display; 
		theOwnersObject.style.display = (ownersStyle == 'block') ? 'none' : 'block';
		}
	}
	
}

function toggleBox(theCheckbox){
theCheckbox.value = theCheckbox.checked ? 1 : 0;
}


function setParentPrefs(theCheckbox,theIndex){
newPrefs = theCheckbox.value + '|' + (theCheckbox.checked ? 1 : 0);
checkboxArray = new Object;
checkboxArray = document.forms['parentprefs'].elements['display_on_parent[]'];
checkboxArray[theIndex].value = newPrefs;
}

lastTabIda = 1;
lastTabIdb = 1;

function cotab(tabId,subId){

lastTabIdNum = eval('lastTabId' + subId);


if (subId == 'a'){
lastTabIda = tabId;
}else{
lastTabIdb = tabId;
}


if (tabId != lastTabIdNum){
lastdivObject = eval("document.getElementById('sectordiv" + subId + lastTabIdNum + "')");
lasttabObject = eval("document.getElementById('subtab" + subId + lastTabIdNum + "')");
lastlinkObject = eval("document.getElementById('subtablink" + subId + lastTabIdNum + "')");

divObject = eval("document.getElementById('sectordiv" + subId + tabId + "')");
tabObject = eval("document.getElementById('subtab" + subId + tabId + "')");
linkObject = eval("document.getElementById('subtablink" + subId + tabId + "')");

lastdivObject.style.display = 'none';
divObject.style.display = 'block';
lasttabObject.className = 'subtab';
tabObject.className = 'subtabon';
lastlinkObject.className = 'subtablink';
linkObject.className = 'subtablinkon';
}



}

infoHead = '<div style="float:left;"><b style="color: #6528CB;">Additional Info:</b> </div><div class="closebox"><a href="Javascript:closeInfo();" style="text-decoration: none; color: #6528CB;">X</a></div><br><br>';
infoHead2 = '<div style="float:left;"><b style="color: #6528CB;">Owners:</b> </div><div class="closebox"><a href="Javascript:closeInfo();" style="text-decoration: none; color: #6528CB;">X</a></div><br><br>';

function infoPop(theInfo,xid){
	
mssgBox = new Object();
infoPos = new Object();
mssgBox = document.getElementById('infobox');

mssgBox.innerHTML = (xid != '_fin' ? infoHead : infoHead2) + theInfo;

//boxHeight = mssgBox.offsetParent;
//alert(boxHeight);

xinfoId = xid ? 'xinfo' + xid : 'xinfo';

infoPos = document.getElementById(xinfoId);

mssgBox.style.left = (infoPos.offsetLeft - 150) + 'px';
mssgBox.style.top = (infoPos.offsetTop - 30) + 'px';

mssgBox.style.visibility = 'visible';
mssgBox.style.display = 'block';
}

function closeInfo(){
document.getElementById('infobox').style.visibility = 'hidden';
document.getElementById('infobox').style.display = 'none';
}

function notice(subsidCo,parentCo,evt){
divObj = new Object;
divObj = document.getElementById("captiondiv");

cap = 'This link takes you to the ' + subsidCo + ' parent company page, <b>' + parentCo + '</b>';
divObj.innerHTML = cap;
	//if (navigator.userAgent.indexOf('Mac') == -1){
	ytop = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	divObj.style.top = (evt.clientY + (ytop-70)) + "px"; 
	boxleft = (evt.clientX - 300) < 0 ? (evt.clientX + 0) : (evt.clientX - 300);
	divObj.style.left = boxleft + "px"; 
	
	/*
	//}else{
	ytop = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	divObj.style.top = (evt.clientY + (ytop-70)) + "px"; 
	boxleft = (evt.clientX - 300) < 0 ? (evt.clientX + 0) : (evt.clientX - 300);
	divObj.style.left = boxleft + "px"; 
	}
	*/
	
divObj.style.visibility = "visible";

}

function hideCaption(){
divObj = new Object;
divObj = document.getElementById("captiondiv");
divObj.style.visibility = "hidden";
}

function reqWidget(listName,mssg){
	badresult = 0;
	if(document.forms["sdform"].elements[listName]){
		if(document.forms["sdform"].elements[listName].length <= 1){		
			if (document.forms["sdform"].elements[listName].length == 0){
			badresult = 1;
			}else{
				if(document.forms["sdform"].elements[listName].options[0].value.indexOf('Click + ADD to enter') != -1){
				badresult = 1;
				}
			}
		}
	}
	if (badresult){
		alert('Please enter at least 1 ' + mssg);
		return false;
	}else{
		return true;
	}
}


function listmove(theListName,theListPrefix,direction){

	theListObj = eval("document.forms['sdform'].elements['" + theListName + "']");
	listObjLength = theListObj.length;
	
	

			for(i = 0; i<=listObjLength; i++){
				if (theListObj.options[i].selected){	
					selIndex = i;
					break;
				}
			}



	selItem = new Object();
	swapItem = new Object();
	swapItemTemp = new Object();
	selItem = theListObj.options[selIndex];
	nextItem = selIndex+1;
	prevItem = selIndex-1;


		if (listObjLength > 0){
			if (selIndex == 0 && !direction){
				swapItem = theListObj.options[nextItem];
			}else if (selIndex == listObjLength-1 && direction){
				swapItem = theListObj.options[prevItem];
			}else{
				swapItem = direction ? theListObj.options[prevItem] : theListObj.options[nextItem];		
			}
			
			//alert(selItem.text + ' ' + swapItem.text);
			swapItemTemp.value = swapItem.value;
			swapItemTemp.text = swapItem.text;
			swapItem.value = selItem.value;
			swapItem.text = selItem.text;
			selItem.value = swapItemTemp.value;
			selItem.text = swapItemTemp.text;
		
			manageList(theListObj,theListPrefix,direction);
			
		}

}