var newWindow;
openWindow = false;

function initSiteUnder() {
	if (document.getElementById('site_under')) {
	    var site_under = document.getElementById('site_under').value;
	    if (site_under == 'true' && jQuery.cookie('measure_ext') == null) {
	        openWindow = true;
	    }
	}
}

fldFocus = '';

function openSiteUnder(website_url) {
    if(openWindow === true){

        pop_meetic = window.open(website_url,'_blank','toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1,copyhistory=1,menuBar=1')
        if (null == pop_meetic || true == pop_meetic.closed || !pop_meetic || pop_meetic == undefined || pop_meetic == 'undefined'){
            // pop up ungranted
            openWindow = true;
        }else{
	        pop_meetic.blur()
	        window.focus();

	        // pop up granted
	        openWindow = false;
	        setFocus();
	        if(newWindow) newWindow.focus();
			jQuery.cookie('measure_ext',1);
        }
    }
}

function in_array(needle, collection, strict) {

    if (strict == null) {
        strict = false;
    }
    var i = collection.length-1;

    if (i >= 0) {
        do {
            if (collection[i] == needle) {
                if (strict && typeof(collection[i]) != typeof(needle)) {
                    continue;
                }
                return true;
            }
        } while (i--);
    }
    return false;
}


function getFldFocus(fld) {
    fldFocus = document.getElementById(fld);
    info = help[fld]; 
    if(info) document.getElementById('boxdescription').innerHTML = info.content; 
    if (fldFocus != null && fldFocus != '' && fldFocus.tagName != 'SELECT') {
		emptyFld(fldFocus);
	}
}

function setFocus() {
	var aExcepts = new Array('frmMonth', 'frmYear','frmDay','frmLooking','frmGender');

	if (fldFocus != null && fldFocus != '' && fldFocus.tagName != 'SELECT') {
		if(in_array(fldFocus.id, aExcepts) == false)
		{
			fldFocus.focus();
			emptyFld(fldFocus);
		}
	}
}

function emptyFld(fld) {
    var info = help[fld.id];
    var defaultLbl = info.inputDef;
	
    if (defaultLbl != '') {
        if (fld.value == defaultLbl && openWindow == false) {
            setTimeout(function() {
	              fld.value='';
            }, 100);
        }
    }

}

function showTerms()
{
	newWindow = window.open('/helptandc.asp?s=s','_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=1,copyhistory=1,copyhistory=no,width=540,height=440');
	newWindow.focus();
}
