function confirmCancel(cancelMsg,onCancelControlID)
{
    var conf = confirm(cancelMsg);
    if (conf==true) {
        var theControl = getControl(onCancelControlID);
        theControl.click();
    }
}
function showProductPopup(behaviorID,targetID,controlList,dataList)
{
    populateControls(controlList,dataList);
    showPopup(behaviorID,targetID);
}
function showPopup(behaviorID, targetID) {
    

    // set the parentElementID to the targetID...the popup is positioned on this
    
    var extenderPopupBeh = $find(behaviorID+"PopupBehavior")

    /*             
    Positioning Ints
    Center: 1
    BottomLeft: 2
    BottomRight: 3
    TopLeft: 4
    TopRight: 5 
    */

    extenderPopupBeh.set_parentElementID(targetID);
    
    // set the positioningMode of where to position upon on the parent
    extenderPopupBeh.set_positioningMode(4);

    // fill the popup with what ever content you want...maybe result from json web service call
    //$get('divPopup').innerHTML = content;

    // show the popup...the .showPopup() method does not work well here
    var extender = $find(behaviorID);
    extender._onFocus();
    //extender.showPopup();
    
}

function populateControls(controlIDList, dataList) {
    
    
    var controlArray = controlIDList.split('|');
    var dataArray = dataList.split('|');
    var theControl;
    for (var i = 0; i < controlArray.length; i++) {
        theControl = getControl(controlArray[i]);
        theControl.innerHTML = dataArray[i];
    }
}

function setFocus(controlID) {
    var theControl = getControl(controlID);
    theControl.focus();
}
function popUpWindow(URL) {
    popUpWindowCustom(URL, 'CONDITIONS',480, 500);
}
function popUpWindowCustom(URL, Title,popW, popH) {
    w = screen.width;
    h = screen.height;

    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;

    popUpWin = window.open(URL, Title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);

    popUpWin.focus();
}
function showDPI(controlID, res300ID, res600ID,fmtPDFID,fmtTIFFID) 
{
    var theControl = getControl(controlID);
    var res300 = getControl(res300ID);
    var res600 = getControl(res600ID);
    var fmtPDF = getControl(fmtPDFID);
    var fmtTIFF = getControl(fmtTIFFID);
    var result = '';
    
    if (res300.checked && fmtPDF.checked) {
        result = '520 kb';
    } else if (res300.checked && fmtTIFF.checked) {
        result = '820 kb';
    } else if (res600.checked && fmtPDF.checked) {
        result = '1,620 kb (1.6 mb)';
    } else if (res600.checked && fmtTIFF.checked) {
        result='2,680 kb (2.7 mb)';
    }
    theControl.innerHTML = result;
}
function showOnCheck(controlID,checkboxID)
{
    showhideOnCheckHelper(controlID,checkboxID,true);
}
function hideOnCheck(controlID,checkboxID)
{
    showhideOnCheckHelper(controlID,checkboxID,false);
}
function showhideOnCheckHelper(controlID,checkboxID,isChecked)
{
    var isVisible=false;
    var theCheckbox=getControl(checkboxID);
    if (theCheckbox.checked==isChecked)
    {
        isVisible=true;
    }
    
    visi(controlID,isVisible);
}


function showOnValue(controlIDList, dropdownID, hideonValue)
{
    showHideOnValueHelper(controlIDList,dropdownID,hideonValue,true);
}
function hideOnValue(controlIDList, dropdownID, hideonValue)
{
    showHideOnValueHelper(controlIDList, dropdownID, hideonValue, false);
}

function showHideOnValueHelper(controlIDList, dropdownID, showonValue, show) 
{
    var theDropdown = getControl(dropdownID);
    var selIndex = theDropdown.selectedIndex;
    var selValue = theDropdown.options[selIndex].value
    var isVisible=false;    

    var valArray = showonValue.split('|');
    var controlArray = controlIDList.split('|');

    for (var i = 0; i < valArray.length; i++) {
        if (valArray[i] == selValue) {
            isVisible = show;
            break;
        }
    }
    for (var c=0; c < controlArray.length; c++) {
        visi(controlArray[c], isVisible);    
    }
    
}


function getRadioValue(radioObject) {
      var value = null
      for (var i=0; i<radioObject.length; i++) {
           if (radioObject[i].checked) {
                value = radioObject[i].value;
                break ;
           }
      }
     return value
 }
 
function visi(theControl,isVisible) {
    visiHelper(theControl,isVisible,true);
}
function enable(theControl,isEnabled) {
    visiHelper(theControl,true,isEnabled);
}

function visiHelper(theControl,isVisible, isEnabled)
{
    var isDisabled = isEnabled?0:true;
    var vista='';
    var display = '';
    
	if (document.layers)
	{
		vista = (isVisible==true) ? 'show' : 'hide';
		document.layers[theControl].visibility = vista;
		document.layers[theControl].disabled = isDisabled;
	}
	else if (document.all)
	{
	    vista = (isVisible == true) ? 'visible' : 'hidden';
	    disp = (isVisible == true) ? '' : 'none';
	    document.all[theControl].style.visibility = vista;
	    document.all[theControl].style.display = disp;
		document.all[theControl].disabled= isDisabled;
	}
	else if (document.getElementById)
	{
	    vista = (isVisible == true) ? 'visible' : 'hidden';
	    disp = (isVisible == true) ? '' : 'none';
	    ctl = document.getElementById(theControl);
	    ctl.style.visibility = vista;
	    ctl.style.display = disp;
        ctl.disabled=isDisabled;
	}
}
function getControl(controlID)
{
	if (document.layers)
	{
		theControl=document.layers[controlID];
	}
	else if (document.all)
	{
		theControl=document.all[controlID];
	}
	else if (document.getElementById)
	{
		theControl=document.getElementById(controlID);
	}
	return(theControl);
}
function markAsChanged(controlID)
{
    var theControl = getControl(controlID);
    theControl.value='1';
}
function confirmDataUpdate(controlID,confirmMessage) {
    var theControl=getControl(controlID);
    var dataChanged = theControl.value;
    if (dataChanged=='1') {
        return(confirm(confirmMessage));
    } else {
        return(true);
    }
}
function keyPress(evt, buttonID) {
    var theControl = getControl(buttonID);
    if (evt.which || evt.keyCode) {
        if ((evt.which == 13) || (evt.keyCode == 13)) {
            location = theControl.href;
            return false;
        }
        return true;
    }
}