function AjaxCall(url,target,loop){
    var request = '';
	var content = '';
	if (window.XMLHttpRequest) 
	{
		request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (request)
	{	
        var urlPost = url;
        //alert(urlPost);
        request.open("GET", urlPost, false);
        request.send(null);
        if (request.status == 200)
        {
            content = request.responseText;
    		document.getElementById(target).innerHTML = content;
			//alert(request.status);
			
			if(target.indexOf("prc3_") > -1){
			//alert(target.indexOf("prc3_"));
			//document.getElementById('Img_'+loop).style.visibility = 'hidden';
			}
			//alert(content);
        }
        else
        {
         	content = request.responseText;
			//alert(content);
        }
    }
}

/*Get the default quantity and unitprice of the selected UnitType*/
function SelectedUnitType(loop_count,ModuleID,RelatedModuleID,UnitType){
	//document.getElementById('Img_'+loop_count).style.visibility = 'visible';
	var ses = document.getElementById('Session').value;	 
	var qty = document.getElementById('users_'+loop_count).value;	
	var url = 'ModulePrice.Lasso?-Session='+ses+'&ModuleID='+ModuleID+'&RelatedModuleID='+RelatedModuleID+'&UnitType='+UnitType+'&ModuleCounter='+loop_count+'&Qty='+qty;	 
	AjaxCall(url,'qty_'+loop_count,loop_count);
}

/*Set the Amount for the selected Quantity of the selected UnitType*/
function QtyBreakCalc(loop_count,ModuleID,Qty){
    if(Qty = '0'){
	Qty = document.getElementById('users_'+loop_count).value;
	}
	var ses = document.getElementById('Session').value;	 
	var UnitType = document.getElementById('UnitType_'+loop_count).value;
	var url = 'KibizQtyBreakCalc.Lasso?-Session='+ses+'&ModuleID='+ModuleID+'&UnitType='+UnitType+'&ModuleCounter='+loop_count+'&Qty='+Qty+'&Maintenace=1stYear';
	//alert(url);	 
	AjaxCall(url,'prc1_'+loop_count,loop_count);
	var url = 'KibizQtyBreakCalc.Lasso?-Session='+ses+'&ModuleID='+ModuleID+'&UnitType='+UnitType+'&ModuleCounter='+loop_count+'&Qty='+Qty+'&Maintenace=Total';
	//alert(url);	 
	AjaxCall(url,'prc2_'+loop_count,loop_count);
	var url = 'KibizQtyBreakCalc.Lasso?-Session='+ses+'&ModuleID='+ModuleID+'&UnitType='+UnitType+'&ModuleCounter='+loop_count+'&Qty='+Qty+'&Maintenace=OneTime';
	//alert(url);	 
	AjaxCall(url,'prc3_'+loop_count,loop_count);
	
}

/*Get the selected indices in a hidden field for the quantity selected from the combo list*/
  function getSelectedIndex(loop_count,ModuleID,RelatedID,Qty) {
  //alert(Qty.indexOf("."));
  if(Qty.indexOf(".")== '-1'){
   		//document.getElementById('Img_'+loop_count).style.visibility = 'visible';
		var moduleFoundCount = document.getElementById('Module_Count').value;
		//alert(document.getElementById('users_'+loop_count).id);
      	QtyBreakCalc(loop_count,ModuleID,Qty);
    	if(RelatedID != ''){
    		var qty = document.getElementById('users_'+loop_count).value;
        	if (ModuleID==103 || ModuleID==104){
    			var Newloop_count = parseInt(loop_count) + 2;
    			document.getElementById('users_'+Newloop_count).value = qty;
    		}  
			QtyBreakCalc(Newloop_count,RelatedID,Qty);
         } 
	
	}
	else{
	 alert('Please enter valid Quanitity for the No. of Users');
	 document.getElementById('users_'+loop_count).value='';
	 document.getElementById('users_'+loop_count).focus();
	 }
	
	}
	
/********************************************
* Check the status of the ajax call         *
********************************************/
function alertContents(http_request) 
{

	if (http_request.readyState == 4)
	{
	    // everything is good, the response is received     
         
		if (http_request.status == 200) 
		{
            //alert(http_request.responseText);  
			return http_request.responseText;
			
		  }
	}
}	

/*Function to send the long parameters through the url and open a new window for view quote page*/
function AjaxView(url,parameters){
//alert(parameters.length);
   var http_request = false;
   var self = this;
   	if (window.XMLHttpRequest) 
   	{ // Mozilla, Safari, ...
        self.http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
		{
          	self.http_request.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) 
	{ // IE
        try 
        {
            self.http_request = new ActiveXObject("MSXML4.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
                self.http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {}
        }
        
    }
	if (!self.http_request) 
	{
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
	
    // if there it's in a ready state, then load the FCKeditor in place of the paragraph.
   self.http_request.onreadystatechange = 
    function() 
    { 
		var strText = alertContents(self.http_request);
		if (strText == undefined) 
		{
		} 
		else 
		{
		//window.self.location.reload();
		var ses = '-Session='+document.getElementById('Session').value;
		var Maintenance = document.getElementById('Maintenance').value;
		 var addWin = window.open('KiQuotePrintable.lasso?'+ses+'&print=1&Maintenance='+Maintenance,'printable',"resizable,width=850,height=550");
	       if (addWin==null || typeof(addWin)=="undefined"){
            alert('It appears your browser is blocking popup windows');
            } else {
            addWin.focus();
            }
		}
	};	//end of on ready state change function
	
	self.http_request.open('POST', url, true);
	//self.setRequestHeader(”Cache-Control”, “no-cache”);
	self.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	self.http_request.setRequestHeader("Content-length", parameters.length);
	self.http_request.setRequestHeader("Connection", "close");
	self.http_request.send(parameters);
	//alert('LAST HELLO');
}

/*Function to send the long parameters through the url using the SaveQuote button*/
function AjaxQuote(url,parameters){
   var http_request = false;
   var self = this;
   	if (window.XMLHttpRequest) 
   	{ // Mozilla, Safari, ...
        self.http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
		{
          	self.http_request.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) 
	{ // IE
        try 
        {
            self.http_request = new ActiveXObject("MSXML4.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
                self.http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {}
        }
        
    }
	//alert(self.http_request);
	if (!self.http_request) 
	{
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
	
    // if there it's in a ready state, then load the FCKeditor in place of the paragraph.
    self.http_request.onreadystatechange = 
    function() 
    { 
		var strText = alertContents(self.http_request); 
		if (strText == undefined) 
		{
		} 
		else 
		{
		//alert(strText);
		//var ses = '-Session='+document.getElementById('Session').value;
		//alert('1');
		self.location.href = url+parameters;
		//alert('2');
		}
	};	//end of on ready state change function
	
	self.http_request.open('POST', url, true);
	self.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	self.http_request.setRequestHeader("Content-length", parameters.length);
	self.http_request.setRequestHeader("Connection", "close");
	self.http_request.send(parameters);
}	
