//---------------- MISC

dt.flyouts();

function global() {
}

function getVenue(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

//---------------- //

function myvalidate(f,vAr) {
	var errorColor = "#FF9900";
	var error='';
	for (i=0;(obj=vAr[i]);i++) {
		con='';arg='';objAr='';objAr=obj.split(",");
		if(objAr[0])obj=eval('document.'+f.name+'.'+objAr[0]);
		arg = objAr[1]; alt = objAr[2];
		if (arg != 'div') {
		    if (obj.style && !obj.n) {
		        objbc = obj.style.backgroundColor;
		        if (objbc) obj.n = objbc;
		        else obj.n = "#FFFFFF";
		        obj.e = errorColor;
		    } else if (obj.style && obj.n) obj.style.backgroundColor = obj.n;
		    myerror = function () {
		        error += '- ' + alt + '\n';
		        if (arg != 'div') {
		            if (obj.style) {
		                obj.style.backgroundColor = obj.e;
		            }
		        }
		    }
		    if (arg.length > 3) con = eval(objAr[1]);
		    if (con) myerror();
		    if (arg == 'req') if (!obj.value) myerror();
		    if (arg == 'eml') if (!isMyEmail(obj.value)) myerror();
		    if (arg == 'num') if (isNaN(obj.value) || !obj.value) myerror();
		    if (arg == 'rby') if (!isYesSelected(f.name, objAr[0])) myerror();
		    if (arg == 'rb') if (!isSelected(f.name, objAr[0])) myerror();
		    if (arg == 'cb') if (!isChecked(f.name, objAr[0])) myerror();
		} else {
		    if (!hasContent(f.name,objAr[0])) myerror();
		}
	}if(error) {alert('Please correct the following fields:\n\n'+error);return false}
	else return true;
}

function isSelected(theForm, theGroup) {

    var radios = eval('document.' + theForm + '.' + theGroup);
    for (var i=0; i <radios.length; i++) { 
        if (radios[i].checked) { 
            return true; 
        } 
    } 
    return false;
}

function isYesSelected(theForm, theGroup) {
    var radios = eval('document.' + theForm + '.' + theGroup);
    for (var i = 0; i < radios.length; i++) {
        if (radios[i].checked) {
            if (radios[i].value == 1) {
                return true;
            }
        }

    }
    return false;
}

function isChecked(theForm, theCB) {

    var cb = eval('document.' + theForm + '.' + theCB);
    if (cb.checked == false) {
        return false;
    } else {
    return true;
    }

}

function hasContent(theForm, theDIV) {
    var dDiv = eval('document.getElementById("' + theDIV + '")');
    if (theDIV == 'div_water_use_verified_document') {
        if (isYesSelected('product', 'water_use_verified')) {
            if (dDiv.innerHTML.length > 0) {
                return true;
            } else {
                return false;
                }
        } else {
            return true;
        }

    } else {

        if (dDiv.innerHTML.length > 0) {
            return true;
        } else {
            return false;
        }

    }
}

function isMyEmail(eml) {
	var emailPat = /^(\".*\"|[A-Za-z0-9\_][A-Za-z0-9\.\-\_]*)@(\[\d{1,3}(\.\d{1,3}){3}]|([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,4})$/;
	var matchArray = eml.match(emailPat);
	if (matchArray == null) return false;
	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) for(i=1;i<=4;i++) if (IPArray[i]>255) return false;
	return true;
}

