/*
* Sets position of div1 relatively div2 
*
*/
function setposition(divId1, divId2){
	var div1Obj = document.getElementById(divId1);
	var div2Obj = document.getElementById(divId2);
	div1Obj.style.top = '100px'; // or something related with => div2Obj.offsetTop 
	div1Obj.style.left = 650+div2Obj.offsetLeft+'px';
}

var ajax;
var resultDiv;


function loginRegAjaxCall(myparams){
	ajax = new Ajax.Request('/login-reg-ajax.php', {parameters: myparams, onSuccess:handlerFunc, onFailure:errFunc});
}

function voteAjaxCall(myparams){

	ajax = new Ajax.Request('/vote-ajax.php', {parameters: myparams, onSuccess:VoteHandFunc, onFailure:errFunc});
}

function tagAjaxCall(myparams){

	ajax = new Ajax.Request('/tags-ajax.php', {parameters: myparams, onSuccess:TagHandFunc, onFailure:errFunc});
}

function commAjaxCall(myparams){

	ajax = new Ajax.Request('/comments-ajax.php', {parameters: myparams, onSuccess:CommHandFunc, onFailure:errFunc});
}

function profAjaxCall(myparams){

	ajax = new Ajax.Request('/profile-ajax.php', {parameters: myparams, onSuccess:ProfHandFunc, onFailure:errFunc});
}

function BldNxtImageAjaxCall(myparams){

	ajax = new Ajax.Request('/images-ajax.php', {parameters: myparams, onSuccess:ImgHandFunc, onFailure:errFunc});
}

function BldNxtPageAjaxCall(myparams){

	ajax = new Ajax.Request('/images-ajax.php', {parameters: myparams, onSuccess:PageHandFunc, onFailure:errFunc});
}

function NikHintAjaxCall(myparams){

	ajax = new Ajax.Request('/hint-ajax.php', {parameters: myparams, onSuccess:HintHandFunc, onFailure:errFunc});
}

function availAjaxCall(myparams){

	ajax = new Ajax.Request('/add-availability-ajax.php', {parameters: myparams, onSuccess:AvailHandFunc, onFailure:errFunc});
}

function SesImgAjaxCall(myparams){

	ajax = new Ajax.Request('/session-action.php', {parameters: myparams, onSuccess:SesImgHandFunc, onFailure:errFunc});
}

function messAjaxCall(myparams){
	ajax = new Ajax.Request('/mark_mess_ajax.php', {parameters: myparams, onSuccess:orgFunc, onFailure:errFunc});
}

function checkAjaxCall(myparams){

	var my_c_params;
	my_c_params = 'form_name=' + myparams.name + '&';
	
	for(i=0;i<myparams.elements.length;i++)	my_c_params += myparams.elements[i].name + '=' + myparams.elements[i].value + '&';
		
	ajax = new Ajax.Request('/check-ajax.php', {parameters: my_c_params, onSuccess:orgFunc, onFailure:errFunc});
}

function leadAjaxCall(fn_id, ln_id, em_id, ph_id, com_id, address_id){
	var fn_val = document.getElementById(fn_id).value;
	var ln_val = document.getElementById(ln_id).value;
	var em_val = document.getElementById(em_id).value;
	var ph_val = document.getElementById(ph_id).value;
	var com_val = document.getElementById(com_id).value;
	var address_val = document.getElementById(address_id).value;
	com_val = com_val + " (Building: " + address_val + ")";
	var myparams = "fn=" + fn_val + "&ln=" + ln_val + "&em=" + em_val + "&ph=" + ph_val + "&com=" + com_val;
	ajax = new Ajax.Request('/lead-ajax.php', {parameters: myparams, onSuccess:LeadHandFunc, onFailure:errFunc});

	document.getElementById(fn_id).value = '';
	document.getElementById(ln_id).value = '';
	document.getElementById(em_id).value = '';
	document.getElementById(ph_id).value = '';
	document.getElementById(com_id).value = '';
}

function leadPopupAjaxCall(fn_id, ln_id, em_id, ph_id, com_id, address_id){
	var fn_val = document.getElementById(fn_id).value;
	var ln_val = document.getElementById(ln_id).value;
	var em_val = document.getElementById(em_id).value;
	var ph_val = document.getElementById(ph_id).value;
	var com_val = document.getElementById(com_id).value;
	var address_val = document.getElementById(address_id).value;
	com_val = com_val + " (Building: " + address_val + ")";
	var myparams = "fn=" + fn_val + "&ln=" + ln_val + "&em=" + em_val + "&ph=" + ph_val + "&com=" + com_val;
	ajax = new Ajax.Request('/lead-ajax.php', {parameters: myparams, onSuccess:LeadPopupHandFunc, onFailure:errFunc});
	
	document.getElementById(fn_id).value = '';
	document.getElementById(ln_id).value = '';
	document.getElementById(em_id).value = '';
	document.getElementById(ph_id).value = '';
	document.getElementById(com_id).value = '';
}

var orgFunc = function(t) {
	
	eval(t.responseText);
}

var handlerFunc = function(t) {
	
	if(t.responseText == "reload") { 
    	window.location.reload();
    }
	else {
    	resultDiv.innerHTML = t.responseText;
    	document.getElementById('pswd_').value = ''; 
    }
}

var VoteHandFunc = function(t) {
	
	pos1 = t.responseText.indexOf('|');
	str1 = t.responseText.substring(0, pos1);
	tmpstr = t.responseText.substring(pos1+1, t.responseText.length);
	pos2 = tmpstr.indexOf('|');
	str2 = tmpstr.substring(0, pos2);  
	str3 = tmpstr.substring(pos2+1, tmpstr.length);	
	
   	document.getElementById('up_div').innerHTML = str1; 
   	document.getElementById('dn_div').innerHTML = str2;
   	document.getElementById('vote_result').innerHTML = str3;
}
var TagHandFunc = function(t) {
	
   	document.getElementById('tag_div').innerHTML = t.responseText; 
}
var CommHandFunc = function(t) {
	
   	document.getElementById('com_div').innerHTML = t.responseText; 
}
var ProfHandFunc = function(t) {
	
   	document.getElementById('prof_div').innerHTML = t.responseText; 
}
var ImgHandFunc = function(t) {
	
   	document.getElementById('map_ph_img').innerHTML = t.responseText; 
}
var PageHandFunc = function(t) {
	
   	document.getElementById('map_ph_page').innerHTML = t.responseText; 
}
var AvailHandFunc = function(t) {
	
   	document.getElementById('avail_res').innerHTML = t.responseText; 
}
var HintHandFunc = function(t) {
	
	if (t.responseText.length > 1) {
		document.getElementById('hint_class').style.display = 'block';
   		document.getElementById('hint_class').innerHTML = t.responseText;	
	} 
	else {
		document.getElementById('hint_class').style.display = 'none';	
	}
}

var SesImgHandFunc = function(t) {
	
   	document.getElementById('upload_process_div').innerHTML = t.responseText; 
}

var LeadHandFunc = function(t) {

	document.getElementById('message_inline').innerHTML = t.responseText; 
}

var LeadPopupHandFunc = function(t) {
	
	document.getElementById('f_popupform').style.display = 'none';
	document.getElementById('message_popup').innerHTML = t.responseText; 
}


var errFunc = function(t) {
    alert('Error ' + t.status + ' -- ' + t.statusText);
}




