function removespaces(string)
{
	var newstring = '';
	for (var i = 0; i < string.length; i++) {
	if (string.charAt(i) != ' ') newstring += string.charAt(i);
	}
	return newstring;
}

var req=new Array();
var Ret_Fun=new Array();

function sendAjaxReq(url,params,HttpMethod,retFun){
	if (!HttpMethod)HttpMethod="POST";
	req.push(initXMLHTTPRequest());
	Ret_Fun.push(retFun);
	i=parseInt(req.length)-1;
		if (req[i]){
			req[i].open(HttpMethod,url,true);
			req[i].onreadystatechange=onReadyStateChange;
			req[i].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			req[i].send(params);
		}
}

function initXMLHTTPRequest()
{ // Initialize the XML HTTP  Object
	var xRequest=null;
	if (window.XMLHttpRequest)xRequest=new XMLHttpRequest();
	else if (window.ActiveXObject)xRequest=new ActiveXObject("Microsoft.XMLHTTP");
	else {	}
	return xRequest;
}

function onReadyStateChange()
{
	for (i=0;i<req.length;i++)
	{
		if (req[i]) {
			var ready=req[i].readyState;
			var data=null;	
			if (ready==4) 
			{	
				fun=Ret_Fun[i];
				
				data=req[i].responseText;
				Ret_Fun.splice(i,1);
				
				req.splice(i,1);		

				if(data.indexOf("[MSGBOX]")>-1)
				{
					alert(data.replace("[MSGBOX]",""));
				}
				else if(data.indexOf("[REFRESH]")>-1)
				{
					location.reload();
				}
				else if(data.indexOf("[VALIDATE]")>-1) { }// Do Something
				
				else if(data.indexOf("[DISPLAY_ERROR]")>-1){ } // Do Something Else
				
				else if(data.indexOf("[NULL]")>-1){ }// Do Nothing In The Html
				
				else eval(fun+"('"+data+"')");
			}		
			else {	/* Something Here */	}
		}	
	}
}


function displayErrorMessage (message)
{
	var messageDiv = document.getElementById("messageDiv");
	messageDiv.innerHTML = message ;
	messageDiv.className = "error_box";
	messageDiv.style.display = "block";
	
}
function hideErrorMessage()
{
	var messageDiv = document.getElementById("messageDiv");
	messageDiv.style.display = "none";
}
function fillOtherComboBox(comboBox , stringOptions,flag)
{
    if(stringOptions.length>0)
    {
    	clearComboBox(comboBox , flag);
    }
    
    options = stringOptions.split(':row:');
    for(i = 0 ; i < options.length; i++)
    {
        var optionDetails = options[i].split(':col:');
        if(optionDetails.length == 1)
            return;
        var optionId = optionDetails[0];
        var optionName = optionDetails[1];
        var currentOption = new Option(optionName , optionId , false , false);
        comboBox.options[comboBox.options.length] = currentOption;
    }
}

function clearComboBox(comboBox , deleteFirstEntry)
{
    for(i = comboBox.options.length - 1 ; i > 0 ; i--)
    {
        comboBox.options[i] = null;
    }
    if(deleteFirstEntry)
        comboBox.options[0] = null;
}



function showErrorMessage(errorMessage)
{
    try
    {
        errorMessage = encodeURIComponent(errorMessage);
        window.showModalDialog("tafi/modules/error_page.php?errorMessage="+ errorMessage,window , 'dialogHeight:200 px;dialogWidth: 420 px;status: no; toolbar: no ; titlebar: no ; menubar: no; resizable: no ;scroll: no ;'  );
    }
    catch(exception){}
}

function confirmOperation(message)
{
    try
    {
        message = encodeURIComponent(message);
        var returnedValue = window.showModalDialog("tafi/modules/confirm_page.php?message="+ message,window , 'dialogHeight:200 px;dialogWidth: 420 px;status: no; toolbar: no ; titlebar: no ; menubar: no; resizable: no ;scroll: no ;'  );
        return returnedValue;
    }
    catch(exception){}
}
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

