// JavaScript Document
//generic AJAX initialisation
//***Author: JMAMMOUS***
//***Date: Feb 11 2009***
	var commonXHR;
	if (window.XMLHttpRequest)     // Object of the current windows
		{ 
    		commonXHR = new XMLHttpRequest();     // Firefox, Safari, ...
		} 
		else 
 			if (window.ActiveXObject)   // ActiveX version
 				{
    				commonXHR = new ActiveXObject("MSXML2.XMLHTTP");  // Internet Explorer 
 				} 
				
//****************************************************
//start your functions here

//this function cotnrols which actionFunction to call and which page to include
function commonActionMain(actionFunction, actionPage) {
	actionFunction(actionPage);
	return false;
}



function commonInnerHTMLWrite(divName, actionPage) {
	if(actionPage != "") {
	document.getElementById(divName).innerHTML = '<img src="../images/loadingGif.gif" width="40" height="40"/>';
	} 
		commonXHR.open("GET", actionPage);
		commonXHR.onreadystatechange  = function()
    	{ 
         	if(commonXHR.readyState  == 4)
         	{
			document.getElementById(divName).innerHTML = commonXHR.responseText;
			}
       }
	    commonXHR.send(null);
	   	   
	//alert(xhr.responseText);	
	
}


function commonInnerHTMLClose(divName, actionPage) {
	
			document.getElementById(divName).innerHTML = '';
				
}

function commonImageHTMLWrite(divName, actionPage) {
	
	document.getElementById(divName).innerHTML = '<img src="../images/loadingGif.gif" width="40" height="40"/>';
		commonXHR.open("GET", actionPage);
		commonXHR.onreadystatechange  = function()
    	{ 
         	if(commonXHR.readyState  == 4)
         	{
			document.getElementById(divName).innerHTML = '<img src="'+actionPage+'" alt="" name="img" border="1" align="middle" id="img2"/>';
			}
       }
	    commonXHR.send(null);
	   	   
	//alert(xhr.responseText);	
	
}

function loanCalculations() {
	var qString = '';
	qString += 'contract_price=' + document.getElementById('contract_price').value;
	qString += '&option1=' + document.getElementById('grace_period').value;
	qString += '&option2=' + document.getElementById('grace_prinicipal').value;
	qString += '&option3=' + document.getElementById('grace_scheduled_payments').value;
	qString += '&option4=' + document.getElementById('scheduled_pay_grace_period').value;
	qString += '&loan_duration=' + document.getElementById('loan_years').value;
	qString += '&interest_rate=' + document.getElementById('interest_rate').value;
	qString += '&loan_start_date=' + document.getElementById('loan_start_date').value;	
	qString += '&loan_amount=' + document.getElementById('loan_amount').innerHTML;	
	
	//************************************************************************************************************************//
	//*******************************************************MARIANNE ANGELIDES***********************************************//
	//*******************************************************DATE:18 MARCH 2008***********************************************//
		
		qString += '&loan_end_date_hidden=' + document.getElementById('loan_end_date_hidden').value;
		qString += '&development=' + document.getElementById('development').value;
		qString += '&unit_hidden=' + document.getElementById('unit_hidden').value;
		qString += '&property_type=' + document.getElementById('property_type').value;
		qString += '&contractPrice=' + document.getElementById('contract_price').value;
		qString += '&contract_price_hidden=' + document.getElementById('contract_price_hidden').value;
		qString += '&delivery_date=' + document.getElementById('delivery_date').value;
		qString += '&contract_date=' + document.getElementById('contract_date').value;
		qString += '&client_name=' + document.getElementById('client_name').value;
		qString += '&client_currency_hidden=' + document.getElementById('client_currency_hidden').value;
		qString += '&monthly_income=' + document.getElementById('monthly_income').value;
		qString += '&other_mortgage_install=' + document.getElementById('other_mortgage_install').value;
		qString += '&clients_age=' + document.getElementById('clients_age').value;
		qString += '&client_properties=' + document.getElementById('client_properties').value;
		qString += '&bank_chosen=' + document.getElementById('bank_chosen').value;
		qString += '&installment_to_income=' + document.getElementById('installment_to_income').value;
		qString += '&maximum_instalments_client=' + document.getElementById('maximum_instalments_client').value;
		qString += '&loan_curr_hidden=' + document.getElementById('loan_curr_hidden').value;
		qString += '&maximum_instalments_loan=' + document.getElementById('maximum_instalments_loan').value;
		qString += '&interest_rate=' + document.getElementById('interest_rate').value;
		qString += '&exchange_rate=' + document.getElementById('exchange_rate').value;
		qString += '&client_contribution_perc=' + document.getElementById('client_contribution_perc').value;
		qString += '&client_contribution=' + document.getElementById('client_contribution').innerHTML;
		qString += '&finance_perc=' + document.getElementById('finance_perc').value;
		//added by J.Mammous/P.Petrou in consideration of the fact that the scheme in question may not be offering compound interest
		//but APR
		qString += '&interest_rate_type=' + document.getElementById('interest_rate_type').value;
		qString += '&schemeID=' + document.getElementById('schemeID').value;
		
		
	
//*****************************************************END:MARIANNE ANGELIDES***********************************************//
	
	commonXHR.open("POST", "loan.php", true);
	commonXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	commonXHR.setRequestHeader("Content-length", qString.length);	
		commonXHR.onreadystatechange  = function()
    	{ 
         	if(commonXHR.readyState  == 4)
         	{
			//window.open('test.php');
			fireMyPopup();
			//document.getElementById("styled_popup").style.display = "block";
			document.getElementById("styled_popup").innerHTML = (commonXHR.responseText);
			
			}
       }
	    commonXHR.send(qString);
	
	//end function
}

function genericTransAlertFunction(actionPage) {
	
	commonXHR.open("GET", actionPage, true);
		
	commonXHR.onreadystatechange  = function()
    { 
         if(commonXHR.readyState  == 4)
         {
			 //document.getElementById("uniqueDiv").innerHTML = xhr.responseText;
			alert(commonXHR.responseText);
			 
         }
    }
	
	   commonXHR.send(null);
	
}

//JMAMMOUS