function modalWin(url) {
	var w = 300;
	var h = 360;
	var l = (screen.availWidth - w) / 2;
	var t =  (screen.availHeight - h) / 2;
	window.open(url,'Browser','height=430,width=400,left='+l+', top='+t+',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes');
}

function OpenPopupHelpMovie(movie) {
	var w = 700;
	var h = 625;
	var l = (screen.availWidth - w) / 2;
	var t =  (screen.availHeight - h) / 2;
	var url = "/phplib/tccp_helpmovie.php?movie="+movie;
	if (window.showModalDialog) {
	var params='dialogWidth='+w+'px;dialogHeight='+h+'px;dialogLeft='+l+'px;resizable:yes;scroll:yes';
	window.showModalDialog(url, "mywindow", params);
	} else {
	var params='height='+h+',width='+w+',left='+l+', top='+t+',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes';
	window.open (url,"mywindow",params);
	}
	
}

function OpenPopupHelp(pouphelp) {
	var w = 475;
	var h = 500;
	var l = (screen.availWidth - w) / 2;
	var t =  (screen.availHeight - h) / 2;
	var url = "/phplib/tccp_popuphelp.php?ID="+pouphelp;
	if (window.showModalDialog) {
	var params='dialogWidth='+w+'px;dialogHeight='+h+'px;dialogLeft='+l+'px;resizable:yes;scroll:yes';
	window.showModalDialog(url, "mywindow", params);
	} else {
	var params='height='+h+',width='+w+',left='+l+', top='+t+',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes';
	window.open (url,"mywindow",params);
	}
	
}

function ccsi_replace(StrOrg,strFind,strReplace){
	st = new String;
	s = new String(StrOrg);
	s.replace(strFind,strReplace);
	var st =  s.replace(strFind,strReplace);
	return st.toString();
}

function AutoSubmit(frmName) {
	var vTest = document.getElementById('reload');
	vTest.value = 'yes';
	var formObject = document.forms[frmName];
	formObject.submit();
	}
	
function leftTrim(sString){
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString){
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function trimAll(sString){
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
return sString;}

var req;
var req2;

function UpdateCCI(countrycode, beer, other){
	var url = location.protocol + "//" + location.hostname + "/phplib/tccp_xml_cci.php";
	url += '?country=' + countrycode + '&beer=' + beer + '&other=' + other;
	
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = ReportUpdateCCI;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = ReportUpdateCCI;
            req.open("GET", url, true);
            req.send();
        }
    }	
}

function ReportUpdateCCI(){
	var oMessage;
	if (req.readyState == 4) { // Complete
	  if (req.status == 200) { // OK response
		xml = req.responseXML;
		if(xml!=null) {
			t = xml.getElementsByTagName("message");
			if(t==null){
				alert('Houston we have a problem');
			} else {
				if (t.length>0) {
					//oMessage = document.getElementById('ErrMsg')
					//if (oMessage){
						//oMessage.innerHTML = t[0].firstChild.textContent;
					//}
					alert(t[0].firstChild.textContent);
				}
			}
		  } else {
		  }
		}
	}
}

function ExecAjax(url){
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.open("POST", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.open("POST", url, true);
            req.send();
        }
    }
}

function AjaxGetDesc(url, code, maintlink){
	// branch for native XMLHttpRequest object
    oInput = document.getElementById(code);
	url = url + '&code=' + oInput.value + '&maintlink=' + maintlink;
	
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = AjaxSetDesc;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = AjaxSetDesc;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function AjaxGetList(url, code, dropdown){
    // branch for native XMLHttpRequest object
    oInput = document.getElementById(code);
	url = url + '&code=' + oInput.value + '&maintlink=' + dropdown;
	
	if (window.XMLHttpRequest) {
         req2 = new XMLHttpRequest();
         req2.onreadystatechange = AjaxSetList;
         req2.open("GET", url, true);
         req2.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
         req2 = new ActiveXObject("Microsoft.XMLHTTP");
        if ( req2) {
             req2.onreadystatechange = AjaxSetList;
             req2.open("GET", url, true);
             req2.send();
        }
    }
}
  
function AjaxSetDesc() {
	if (req.readyState == 4) { // Complete

	  if (req.status == 200) { // OK response
		xml = req.responseXML;
		if(xml!=null) {
			t = xml.getElementsByTagName("entity");
			sText = "";
			if(t==null){
				alert('Houston we have a problem');
			} else {
				if (t.length>0) {
				maintlink = t[0].getAttribute('maintlink')
				document.getElementById(maintlink).innerHTML = t[0].getAttribute('desc');
				document.getElementById(maintlink).href = t[0].getAttribute('url');
				}
			}
		  } else {
		  }
		}
	}
}
  
function AjaxSetList() {
	var t;
	var maintlink;
	var emptyfirst;
	var bEmptyFirst;
	var i=0;
	var oDropDown;
	var iMinimal;
	var title;
	var st;

	if (req2.readyState == 4) { // Complete

	  if (req2.status == 200) { // OK response
		xml =  req2.responseXML;
		if(xml!=null) {
			t = xml.getElementsByTagName("entity");
			sText = "";
			if(t==null){
				alert('Houston we have a problem');
			} else {
				
				if (t.length>0) {
					bEmptyFirst = true;
					maintlink = t[0].getAttribute('maintlink');
					emptyfirst = t[0].getAttribute('emptyfirst');
					if (emptyfirst=="1"){
						bEmptyFirst	= true;
					} else {
						bEmptyFirst	= false;
					}
					
					oDropDown = document.getElementById(maintlink);
					oDropDown.length=0;

					iMinimal = 0;
					if (bEmptyFirst) {
						st = new Option('', "0");
						iMinimal = 1;
						oDropDown.options.add(st);
					}
				
					if((t.length>iMinimal)) {
						for (i=0; i<t.length; i++ )
						   {
						   if (bEmptyFirst) {
						   title = t[i].getAttribute('code') + ' - ' + t[i].getAttribute('desc');
						   } else {
							title = t[i].getAttribute('desc');
						   }
						   st = new Option(title, t[i].getAttribute('id'));
						   oDropDown.options.add(st);
						   }
					} else {
						
						oDropDown.length=0;
						// always add the first for no selection
						st = new Option('None available', "0");	
						oDropDown.options.add(st);						
					}
				}
			}
		  } else {
		  }
		}
	}
}