$(document).ready(function() {
	
	fixExplorer6Height();
	
	$("li.dropDown").mouseenter(function() {
		
		if ($(this).find("ul").css("display") == "none") {
			$(this).find("ul").slideDown("fast");
		}
			
	});
	
	$("li.dropDown").mouseleave(function() {
		
		if ($(this).find("ul").css("display") == "block") {
			$(this).find("ul").slideUp();
		}
		
	});
	
});

function fixExplorer6Height() {
	
	// Needless scrollbar in IE6 on pages that do not have much content. This is because of the background image.
	
	if ($.browser.msie && $.browser.version == "6.0") {

		$("#pageBackground").height($(window).height());

		$(window).resize(function() {
			$("#pageBackground").height($(window).height());
		});

	}
	
}

function positionHomePageContent() {
	var yViewPort = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
	var newMarginTop = eval(yViewPort * 0.5 - 125);
	newMarginTop = (newMarginTop < 165) ? 165 : newMarginTop;
	$("#pageContent").css("margin-top",newMarginTop+"px");
}

var poppedWindow = null;

function popupWindow( pURL, pWindowName, pWindowFeatures ){
    closePoppedWindow();
    poppedWindow = window.open( "", pWindowName, pWindowFeatures  );
    poppedWindow.location.href = pURL;
    poppedWindow.focus();
}

function popup( pURL ){
    popupWindow( pURL, "popup", "left=50,top=50,status=yes,dependent=yes,scrollbars=auto,resizable=1,width=780,height=400" );
}

function closePoppedWindow() {
    if ( navigator.appName != "Microsoft Internet Explorer" || parseInt( navigator.appVersion ) >= 4 ) {
        if( poppedWindow != null ) {
            if( !poppedWindow.closed ) {
                poppedWindow.close();
            }
        }
    }
}

function clearAll() {
	document.getElementById("states_of_interest").value = "";
}

function findObject( pElementId ) {
    if ( document.getElementById ) {
        return document.getElementById( pElementId );
    } else if ( document.all ) {
        return document.all[ pElementId ];
    } else {
        return { style: {} };
    }
}

function findObjectOrNull( pElementId ) {
    if ( document.getElementById ) {
        return document.getElementById( pElementId );
    } else if ( document.all ) {
        return document.all[ pElementId ];
    } else {
        return null;
    }
}


function toggleStateProvince( pPrefix ) {
    //patch to avoid js errors on bne,s gcu form
    if( document.getElementById( pPrefix + 'Country' ) == null ){
      return;
    }

    var wCountry = findObject( pPrefix + 'Country' ).value;
    var wStateProvText = findObject( pPrefix + 'StateProvince' );
    var wStateProvCode = findObject ( pPrefix + 'StateProvinceCode');        
    var wState = findObject( pPrefix + 'State' );    
    var wProvince = findObject( pPrefix + 'Province' );    
    wStateProvCode.value = '';
    if ( wCountry == 'US' ) {
        wState.style.display = 'inline';
        wProvince.style.display = 'none';
        wStateProvText.style.display = 'none';
        wStateProvText.value = '';
        wStateProvCode.style.display = 'none';
        wStateProvCode.value = wState.value;    
        populateStateProvinceText(wState,'main');   
    } else if ( wCountry == 'CA' ) {
        wState.style.display = 'none';
        wProvince.style.display = 'inline';        
        wStateProvText.style.display = 'none';
        wStateProvText.value = '';
        wStateProvCode.style.display = 'none';
        wStateProvCode.value = wProvince.value;
        populateStateProvinceText(wProvince,'main'); 
    } else {
        wState.style.display = 'none';
        wProvince.style.display = 'none';
        wStateProvCode.style.display = 'none';
        wStateProvText.style.display = 'inline';
    }    
}

function populateStateProvinceText( pSelect, pPrefix ) {
    findObject( pPrefix + 'StateProvinceCode' ).value = pSelect.value;
}

function setQuestionCodeValue(pSelect, pTable, pField) {

  var wSelectedCodeValue = findObject( pSelect ).value;
  var wTable = findObject( pTable );
  var wField = findObject( pField ); 
  for (var i=0; i<wTable.length; i++) {
    if (wTable[i].name == wSelectedCodeValue) {
      wField.value = wTable[i].value
      return;
    }
  }
  
}

function addPhone( pSufix ) {
    var wPhonesDiv = findObject( 'companyPhones' ).innerHTML;
    var wPhoneLabel = new String( findObject( 'phone_label0' ).innerHTML );
    wPhoneLabel = wPhoneLabel.substr( 0, wPhoneLabel.length - 1 );  
    wPhonesDiv += '<br />\n' 
    wPhonesDiv += '<label for="phone_number' + pSufix + '">' + wPhoneLabel + '</label>\n';
    wPhonesDiv += '<input id="phone_number' + pSufix + '" maxlength="12" name="Client.Phones.Phone[' + pSufix + '].PhoneNumber" size="30" tabindex="7" type="text"/>\n';
    wPhonesDiv += '<label class="extension" for="extension' + pSufix + '">Extension</label>\n';
    wPhonesDiv += '<input id="extension' + pSufix + '" maxlength="20" name="Client.Phones.Phone[' + pSufix + '].Extension" size="10" tabindex="8" type="text"/>\n';
    wPhonesDiv += '<button id="addPhone' + pSufix + '" onclick="addPhone( ' + ( Number( pSufix ) + 1 ) + ' )" type="button">' + findObject( 'addPhone0' ).innerHTML + '</button>\n';
    findObject( 'companyPhones' ).innerHTML = wPhonesDiv;
    findObject( 'addPhone' + ( Number( pSufix ) - 1 ) ).style.display = 'none';
}


function addPhoneWithFormat( pSufix, pPhoneCode ) {
    var wPhonesDiv = findObject( 'companyPhones' ).innerHTML;
    var wPhoneLabel = new String( findObject( 'phone_label2' ).innerHTML );
    
    wPhoneLabel = wPhoneLabel.substr( 0, wPhoneLabel.length );  
    wPhonesDiv += '<p style="width: 450px;">';
    wPhonesDiv += '    <label id="phone_label' + pSufix + '" for="phone_number' + pSufix + '">' + wPhoneLabel + '</label>';
    wPhonesDiv += '    <input class="countryCode" id="phoneCodeNumber' + pSufix + '" name="Client.Phones.Phone[' + pSufix + '].CountryCodeNumber" size="2" value="' + pPhoneCode + '" DISABLED="true" style="color:#646464;">'; 
    wPhonesDiv += '    <input class="phoneNumber2"  id="phone_number' + pSufix + '" name="Client.Phones.Phone[' + pSufix + '].PhoneNumber" size="30" maxlength="30" tabindex="31" type="text"/>';
    wPhonesDiv += '    <label class="second" for="extension' + pSufix + '">Extension</label>';
    wPhonesDiv += '    <input class="extension" id="extension' + pSufix + '" name="Client.Phones.Phone[' + pSufix + '].Extension" size="10" tabindex="31" maxlength="30" type="text"/>';
    wPhonesDiv += '</p>';
    wPhonesDiv += '<p class="pad135" style="width: 315px;">';
    wPhonesDiv += '    <a href="javascript:addPhoneWithFormat( ' + (  Number( pSufix )  + 1 ) + ',' + pPhoneCode + ' )" tabindex="40" id="addPhone' + pSufix + '" class="smallButton">Add Phone</a>';
    wPhonesDiv += '    <input name="Client.Phones.Phone[' + Number( pSufix ) + '].TypeCode" type="hidden" value="OFFICE"/>';
    wPhonesDiv += '</p>';                         
    findObject( 'companyPhones' ).innerHTML = wPhonesDiv;
    findObject( 'addPhone' + ( ( pSufix - 1 ) ) ).style.display = 'none';
}

function referredByOther() {
  if(findObject('ReferredByCbo').value == 'OTHER'){
    findObject('ReferredByCode').style.display = 'inline'; 
  }else{
    findObject('ReferredByCode').style.display = 'none';
    findObject('ReferredByCode').value = '';  
  }
}

function targetWin(anchor) {
window.open(anchor.href);
return false;
}

function checkMaxLength(tag,size) {
  var child =   findObject('area_size_label');
  if (child != null)  {
    if (tag.value.length > 1)
      child.childNodes[0].nodeValue = 'Length: ' + tag.value.length+ ' characters (' + size + ' Max.)';
      else
          child.childNodes[0].nodeValue = 'Length: ' + tag.value.length+ ' character (' + size + ' Max.)';
  }
}

function selectSearchBoxIfSearchWasDone() {
  url = new String( location.href );
  if ( url.indexOf( 'main.search' ) >= 0 ) {
    findObject( 'search1' ).select();
  }
}

function sendFreeRFQ( pRfqNumber, pNumberOfRecords ) {
  for (i = 1; i <= pNumberOfRecords; i++ ) {
    findObject( 'item' + i ).value = '';
  }
  findObject( 'item' + pRfqNumber ).value = 1;
  findObject( 'SubmitFreeRfq' ).submit();
}

function checkedRFQ() {
  wChecked = false;
  wInputs = document.getElementsByTagName( "input" );
  for( i = 0; i < wInputs.length; i++ ) {
    wId = new String( wInputs[i].id );
    if ( wInputs[i].type == 'checkbox' ) {
      if ( wId.indexOf( 'item' ) >= 0 ) {
        if ( wInputs[i].checked ) {
          wChecked = true;
          break;
        }
      }
    }
  }
  if ( !wChecked ) {
    findObject( 'NoItemSelected' ).style.display = 'block';
  } else {
    findObject( 'NoItemSelected' ).style.display = 'none';
    if ( findObject( 'SubmitQuote' ) ) {
      findObject( 'SubmitQuote' ).submit();
    } else {
      findObject( 'SubmitRfq' ).submit();
    }
  }
}

function submitAction(pForm,controller) {
  var forms = document.forms;
  var form = null;
  for (var i = 0; i < forms.length; i++) {
    if (forms[i].id == pForm) {
      form = forms[i];  
    }
  }
  if ( controller != null ) {
    form.action=controller;
  }
  form.target=window.name;
  form.submit();
}

function closeAndReloadOpener() {
  var wReferer = new String( window.opener.location.href );
  var wStart = wReferer.indexOf( 'SearchRequest.ResultSetId=' );
  if ( wStart > -1 ) {
    var wEnd = wReferer.indexOf( '&', wStart );
    if ( wEnd <= 0 ) {
      wEnd = wReferer.indexOf( '/', wStart );
    }
    if ( wEnd <= 0 ) {
      wReferer = wReferer.substring( 0, wStart - 1 );
    } else {
      wReferer = wReferer.substring( 0, wStart - 1 ) + wReferer.substring( wEnd );
    }
  }
  wStart = wReferer.indexOf( 'SearchRequest.QueryCriteria.PageNumber=' );
  if ( wStart > -1 ) {
    var wEnd = wReferer.indexOf( '&', wStart );
    if ( wEnd <= 0 ) {
      wEnd = wReferer.indexOf( '/', wStart );
    }
    if ( wEnd <= 0 ) {
      wReferer = wReferer.substring( 0, wStart - 1 );
    } else {
      wReferer = wReferer.substring( 0, wStart - 1 ) + wReferer.substring( wEnd );
    }
  }
  window.opener.location.replace( wReferer );
  window.close();
}

function switchSections( sectionToHide, sectionToShow, buttonToHide, buttonToShow ) {
  var wSectionToHide = document.getElementById( sectionToHide );
  var wSectionToShow = document.getElementById( sectionToShow );  
  var wButtonToHide = document.getElementById( buttonToHide );
  var wButtonToShow = document.getElementById( buttonToShow );
    
  wSectionToHide.style.display = "none";
  wButtonToHide.style.display = "none";
  wSectionToShow.style.display = "";  
  wButtonToShow.style.display = "";   
}

function hintBox(pElementId,pHintText,e)
  {
    var posx  = 0;
    var posy  = 0;
    if(!e) var e  = window.event;
    if(e.pageX || e.pageY) {
      posx  = e.pageX;
      posy  = e.pageY;
    } else if(e.clientX || e.clientY) {
      posx = e.clientX + document.documentElement.scrollLeft;
      posy = e.clientY + document.documentElement.scrollTop;
    }
    var state   = document.getElementById(pElementId).style.display;
    if(document.getElementById) {
      if (state=='none') {  
        state = 'inline';
      } else  {
         state = 'none';
      }
      document.getElementById(pElementId).innerHTML=pHintText;
      document.getElementById(pElementId).style.top=(posy - 30) + 'px';
      document.getElementById(pElementId).style.left=(posx - 250) + 'px';
      document.getElementById(pElementId).style.display=state;
    }
}

function hintBox(pElementId,pHintText,pTop,pLeft,e)
  {
    
    var state   = document.getElementById(pElementId).style.display;
    if(document.getElementById) {
      if (state=='none') {  
        state = 'inline';
				document.getElementById(pElementId).innerHTML=pHintText;
				document.getElementById(pElementId).style.top= pTop + 'px';
				document.getElementById(pElementId).style.left=pLeft + 'px';
				document.getElementById(pElementId).style.display=state;
      } else  {
         state = 'none';
         document.getElementById(pElementId).style.display=state;
      }
    }
}

function setFocusOnElement ( pElementId ) {
	if ( document.getElementById( pElementId ) ) {
		if ( document.getElementById( pElementId ).disabled == false ) {
			document.getElementById( pElementId ).focus();
		} 
	}
}

    function disableForm( pFormId ) {
    
        var wForm = document.getElementById( pFormId );
        
        // Disable all <input> fields
        wInputs = document.getElementsByTagName( 'input' );
        
        for( i = 0; i < wInputs.length; i++ ) {
            wInputs[i].style.backgroundColor='#DFDDE2';
            wInputs[i].disabled='disabled';
        }   
        
        // Disable all <button> fields
        wButtons = document.getElementsByTagName( 'button' );
        
        for( i = 0; i < wButtons.length; i++ ) {
            wButtons[i].disabled='disabled';
        } 
        
        // Disable all <select> fields
        wSelects = document.getElementsByTagName( 'select' );
        
        for( i = 0; i < wSelects.length; i++ ) {
        	wSelects[i].style.backgroundColor='#DFDDE2';
            wSelects[i].disabled='disabled';
        } 
    }
    
 // Display Phone Code value associated to a country code
function displayPhoneCodeValue(phoneCodeNumbers,countryCode,phoneCodeNumber) {

   var st=document.getElementById(phoneCodeNumbers).value;
   var bar = st.split("|");
   for(var i = 0;i<bar.length;i++){
	if(countryCode==bar[i].match(countryCode)){
	   var codeNum = bar[i].split("=");
           document.getElementById(phoneCodeNumber).value=codeNum[1];	
	   break;
	}
   }
}

 // Get Phone Code value associated to a country code
function getPhoneCodeValue(phoneCodeNumbers,countryCode) {

   var st=document.getElementById(phoneCodeNumbers).value;
   var countryCode=document.getElementById(countryCode).value;
   var bar = st.split("|");
   for(var i = 0;i<bar.length;i++){
	if(countryCode==bar[i].match(countryCode)){
	   var codeNum = bar[i].split("=");
       
	   return codeNum[1];
	}
   }
   
   return "";
}


// Get id attribute from the selected option
function getOptionId(pObj) {

    var optionsList = document.getElementById(pObj);
    var selectedIndex = optionsList.selectedIndex;
    var idValue = optionsList.options[selectedIndex].id;
    
    return idValue;
   
}

function displayPhoneCode(phoneCodeNumbers,countryCode,phoneCodeNumber) {
   var st=document.getElementById(phoneCodeNumbers).value;
   var countryCode=document.getElementById(countryCode).value;
   var bar = st.split("|");
   for(var i = 0;i<bar.length;i++){
	if(countryCode==bar[i].match(countryCode)){
	   var codeNum = bar[i].split("=");
           document.getElementById(phoneCodeNumber).value=codeNum[1];	
	   break;
	}
   }
}
 function clearField( pId, pCompare ) {
	var wObj = 	document.getElementById( pId );
	if ( wObj.value == pCompare ) {
		wObj.value='';
	}
}

function displayPlanInfo ( pId, pCommonName, pMaxId ) {
	// Used in the Pricing page to show/hide pricing options
	var wElement = document.getElementById(pId);
	if ( wElement != null ) {
		if ( wElement.style.display == 'block' ) {
			wElement.style.display = 'none';
			var wLink = document.getElementById(pId+'Link');
			if ( wLink != null ) {
				wLink.style.backgroundImage = 'url(/cgi/en/img/bullets-cross-hair.gif)';
				wLink.style.fontWeight = 'normal';
				wLink.style.color = '';
			}
		}
		else {
			for ( x = 1; x < (pMaxId+1); x++ ) {
				var wElement2 = document.getElementById( pCommonName + x );
					//window.alert( wElement2);
				if ( wElement2 != null ) {
					wElement2.style.display = 'none';
					var wLink2 = document.getElementById(pCommonName + x + 'Link');
					if ( wLink2 != null ) {
						wLink2.style.backgroundImage = 'url(/cgi/en/img/bullets-cross-hair.gif)';
						wLink2.style.fontWeight = 'normal';
						wLink2.style.color = '';
					}
				}
			}
			wElement.style.display = 'block';
			var wLink = document.getElementById(pId+'Link');
			if ( wLink != null ) {
				wLink.style.backgroundImage = 'url(/cgi/en/img/bullets-cross-hair-minus.gif)';
				wLink.style.fontWeight = 'bold';
				wLink.style.color = '#CC0000';
			}
		}
	} 
}

function displaySignUpPlans ( pType, pTime, pAlternateInputId ) {
	var wTimeArray = ['Monthly', 'Quarterly', 'Yearly'];
	var wInputSuffix = "Plan";
	var wLinkSuffix = "Link";
	
	for ( x = 0; x < wTimeArray.length; x++ ) {
		if ( pTime == wTimeArray[x] ) {
			// Show info
			var wSection = document.getElementById( pType + wTimeArray[x]);
			if ( wSection ) {  wSection.style.display ='block'; }
			
			// Set Radio to checked
			var wRadio = document.getElementById( pType + wTimeArray[x] + wInputSuffix );
			if ( pAlternateInputId ) { wRadio = document.getElementById( pAlternateInputId ); }
			if ( wRadio ) {  wRadio.checked = true; }
			
			// Set Link to active
			var wLink = document.getElementById( pType + wTimeArray[x] + wLinkSuffix );
			if ( wLink ) { wLink.style.fontWeight = 'bold'; }
			
			//Set Upgrade Pricing Input
			var wFeatureCode = document.getElementById( 'FeatureCode' );
			if ( wFeatureCode ) {
				var wNewItemCode = document.getElementById( 'NewItemCode' );
				if ( wNewItemCode ) { wNewItemCode.value = wFeatureCode.value + '_' + wTimeArray[x].toUpperCase(); }
			}
			
		} else {
			// Hide info	
			var wSection = document.getElementById( pType + wTimeArray[x] );
			if ( wSection ) {  wSection.style.display ='none'; }
			
			// Set Link to not(active)
			var wLink = document.getElementById( pType + wTimeArray[x] + wLinkSuffix );
			if ( wLink ) { wLink.style.fontWeight = 'normal'; }			
		}
	}
	
}



function showPreviousSelectedFrequencyCode(pPrefix, pDefaultFrequencyCode, pSuffix ) {
	var wTimeArray = ['Monthly', 'Quarterly', 'Yearly'];
	var wFrequencyCode = pDefaultFrequencyCode;
	var wTerm = '';
	
	if(wFrequencyCode =='MONTHLY') {
    	wTerm = 'Monthly';
    } else if(wFrequencyCode =='QUARTERLY') {
        wTerm = 'Quarterly';
    } else if(wFrequencyCode =='YEARLY') {
        wTerm = 'Yearly';
    }

  	if(wTerm.length > 0 ) {    	
        var wInput = document.getElementById( pPrefix + wTerm + pSuffix );
        if ( wInput ) {
        	wInput.checked = true;
        }
        displaySignUpPlans( pPrefix, wTerm );
    } else {
		for ( x = 0; x < wTimeArray.length; x++ ) {
			var wInput = document.getElementById( pPrefix + wTimeArray[x] + pSuffix );
			//window.alert(wTimeArray[x] + ' - Checked: ' +  wInput.checked );
			if ( wInput ) {
				if ( wInput.checked == true ) {
					displaySignUpPlans( pPrefix, wTimeArray[x] );
				}
			}
		}    
    }
}

function showPreviousSelectedFrequencyCodeForUpdate( pPrefix, pDefaultFrequencyCode ) {
	var wTimeArray = ['Monthly', 'Quarterly', 'Yearly'];
	var wFrequencyCode = pDefaultFrequencyCode;
	var wTerm = '';
	
	var wIndex = wFrequencyCode.lastIndexOf( '_' );
	if ( wIndex >= 0 && (wIndex + 1) < wFrequencyCode.length ) {
		wFrequencyCode = wFrequencyCode.substr( wIndex + 1 );
	}

	
	if(wFrequencyCode =='QUARTERLY') {
        wTerm = 'Quarterly';
    } else if(wFrequencyCode =='YEARLY') {
        wTerm = 'Yearly';
    } else {
    	wTerm = 'Monthly';
    	wFrequencyCode = 'MONTHLY';
    }

  	if(wTerm.length > 0 ) {    	
        var wInput = document.getElementById( wFrequencyCode );
        if ( wInput ) {
        	wInput.checked = true;
        }
        displaySignUpPlans(pPrefix, wTerm);
    } else {
		for ( x = 0; x < wTimeArray.length; x++ ) {
			var wInput = document.getElementById( wFrequencyCode );
			//window.alert(wTimeArray[x] + ' - Checked: ' +  wInput.checked );
			if ( wInput ) {
				if ( wInput.checked == true ) {
					displaySignUpPlans( pPrefix, wTimeArray[x] );
				}
			}
		}    
    }
  
}


function loadContactList (pStatus) {
	document.getElementById('statusCode').value = pStatus;
	submitAction( 'Filter', '/cgi/en/contact-admin.admin.list');
}

function uncheckAll(pForm, pFieldName) {
	var wx = document.getElementById(pForm).elements.length;
	for ( var x = 0; x < wx; x++ ) {
		if ( ( document.getElementById(pForm).elements[x].name == pFieldName  ) && ( document.getElementById(pForm).elements[x].checked == 1) ) {
				if ( document.getElementById(pForm).elements[x].value == 'ALL' ) {
					document.getElementById(pForm).elements[x].checked = 0;
				}
		}
	}
}

function uncheckAllCat(pForm) {
	var wx = document.getElementById(pForm).elements.length;
	for ( var x = 0 ; x < wx ; x++ ) {
				if ( document.getElementById(pForm).elements[x].value != 'ALL' ) {
					document.getElementById(pForm).elements[x].checked = 0;
				}
	}
}

function uncheckAllCat(pForm, pFieldName) {
	var wx = document.getElementById(pForm).elements.length;
	for ( var x = 0; x < wx; x++ ) {
		if ( ( document.getElementById(pForm).elements[x].name == pFieldName  ) && ( document.getElementById(pForm).elements[x].checked == 1) ) {
				if ( document.getElementById(pForm).elements[x].value != 'ALL' ) {
					document.getElementById(pForm).elements[x].checked = 0;
				}
		}
	}
}

function selectAll(pFormId) {
	if ( document.getElementById(pFormId) != null ) {
		var wForm = document.getElementById(pFormId);
		for ( var x=0; x < wForm.length; x++ ) {
			if ( wForm[x].type == 'checkbox' ) {
				wForm[x].checked='checked';
			}
		}
	}
}

function selectNone(pFormId) {
	if ( document.getElementById(pFormId) != null ) {
		var wForm = document.getElementById(pFormId);
		for ( var x=0; x < wForm.length; x++ ) {
			if ( wForm[x].type == 'checkbox' ) {
				wForm[x].checked=false;
			}
		}
	}
}

function checkOrUncheck(pFormId, pMainCheckboxId) {
	var wMainCheckBox = document.getElementById( pMainCheckboxId );
	if ( wMainCheckBox ) {
		if ( wMainCheckBox.checked == true ) {
			selectNone( pFormId );
			wMainCheckBox.checked = true;
		} else {
			selectNone( pFormId );
		}
	}
}

function checkOrUncheckBackup(pFormId, pMainCheckboxId) {
	// proper fix to the checkOrUncheck solution above
	var wMainCheckBox = document.getElementById( pMainCheckboxId );
	if ( wMainCheckBox ) {
		if ( wMainCheckBox.checked == true ) {
			selectAll( pFormId );
		} else {
			selectNone( pFormId );
		}
	}
}

var win= null;
function surveyPopUp(mypage,myname,w,h,scroll){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
	settings +='resizable=yes';
	win=window.open(mypage,myname,settings);
}

function submitFormOnEnter(pFormId, pController, e) {

  if (!e) {
    var e = window.event;
  }

  var code;
  if (e.keyCode) {
    code = e.keyCode;
  }	else if (e.which) {
    code = e.which;
  }

  if (code == 13) {
    var form = null;
    form = document.getElementById(pFormId);

    if ( pController != null ) {
      form.action=pController;
    }
    form.target=window.name;
    form.submit();
  }
}

function openNewWindow(pUrl) {
   var wUrl = trim( pUrl );
  if ( wUrl.length >= 8 ) {
    if ( wUrl.substr(0, 7).toUpperCase() == new String("http:\/\/").toUpperCase() || wUrl.substr(0, 8).toUpperCase() == new String("https:\/\/").toUpperCase() ) {
      window.open(wUrl, "win" ,"toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width=560, height=400, left=0, top=0");
    } else {
      window.open( "http:\/\/" + wUrl,"win",'toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width=560, height=400, left=0, top=0');
    }
  } else {
    window.open( "http:\/\/" + wUrl,"win",'toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width=560, height=400, left=0, top=0');
  }
}

function trim(s) {
  while ((s.substring(0,1) == ' '))
  {
    s = s.substring(1,s.length);
  }

  while ((s.substring(s.length-1,s.length) == ' '))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function setRating(pId, pLinkBaseId, pRating, pMaxRating) {
	// Set hidden element with value
	document.getElementById( pId ).value = pRating;
	clearStars( pLinkBaseId, pRating, pMaxRating);
}

function clearStars(pLinkBaseId, pRating, pMaxRating) {
	for ( x = 1; x <= pMaxRating; x++ ){
		var wLink = document.getElementById( pLinkBaseId + '_' + x );
		wLink.style.background = "";
		wLink.style.zIndex = "";
		wLink.style.left = "";
		wLink.style.width = "";
	}

	var wClickedLink = document.getElementById(pLinkBaseId + '_' + pRating);
	if ( wClickedLink ) {
		if ( pRating > 0 ) {
			wClickedLink.style.background = "url(/cgi/en/img/stars.gif) " + "-" + ((pMaxRating - pRating) * 12) + "px 0";
			wClickedLink.style.zIndex = "1";
			wClickedLink.style.left = "12px";
			wClickedLink.style.width = (pRating * 12) + "px";
		}
		document.getElementById( pLinkBaseId + '_text' ).value = wClickedLink.innerHTML;
	} else {
		document.getElementById( pLinkBaseId + '_text' ).value = "";
	}
}

function setStars(pId, pLinkBaseId, pMaxRating) {
	var wRating = document.getElementById( pId ).value;
	clearStars( pLinkBaseId, wRating, pMaxRating);
}

function countAreaChars(areaId,counter,limit) {
  var areaName = document.getElementById( areaId );
  if (areaName.value.length>limit){
    areaName.value=areaName.value.substring(0,limit);
  }else{
    counter.value = limit - areaName.value.length;
  }
}

function gup(name)
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function changeCssClass(pElementId, pClass) {
	 var tag = document.getElementById( pElementId );
	 tag.className= pClass;
}

function showPopup(id, pSector) {
		var wCurrentDiv = document.getElementById(pSector);
		var wDivs = document.getElementsByTagName("div");
	
		for (var i = 0; i < wDivs.length; i++) { 
		
			if (wDivs[i].className == "selectSelectors") { 
				wDivs[i].style.display = "none";
			}
			
		}
		
		wCurrentDiv.style.display = "block";
		document.getElementById('labelSelected').innerHTML = document.getElementById(id).innerHTML;
		document.getElementById('valueSelected').value = pSector;
}

function closeIt(pElementId) {
    var wElement = document.getElementById(pElementId);
    if ( wElement != null ) {
       wElement.style.display="none";
    } else {
     if (document.getElementById('flashMap')) {
         document.getElementById('flashMap').style.display = "none";
     }
    }

    //Clear Error Message
    if (document.getElementById(pElementId + '_error')) {
    	document.getElementById(pElementId + '_error').style.display = 'none';
    }
    
    if (pElementId != 'flashMap' && wElement != null) {
	    //Clears the industry and sub-industry selection
	    document.getElementById('valueSelectedSub').value="";
	    document.getElementById('valueSelected').value="";
	    
	    var wRadios = document.getElementsByTagName('input');
	    for ( var i=0;i<wRadios.length;i++) {
	    	var wRadio_name = wRadios[i].name;
                //gb
	    	if( wRadio_name.indexOf('Client.AddInfo.TmpIndustry') != -1 && wRadios[i].checked ){
	        	wRadios[i].checked = false;
	    	}
                //bne
                if( wRadio_name.indexOf('CompanyLead.TmpIndustry') != -1 && wRadios[i].checked ){
	        	wRadios[i].checked = false;
	    	}
	    }
	}
}

function closeSectors(pElementId,pSectorsId,pChangeId) {
    var wSectorsId = document.getElementById(pSectorsId);
    var wElementId = document.getElementById(pElementId);
    var wChangeId = document.getElementById(pChangeId);
    if (wSectorsId != null) {
        wSectorsId.style.display="none";
    }
    if (wElementId != null) {
        wElementId.style.display="none";
    }
    if (wChangeId != null) {
        wChangeId.style.display="block";
    }
}
function openSectors(pSectorsId,pChangeId, pTempName) {
	document.getElementById(pSectorsId).style.display="block";
	document.getElementById(pChangeId).style.display="none";
	document.getElementById('showSelectedSub').style.display="none";
	
	//Clears the industry and sub-industry selection
	document.getElementById('valueSelectedSub').value="";
	document.getElementById('valueSelected').value="";
	
	var wRadios = document.getElementsByTagName('input');
    for (var i=0;i<wRadios.length;i++) {
    	var wRadio_name = wRadios[i].name;    	
    	if (wRadio_name.indexOf(pTempName) != -1 && wRadios[i].checked) {
        	wRadios[i].checked = false;
    	}
    }
}

function validateSectors(pElementId, pTmpSector) {
	var wSelected = false;
	var wRadios = document.getElementsByTagName('input');
	
    for ( var i=0;i<wRadios.length;i++) {
    	if( wRadios[i].className == pElementId && wRadios[i].checked ){
        	wSelected = true;
    	}
    }
    
    if(wSelected) {
    	document.getElementById(pElementId + '_error').style.display = "none";    	
		copyValue(pTmpSector,'labelSelectedSub','valueSelectedSub','labelSelected');
    	closeSectors(pElementId,'industryOptions','changeSectors');
    	document.getElementById('valueSelected').value = pElementId;
    } else {
    	//Display Error Message
    	document.getElementById(pElementId + '_error').style.display = "block";
    }
    
}

function loadSelection() {
	var selectedIndustry = document.getElementById('valueSelected').value;
	var selectedSector = document.getElementById('valueSelectedSub').value;
	if( selectedIndustry.length > 0 && selectedSector.length > 0 ) {
		closeSectors(selectedIndustry, 'industryOptions', 'changeSectors');
		document.getElementById('showSelectedSub').style.display="block";
	}
}

function validateBidAlertService (pValue) {
    document.getElementById('bidAlertService').value = pValue;
}

function  validateGovBusinessCode (pSelect) {
    document.getElementById('govBusinessCode').value = pSelect.value;
}

function copyValue(pSourceValueName, pTargetLabel, pTargetValue, pLabelPrefix) {
	
    var wRadios = document.getElementsByName(pSourceValueName);
    for (var i=0; i < wRadios.length; i++) {
    	if ( wRadios[i].checked == true) {
        	var wIndex = wRadios[i].id.substring(pLabelPrefix.length);
        	
     		document.getElementById(pTargetLabel).innerHTML = document.getElementById('sourceLabel'+eval(wIndex)).innerHTML;
    		document.getElementById(pTargetValue).value = wRadios[i].value;
    		document.getElementById('showSelectedSub').style.display = "block";
    	}
    }
}

function externalLinks() {

	if (!document.getElementsByTagName) return;

		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		var relvalue = anchor.getAttribute("rel");

		if (anchor.getAttribute("href")) {
			var external = /external/;
			var relvalue = anchor.getAttribute("rel");
			if (external.test(relvalue)) { anchor.target = "_blank"; }
		}
	}
}
function openFlash(pId,pSelectedStates) {

	var wSelectedStates = document.getElementById(pSelectedStates).value;
	
		var wFlashObjectStr = "";

		wFlashObjectStr += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" height=\"239\" width=\"540\">";
		wFlashObjectStr += "<param name=\"movie\" value=\"/cgi/en/Swf/map.swf\"/>";

		if (wSelectedStates.length > 0) {
			wFlashObjectStr += "<param name=\"FlashVars\" value=\"MyXmlPath=/cgi/en/Swf/map.xml&wSelectedStates="+ wSelectedStates +"\"/>";		
			wFlashObjectStr += "<embed src=\"/cgi/en/Swf/map.swf\" flashvars=\"MyXmlPath=/cgi/en/Swf/map.xml&wSelectedStates="+ wSelectedStates +"\" quality=\"high\" pluginspage=\"http:\/\/www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" height=\"239\" width=\"540\"></embed>";
		} else {
			wFlashObjectStr += "<param name=\"FlashVars\" value=\"MyXmlPath=/cgi/en/Swf/map.xml\"/>";		
			wFlashObjectStr += "<embed src=\"/cgi/en/Swf/map.swf\" flashvars=\"MyXmlPath=/cgi/en/Swf/map.xml\" quality=\"high\" pluginspage=\"http:\/\/www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" height=\"239\" width=\"540\"></embed>";		
		}
		
		wFlashObjectStr += "<param name=\"quality\" value=\"high\"/>";		
		wFlashObjectStr += "</object>";

		document.getElementById(pId).innerHTML = wFlashObjectStr;

		var flashPopUp = document.getElementById('flashMap');
		flashPopUp.style.display = 'block';
	}

function showMap(elem) {
    var flashMap = document.getElementById('flashMap');
	flashMap.style.display = 'block';
	
}

function SubmitForm(states) {
		if ( states.charAt(states.length-2) == "," ) {
			states = states.substring(0,states.length-2);
		}	
		var wStates = document.getElementById('states_of_interest');
		wStates.value = states;
		closeIt('flashMap');
		if (wStates.value.length > 0) {
			document.getElementById('showChange').style.display = "inline";
		} else { 
			document.getElementById('showChange').style.display = "none";
		}
}

function openCollapse(pListId) {
	var wList = document.getElementById(pListId);
	
	if (wList.style.display == "none") {
		wList.style.display = "block";
	} else {
		wList.style.display = "none";		
	}
}

function suggestUsername(){
	var wSuggest = document.getElementById('email').value;
	var wUsernameEl = document.getElementById('username');
	//trim wSuggest
	wSuggest=wSuggest.replace(/(^\s*)|(\s*$)/g,'');
	if(wSuggest == ''){
	    document.getElementById('usernameLbl').style.display = "none";
	    document.getElementById('ClearLink').style.display = "none";
	    wUsernameEl.style.display = "";
	}else if(wUsernameEl.value == ''){
	    wUsernameEl.value =wSuggest; 
	    wUsernameEl.style.display = "none";
	    document.getElementById('usernameLbl').innerHTML = wSuggest;
	    document.getElementById('usernameLbl').style.display = "";
	    document.getElementById('usernameLbl').style.width = "250px";
	    document.getElementById('usernameLbl').style.display = "inline-block";
	    document.getElementById('ClearLink').style.display = "";
	}
}

function clearSuggestUsername(){
    document.getElementById('usernameLbl').style.display = "none";
	document.getElementById('ClearLink').style.display = "none";
    document.getElementById('username').value="";
    document.getElementById('username').style.display = "";
    
}

function openPrintVersion(pDiv){
	var content = document.getElementById(pDiv);
	OpenWindow=window.open("", "newwin", "height=1000, width=1000,left=0,top=0,screenX=0,screenY=0,toolbar=no,scrollbars=yes,menubar=yes");
	OpenWindow.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml'>");
	OpenWindow.document.write("<head>");
	OpenWindow.document.write("<title>Print Friendly</title>");
	OpenWindow.document.write("<link href='/cgi/en/css/gb_design_aio.css' type='text/css' rel='stylesheet' media='all' />");
	OpenWindow.document.write("<!--[if IE 7]><link href='/cgi/en/css/ie7.css' type='text/css' rel='stylesheet' media='all'/><![endif]-->");
	OpenWindow.document.write("<!--[if lte IE 6]><style type='text/css'><link href='/cgi/en/css/ie6.css' type='text/css' rel='stylesheet' media='all'/></style><![endif]-->");
	OpenWindow.document.write("</head>");
	OpenWindow.document.write("<body class='nobck'>");
	OpenWindow.document.write(content.innerHTML);
	//OpenWindow.document.write("<img src='cgi/en/img/gb-Pf-check.gif' alt=''/>");
	OpenWindow.document.write("</body>");
	OpenWindow.document.write("</html>");
	OpenWindow.document.close();
}

function setRequiredError(pElementId) {
    document.getElementById(pElementId).style.color="#F00";
}

function changeRequiredLabels(mainCountryId){
    var mainCountry = document.getElementById(mainCountryId).value;
    if( mainCountry == 'US' || mainCountry == 'CA' ){
        document.getElementById('mainProvinceSpan').style.display = "";
        document.getElementById('zipRequiredStar').style.display = "";
    }else if( mainCountry == 'GB' ){
        document.getElementById('mainProvinceSpan').style.display = "";
        document.getElementById('zipRequiredStar').style.display = "none";
    }else{
        document.getElementById('mainProvinceSpan').style.display = "none";
        document.getElementById('zipRequiredStar').style.display = "none";
    } 
}

function disableSumbitButton(pElement) {
    pElement.style.background="transparent url(/cgi/en/img/gb-btn-signUp-off.png) no-repeat scroll left top";
}

function changePackageImage(){
	
	var imgs = getElementsByClassName("payPlanBullet");
	var radios = getElementsByClassName("payPlanRadio");
	
	for (var i=0; i<radios.length; i++){
		imgs[i].src = "/cgi/en/img/x.gif";
		if (radios[i].checked){
			imgs[i].src = "/cgi/en/img/gb-h1redArrow.gif";
		}
	}
}

function getElementsByClassName(class_name)
      {
        var all_obj,ret_obj=new Array(),j=0,teststr;

        if(document.all)all_obj=document.all;
        else if(document.getElementsByTagName && !document.all)
          all_obj=document.getElementsByTagName("*");

        for(i=0;i<all_obj.length;i++)
        {
          if(all_obj[i].className.indexOf(class_name)!=-1)
          {
            teststr=","+all_obj[i].className.split(" ").join(",")+",";
            if(teststr.indexOf(","+class_name+",")!=-1)
            {
              ret_obj[j]=all_obj[i];
              j++;
            }
          }
        }
        return ret_obj;
      }

function checkEmail(str) {
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1) {
	return false;
}

if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
	return false;
}

if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
	return false;
}

if (str.indexOf(at,(lat+1)) != -1) {
	return false;
}

if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
	return false;
}

if (str.indexOf(dot,(lat + 2)) == -1) {
	return false;
}

if (str.indexOf(" ") != -1) {
	return false;
}
return true;
}

function submitFormEpiRequestDemo(pFormName) {
	//Hide the errors section
	document.getElementById("errorMessages").style.display = "none";
	//Activate the "processing" icon and de-activate the Submit button
	switchSectionsSimple('formActions', 'processingIndicator');
	//Validate the form
	var wErrors = new Array();
	if (document.getElementById("first_name").value.length < 1) { wErrors[wErrors.length] = "First Name is a mandatory field" }
	if (document.getElementById("last_name").value.length < 1) { wErrors[wErrors.length] = "Last Name is a mandatory field" }
	if (document.getElementById("company").value.length < 1) { wErrors[wErrors.length] = "Company is a mandatory field" }
	if (document.getElementById("title").value.length < 1) { wErrors[wErrors.length] = "Title is a mandatory field" }
	if (document.getElementById("phone").value.length < 1) { wErrors[wErrors.length] = "Phone is a mandatory field" }	
	if (!checkEmail(document.getElementById("email").value)) { wErrors[wErrors.length] = "Email Address is a mandatory field, and must be valid" }	

        if (document.getElementById("referred_by").value == 'NONE') { wErrors[wErrors.length] = "'How were you referred to epipeline?' is a mandatory field" }
	
	var messageCount = wErrors.length;
	if ( messageCount > 0 ) {
		//If there are errors
		var wErrorMessageStr = "<p>";
		for( i=0; i < messageCount; i++ ) {
			wErrorMessageStr += wErrors[i] + "<br />";
		}
		 wErrorMessageStr += "</p>";
		//Display the errors
		document.getElementById("errorMessages").innerHTML = wErrorMessageStr;
		//Activate the error section
		document.getElementById("errorMessages").style.display = "";						
		//Reactivate the Submit button and hide the "processing" icon
		switchSectionsSimple( 'processingIndicator', 'formActions' );
                window.location = '#';
	} else { 
		//Submit the form
		document.forms[pFormName].submit(); 
	}
}

function submitFormIptRequestDemo(pFormName) {
	//Hide the errors section
	document.getElementById("errorMessages").style.display = "none";
	//Activate the "processing" icon and de-activate the Submit button
	switchSectionsSimple( 'formActions', 'processingIndicator');
	//Validate the form
	var wErrors = new Array();
	if (document.getElementById("agency").value.length < 1) { wErrors[wErrors.length] = "Agency Name is a mandatory field" }
	if (document.getElementById("first_name").value.length < 1) { wErrors[wErrors.length] = "First Name is a mandatory field" }
	if (document.getElementById("last_name").value.length < 1) { wErrors[wErrors.length] = "Last Name is a mandatory field" }
	if (document.getElementById("title").value.length < 1) { wErrors[wErrors.length] = "Title is a mandatory field" }
	if (document.getElementById("phone").value.length < 1) { wErrors[wErrors.length] = "Phone is a mandatory field" }
        else if (!checkPhone(document.getElementById("phone").value)){ wErrors[wErrors.length] = "Phone must be valid (999-999-9999)" }
	if (!checkEmail(document.getElementById("email").value)) { wErrors[wErrors.length] = "Email Address is a mandatory field, and must be valid" }
	if (document.getElementById("mailing_address").value.length < 1) { wErrors[wErrors.length] = "Mailing Address is a mandatory field" }
	if (document.getElementById("city").value.length < 1) { wErrors[wErrors.length] = "City is a mandatory field" }				
	if (document.getElementById("state_province").value.length < 1) { wErrors[wErrors.length] = "State/Province is a mandatory field" }
	if (document.getElementById("state_province").value == '-') { wErrors[wErrors.length] = "State/Province is a mandatory field" }
	if (document.getElementById("country").value.length < 1) { wErrors[wErrors.length] = "Country is a mandatory field" }
	if (document.getElementById("zip_postal").value.length < 1) { wErrors[wErrors.length] = "Zip/Postal Code is a mandatory field" }
	
	var messageCount = wErrors.length;
	if ( messageCount > 0 ) {
		//If there are errors
		var wErrorMessageStr = "<p>";
		for( i=0; i < messageCount; i++ ) {
			wErrorMessageStr += wErrors[i] + "<br />";
		}
		 wErrorMessageStr += "</p>";
		//Display the errors
		document.getElementById("errorMessages").innerHTML = wErrorMessageStr;
		//Activate the error section
		document.getElementById("errorMessages").style.display = "";						
		//Reactivate the Submit button and hide the "processing" icon
		switchSectionsSimple( 'processingIndicator', 'formActions' );
	} else { 
		//Submit the form
		document.forms[pFormName].submit(); 
	}
}	
				
function switchSectionsSimple(sectionToHide, sectionToShow) {
	document.getElementById( sectionToHide ).style.display = "none";
	document.getElementById( sectionToShow ).style.display = "";
} 

function loadTestimonials(pXmlInpuPageUrl) { 
 	xmlHttp=GetXmlHttpObject() 
 	if (xmlHttp==null) { 
 		return;
 	} 
 	xmlHttp.onreadystatechange=stateChanged 
 	xmlHttp.open("GET",pXmlInpuPageUrl,true) 
 	xmlHttp.send(null) 
} 
 
function stateChanged() {
 	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
 		xmlDoc=xmlHttp.responseXML; 
 		var xmlTestimonials=xmlDoc.getElementsByTagName("Testimonial"); 
 		var size = xmlTestimonials.length; 
 
 		var pos1;
 		
 		pos1 = getRandomNumber(size);
 		pos1 = ((pos1 )-((pos1) % 1));
        setTestimonial(xmlTestimonials, pos1, "testimonial");          		
 	} 
 }
 
function getRandomNumber(size) {
	return Number(Math.random() * size);
}
 
function setTestimonial(xmlTestimonials, pos, divId) {
	var by = xmlTestimonials[pos].getElementsByTagName("TestimonialBy")[0].childNodes[0].nodeValue; 
	var from = xmlTestimonials[pos].getElementsByTagName("TestimonialFromCompany")[0].childNodes[0].nodeValue; 
	var details = xmlTestimonials[pos].getElementsByTagName("TestimonialText")[0].childNodes[0].nodeValue; 
 				
	var html = '<p class="quote"><span>' + details + '</span></p>';
		html += '<p class="quotedBy">' + by + '<br/>';
		html += '<strong>' + from + '</strong></p>'

	document.getElementById(divId).innerHTML = html;
}
         	 
function GetXmlHttpObject() { 
 	var objXMLHttp=null 
 	if (window.XMLHttpRequest) { 
 		objXMLHttp=new XMLHttpRequest() 
 	} else if(window.ActiveXObject) { 
 		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") 
 	} 
 	return objXMLHttp 
}

function countEnteredChars(areaId, limit){
    var areaName = document.getElementById( areaId );
    if (areaName.value.length>limit){
        areaName.value = areaName.value.substring(0,limit);
    }
}

function prepSpecifyText(pSpecifyId) {
    var specifyTxtFld = document.getElementById('specify');
    var referrerDD = document.getElementById('referrer');
    var selectedValue = referrerDD.options[referrerDD.selectedIndex].value;
    if( selectedValue == "REFERRED" || selectedValue == "OTHER" ) {
    specifyTxtFld.disabled = false;
    document.getElementById(pSpecifyId).style.display="block";
    } else {
    specifyTxtFld.disabled = true;
    specifyTxtFld.value = 'Please Specify...';
    document.getElementById(pSpecifyId).style.display="none";
	}
}

function clearTextReg(elem) {
	if (document.getElementById("specify").value != 'Please Specify...') {

	} else {
			elem.value = '';
	}
}

function checkPhone(str) 
{
	var newstr = str.replace(/\D/g, "");
	return (newstr.length == 10);
}
