var req;
function importContacts()
{
	this.Update = function( page, msg , pageName)
	{
	 	
		var loc = encodeURIComponent(window.location.href);
		
		req = new Ajax.Request('inviteFriends.php',
		{
			method:'post',
			parameters:'action='+page+'&msg='+msg+'&pageName='+pageName+'&LocationHeader='+loc,
			onSuccess: function(Response)
			{
				$('page_overlay_box').style.width = '500px';
				$('page_overlay_box').style.height = '20px';
				$('page_overlay_box').update(Response.responseText);
				center('page_overlay_box',500,20);
				$('image_overlay').hide();
				$('page_overlay_box').show();
				
/*				var editFormWrap = document.getElementById( 'page_overlay_box' );
				editFormWrap.style.width   = 500;//document.body.clientWidth + 30 + "px";
				editFormWrap.style.height  = 20;//(window.innerHeight ? (window.innerHeight + 30) : screen.height) + "px";			
				
				editFormWrap.style.left    = 100;//getHorizScroll() - 30 + "px";
				editFormWrap.style.top     = 200;//getVertScroll() - 30 + "px";
				editFormWrap.style.display = 'block';
				editFormWrap.innerHTML = Response.responseText;*/
			},
			onLoading:function()
			{
				showBox();
			},
			onFailure:function()
			{
				alert('fail');
				hideBox();
			}
		});
	}
	
	this.Send = function( url, msg )
	{
	 	//alert(url);
		var loc = encodeURIComponent(window.location.href);
		req = new Ajax.Request('inviteFriends.php',
		{
		 	
			method:'post',
			parameters:url+'&LocationHeader='+loc,
			onSuccess: function(Response)
			{
				$('page_overlay_box').style.width = '300px';
				$('page_overlay_box').style.height = '20px';
				$('page_overlay_box').update(Response.responseText);
				center('page_overlay_box',300,20);
				$('image_overlay').hide();
				$('page_overlay_box').show();
			},
			onLoading:function()
			{
				showBox();
			},
			onFailure:function()
			{
				alert('fail');
				hideBox();
			}
		});
	}

	this.CheckFields = function()
	{
		/*var PhotoTitle = document.getElementById('PhotoTitle').value;
		PhotoTitle = PhotoTitle.replace(/^\s*|\s(?=\s)|\s*$/g, "");
		if(PhotoTitle.length >1 && PhotoTitle!='')
		{
			$('EditButton').disable();
			$('CancelButton').disable();
			return true;
		}
		else
		{
			return false
		}*/
		return false;
	}
	this.cancel = function()
	{
		req.transport.abort();
	$('page_overlay_box').style.width = '0%';
	$('page_overlay_box').style.height = '0%';
	$('page_overlay_box').update('');
	$('page_overlay_box').hide();
	hideBox();
		
	}
}

function Cancel(req)
{
	req.transport.abort();
	$('page_overlay_box').style.width = '0%';
	$('page_overlay_box').style.height = '0%';
	$('page_overlay_box').update('');
	$('page_overlay_box').hide();
	hideBox();
}

function addAddresses(num){
	for(var j=0; j<num; j++){
		if(document.getElementById('emailaddresses_'+j).checked == true){
			addFriendName(document.getElementById('emailaddresses_'+j).value, 'friendsEmail')
		}
	}
	req.transport.abort();	
	$('page_overlay_box').style.width = '0%';
	$('page_overlay_box').style.height = '0%';
	$('page_overlay_box').update('');
	$('page_overlay_box').hide();
	//showSelectBoxes();
	hideBox();
}

function addFriendName(id, fieldName){
fieldName = 'txtemails';
var tmpData=document.getElementById(fieldName).value;
		var tmpArray  = new Array();
		var arrCount = 0;
		if(tmpData !="" && tmpData != null ){
			tmpArray = tmpData.split(" , ");	
			arrCount =  tmpArray.length;
		}
		var action =  true;
		for(var i=0; i<arrCount; i++){
			if(tmpArray[i]== id)
				action = false;
		}
		if(action)
			tmpArray[arrCount]= id;
		var tmpVal = tmpArray.join(' , ');
		document.getElementById(fieldName).value = tmpVal;
}
var impContact = new importContacts();