// JavaScript Document

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 ) {

		var wCountry = findObject( pPrefix + 'Country' ).value;
    var wStateProvText = findObject( pPrefix + 'StateProvince' );
    var wStateProvCode = findObject ( pPrefix + 'StateProvinceCode');
    var wState = findObject( pPrefix + 'State' );
    var wCounty = findObject( pPrefix + 'County' );
    var wProvince = findObject( pPrefix + 'Province' );

    wStateProvCode.value = '';

    if ( wCountry == 'US' ) {

        wState.style.display = 'inline';
        wProvince.style.display = 'none';
        wCounty.style.display = 'none';
        wStateProvText.style.display = 'none';
        wStateProvText.value = '';
        wStateProvCode.style.display = 'none';
        wStateProvCode.value = wState.value;
    } else if ( wCountry == 'CA' ) {

        wState.style.display = 'none';
        wProvince.style.display = 'inline';
        wCounty.style.display = 'none';
        wStateProvText.style.display = 'none';
        wStateProvText.value = '';
        wStateProvCode.style.display = 'none';
        wStateProvCode.value = wProvince.value;
    } else if ( wCountry == 'GB' ) {

        wState.style.display = 'none';
        wProvince.style.display = 'none';
        wCounty.style.display = 'inline';
        wStateProvText.style.display = 'none';
        wStateProvText.value = '';
        wStateProvCode.style.display = 'none';
        wStateProvCode.value = wCounty.value;
    } else {

        wState.style.display = 'none';
        wProvince.style.display = 'none';
        wCounty.style.display = 'none';
        wStateProvCode.style.display = 'none';
        wStateProvText.style.display = 'inline';
    }
}

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 populateStateProvinceText( pSelect, pPrefix ) {
    findObject( pPrefix + 'StateProvinceCode' ).value = pSelect.value;
}

