var http_request = false;
function makePOSTRequest( url, parameters ) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	   http_request = new XMLHttpRequest();
	   if (http_request.overrideMimeType) {
	   	// set type accordingly to anticipated content type
	      //http_request.overrideMimeType('text/xml');
	      http_request.overrideMimeType('text/html');
	   }
	} else if (window.ActiveXObject) { // IE
	   try {
	      http_request = new ActiveXObject("Msxml2.XMLHTTP");
	   } catch (e) {
	      try {
	         http_request = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (e) {}
	   }
	}
	if (!http_request) {
	   alert('Cannot create XMLHTTP instance');
	   return false;
	}
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function alertContents() {  		
	if (http_request.readyState == 4) {
	   if (http_request.status == 200) {
	      //alert(http_request.responseText);
	      result = http_request.responseText;
	      //alert( result );
	      PostFormHandling( result );
	      //document.getElementById( 'myspan').innerHTML = result;
	      //toggleBlockControl( 'layForm' , '0');
	      //toggleBlockControl( 'layDone' , '1');            
	   } else {
	      alert('There was a problem with the request.');
	   }
	}
}
   
function get(obj, strProcess, strLayerName) {
	var elem = obj.elements;
	var poststr = "";
	var strJoin = "";
	var elemValue;
	
	for(var i = 0; i < elem.length; i++)
	{
		elemValue = "";
		toggleBlockControl( 'err_' + elem[i].name, '0' );
	  toggleBlockControl( 'err_main', '0' );
		
		if ( poststr.length > 0 ) {
			strJoin = "&";
		} 
		if( elem[i].type == "checkbox" || elem[i].type == "radio" ) {
			if ( elem[i].checked == true ) {
				elemValue = elem[i].value;
				poststr = poststr + strJoin + elem[i].name + "=" + escape( elemValue );
			} 
		}
		else {
			elemValue = elem[i].value;
			poststr = poststr + strJoin + elem[i].name + "=" + escape( elemValue );
		}
		
	}	
	
	poststr = poststr + "&formName=" + obj.name; 
	poststr = poststr + "&layerName=" + strLayerName; 
	
	//alert( poststr );
	makePOSTRequest( strProcess, poststr );
}


var objHTTPRequest = false;
function getPage(contentID, url) {
    objHTTPRequest = getHTTPObject();
    if (objHTTPRequest) {
        objHTTPRequest.onreadystatechange = function() {
            if (objHTTPRequest.readyState == 4) {
                if (objHTTPRequest.status == 200 || objHTTPRequest.status == 304) {
                    document.getElementById(contentID).innerHTML = objHTTPRequest.responseText;   
					Slimbox.scanPage();
                } 
                else {
                  alert('There was a problem with the request.');
              }
          }
      };
        objHTTPRequest.open("GET", url, true);
        objHTTPRequest.send(null);
    }
}

function displayForm2( strContainer, formFile ){
    toggleBlockControl('ccbMov', 0);


	getPage(strContainer, formFile);
	toggleBlockControl( 'formContent', 0);
	toggleBlockControl( 'formContentTQ', 0);
	toggleBlockControl( 'formContentGU', 0);
	toggleBlockControl( 'formContentCU', 0);
	toggleBlockControl( 'formContentMain', 0);
	
	toggleBlockControl( 'overlayForm', 1);
	toggleBlockControl( strContainer, 1);
	
}

function displayFormMain( formFile ){
	getPage('formContentMain', formFile);
	toggleBlockControl( 'overlayFormMain', 1);
}

function closeForm( formContainer ) {
	if ( document.getElementById("formContent") ) {
		document.getElementById("formContent").innerHTML = "";
	}
	
	if ( document.getElementById("formContentTQ") ) {
		document.getElementById("formContentTQ").innerHTML = "";
	}
	
	if ( document.getElementById("formContentGU") ) {
		document.getElementById("formContentGU").innerHTML = "";
	}
	
	if ( document.getElementById("formContentCU") ) {
		document.getElementById("formContentCU").innerHTML = "";
	}
	
	if ( document.getElementById("formContentMain") ) {
		document.getElementById("formContentMain").innerHTML = "";
	}
	toggleBlockControl('overlayForm', '0');
	toggleBlockControl('overlayFormMain', '0');
	
	toggleBlockControl( 'ccbMov', 1);
}


function displayForm( formContainer, formFile ) {
	getPage(formContainer, formFile);
	toggleBlockControl(formContainer, '1');
}

function getPageNBg(contentID, strURL, bgID, bgClass) {
	getPage(contentID, strURL);
	
	if ( document.getElementById( bgID ) ) {
      document.getElementById( bgID ).className = bgClass;
  }
}


function postItYo(strProcess, strParam) {
	var HTTPrequest2 = false;
	HTTPrequest2 = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	   HTTPrequest2 = new XMLHttpRequest();
	   if (HTTPrequest2.overrideMimeType) {
	   	// set type accordingly to anticipated content type
	      //http_request.overrideMimeType('text/xml');
	      HTTPrequest2.overrideMimeType('text/html');
	   }
	} else if (window.ActiveXObject) { // IE
	   try {
	      HTTPrequest2 = new ActiveXObject("Msxml2.XMLHTTP");
	   } catch (e) {
	      try {
	         HTTPrequest2 = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (e) {}
	   }
	}
	if (!HTTPrequest2) {
	   alert('Cannot create XMLHTTP instance');
	   return false;
	}
	HTTPrequest2.onreadystatechange = function() {  		
		if (HTTPrequest2.readyState == 4) {
		   if (HTTPrequest2.status == 200) {
		      result = HTTPrequest2.responseText;
		      //alert( result );        
		   } else {
		   		/* --- Do Nothing - Error Traping --- */
		      //alert('There was a problem with the request.');
		   }
		}
	};
	HTTPrequest2.open('POST', strProcess, true);
	HTTPrequest2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	HTTPrequest2.setRequestHeader("Content-length", strParam.length);
	HTTPrequest2.setRequestHeader("Connection", "close");
	HTTPrequest2.send(strParam);
}

