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

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


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

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

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

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


function genericInnerHTMLFunction(actionPage, langPref) {
	//alert(actionPage);
	xhr.open("GET", actionPage);		
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
				var successAlert = xhr.responseText;
				var successString = successAlert.substring(0,1);
				
				if(successString == '0') {
				
				document.getElementById("addAgentSubmit").disabled = true;
				
			} 
			if(successString == '1') {
				
				document.getElementById("addAgentSubmit").disabled = false;
				
			}
				document.getElementById("uniqueDiv").innerHTML = successAlert.substring(1, successAlert.length);
			 //alert(xhr.responseText);
			 
         }
    }
	
	    xhr.send(null);
	//alert(xhr.responseText);	
	
}

function genericPersonnelInnerHTMLFunction(actionPage, langPref, elemID) {
		//alert(elemID);
	xhr.open("GET", actionPage);		
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
				var successAlert = xhr.responseText;
				var successString = successAlert.substring(0,1);
				
				if(successString == '0') {
				
				document.getElementById(elemID).disabled = true;
				
			} 
			if(successString == '1') {
				
				document.getElementById(elemID).disabled = false;
				
			}
				document.getElementById("uniqueDiv").innerHTML = successAlert.substring(1, successAlert.length);
			 //alert(xhr.responseText);
			 
         }
    }
	
	    xhr.send(null);
	//alert(xhr.responseText);	
	
}

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

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

function addAgentInsert(actionPage, qString) {
	//with this function we are using a POST, special consideration has to be paid to this.
	//if sending a javascript error alert from the checkforms for incorrect client data
	//the headers will be affected and thenthis ajax function will show the resulting page in a 
	//message pop up box.
	//we therefore exit the page within the PHP db_Procs.php to the messagepipe.php and simply
	//update the displaydivs using the responseText
	xhr.open("POST", actionPage, true);
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xhr.setRequestHeader("Content-length", qString.length);
	
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4 && xhr.status == 200)
         {
		//other methods of displaying the info
		// 1)location.href= xhr.responseText;
		//2) listed below this line
		document.getElementById("displayDiv").innerHTML = xhr.responseText;
		} else {
		return false; 
	} 
	}
	xhr.send(qString);
	//return xhr;	
	
}

function addPersonnelInsert(actionPage, qString) {
	//alert(qString);
	//with this function we are using a POST, special consideration has to be paid to this.
	//if sending a javascript error alert from the checkforms for incorrect client data
	//the headers will be affected and thenthis ajax function will show the resulting page in a 
	//message pop up box.
	//we therefore exit the page within the PHP db_Procs.php to the messagepipe.php and simply
	//update the displaydivs using the responseText
	xhr.open("POST", actionPage, true);
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xhr.setRequestHeader("Content-length", qString.length);
	
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4 && xhr.status == 200)
         {
		//other methods of displaying the info
		// 1)location.href= xhr.responseText;
		//2) listed below this line
		document.getElementById("displayDiv").innerHTML = xhr.responseText;
		} else {
		return false; 
	} 
	}
	xhr.send(qString);
	//return xhr;	
	
}

function globalResponseWriter(actionPage, divTarget1, divTarget2, divTarget3, divTarget4, divTarget5, divORText) {
	//alert(actionPage);
	//can be used to write to a text box or a div
	xhr.open("GET", actionPage);		
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
			 var rawItems = xhr.responseText.split("||");
			 var primaryInput = document.getElementById(divTarget1);
			 var secondaryInput = document.getElementById(divTarget2);
			 var tertiaryInput = document.getElementById(divTarget3);
			 var fourthInput = document.getElementById(divTarget4);
			 var fifthInput = document.getElementById(divTarget5);
			 if(divORText == 'value') {
				 primaryInput.value = rawItems[0]
				 secondaryInput.value = rawItems[1];
				 tertiaryInput.selectedIndex = rawItems[2];
				 fourthInput.value = rawItems[3];
				 fifthInput.value = rawItems[4];
			 } else {
				 document.getElementById('displayDiv').innerHTML = xhr.responseText;
			 }
			 
         }
    }
	
	    xhr.send(null);
	//alert(xhr.responseText);	
	
}


function personnelAgentSeekResponseWriter(actionPage, divTarget) {
	//reset company specific fields that might exist on the form
	resetCompanyFields();
	
	//alert(actionPage);
    xhr.open("GET", actionPage);		
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
			document.getElementById("personnelAddressCopy").disabled = true;
			document.getElementById("findAgentsDiv").innerHTML = xhr.responseText;
			
			 //alert(xhr.responseText);
			 
         }
    }
	
	    xhr.send(null);
	//alert(xhr.responseText);	
	
}


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

function toggleInnerHTML(divName, actionPage) {
	if(document.getElementById(divName).innerHTML == "") {
		xhr.open("GET", actionPage);
		xhr.onreadystatechange  = function()
    	{ 
         	if(xhr.readyState  == 4)
         	{
			document.getElementById(divName).innerHTML = xhr.responseText;
			}
       }
	    xhr.send(null);
	   
	   } else {
			document.getElementById(divName).innerHTML = "";
			}
	
	   
	//alert(xhr.responseText);	
	
}

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

function editMyAccount (actionPage, qString) {
	xhr.open("POST", actionPage, true);
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xhr.setRequestHeader("Content-length", qString.length);	
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4 && xhr.status == 200)
         {
		//other methods of displaying the info
		// 1)location.href= xhr.responseText;
		//2) listed below this line
		//alert('posted');
		document.getElementById("displayDiv").innerHTML = xhr.responseText;
		} else {
		return false; 
	} 
	}
	xhr.send(qString);
	
	//end function
}



//***Author: JMAMMOUS***
//***Date: Feb 11 2009***


//********************************Author:Marianne Angelides**************************************************
//***********************************Date: 9 February 2009****************************************************/

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


function findProps(actionPage) {
	document.getElementById("showProps").innerHTML = '<img src="../images/loadingGif.gif" width="40" height="40"/>';
	if(document.getElementById("project_name").value != "") {
	//alert(actionPage);
	xhr.open("GET", actionPage);		
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
			 var propInfo = "http://www.pafiliapartners.com/search/search.php?showOne=1&devID="+document.getElementById('project_name').value;
			 //document.getElementById("displayDev").innerHTML =  "<a href=" + propLink + " class='orange' target='_blank'>View Project</a><br>";
			 var propLink = "http://www.pafiliapartners.com/common/folders.php?img=1.jpg&logo=0.jpg&imgSize=18&logoSize=18&devID="+document.getElementById('project_name').value;
			 var imgPath = "<img src='" + propLink + "' border='1' align='middle' title='Click for information on this development'/>";
			 document.getElementById("displayDev").innerHTML =  "<a href=" + propInfo + " class='orange' target='_blank'>" + imgPath + "</a><br>"
			 document.getElementById("showProps").innerHTML = xhr.responseText;
			 document.getElementById("showType").innerHTML = "";
			 //alert(xhr.responseText);
         }
    }
	
	    xhr.send(null);
	//alert(xhr.responseText);	
	} else { 
	document.getElementById("displayDev").innerHTML = "";
	document.getElementById("showProps").innerHTML = "";
	document.getElementById("showType").innerHTML = "";
	return false;
	}
}


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

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

function findBankCurrency(actionPage, cAge) {
	document.getElementById("showBankCurrency").innerHTML = '<img src="../images/loadingGif.gif" width="40" height="40"/>';
	//alert(actionPage);
	xhr.open("GET", actionPage);		
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
			 //var results = xhr.responseText.split("||");
			 document.getElementById("showBankCurrency").innerHTML = xhr.responseText;
			 validateEnteredAge(cAge);
			 //enableElement(document.getElementById("bank_name").value, 'clients_age');
			 //document.getElementById("showBankMaxAge").innerHTML = results[1];
			 //alert(xhr.responseText);
         }
    }
	
	    xhr.send(null);
	//alert(xhr.responseText);	
	
}

function findInterestRateCurrency(actionPage) {
	
	
	document.getElementById("showInterestRate").innerHTML = '<img src="../images/loadingGif.gif" width="40" height="40"/>';
	
	//alert(actionPage);
	xhr.open("GET", actionPage);		
	xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
			 
			 document.getElementById("showInterestRate").innerHTML = xhr.responseText;
			
			if(document.getElementById('bank_currency').value != "") {
				var currencyCode = document.getElementById('bank_currency').selectedIndex;
				currencyCode = document.getElementById('bank_currency').options[currencyCode].text;
				currencyCode = currencyCode.substring(0,3);
				document.getElementById('loanMaxInstallCurr').value = currencyCode;
				document.getElementById('initContrCurr').value = currencyCode;
				document.getElementById('financeCurr').value = currencyCode;
				clientToLoanConversion();
			 //copyIt(currencyCode, 'loanMaxInstallCurr' );
			 //copyIt('bank_currency' , 'initContrCurr');
			// copyIt('bank_currency' , 'financeCurr');
			  //document.getElementById('exchange_rate').value = document.getElementById('bank_currency').value;
			} else {
				
				copyIt('bank_currency', 'loanMaxInstallCurr' );
				copyIt('bank_currency' , 'initContrCurr');
				copyIt('bank_currency' , 'financeCurr');
				document.getElementById('exchange_rate').value = document.getElementById('bank_currency').value;
			}
         }
    }
	
	    xhr.send(null);
	//alert(xhr.responseText);	
	
}

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




//*************************************End:Marianne Angelides**************************************************/

