// JavaScript Document

var GoogleContacts_timerID = null
var GoogleContacts_timerRunning = false
var GoogleContacts_delay = 1500
var GoogleContacts_sessionid= 0
var GoogleContacts_viral_id= 0
var GoogleContacts_poll_id= 0


function GoogleContacts_OpenWindow(sessionid, viral_id, poll_id, lang){
	 GoogleContacts_sessionid=sessionid;
	 GoogleContacts_viral_id= viral_id;
	 GoogleContacts_poll_id=poll_id;
	 
	var theURL='https://ca.avenija.com/googlecontacts/GmailAdressBookImporter.aspx?sessionid=' + GoogleContacts_sessionid + '&viral_id='+ GoogleContacts_viral_id + '&poll_id=' + GoogleContacts_poll_id + '&lang=' + lang ;
	window.open(theURL,'googlecontacts','scrollbars=yes,resizable=yes,width=569,height=500');
	
	GoogleContacts_StartCheckingImportedEmails();
}


function GoogleContacts_StartCheckingImportedEmails(sessionid, viral_id, poll_id){
	
	
	GoogleContacts_CheckingImportedEmails();
	
	
}

function GoogleContacts_CheckingImportedEmails(){
	var sUrl='googlecontacts/engine_GetEmails.asp?sessionid=' + GoogleContacts_sessionid + '&viral_id='+ GoogleContacts_viral_id + '&poll_id=' + GoogleContacts_poll_id;
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, GoogleContacts_callback);
	

	GoogleContacts_timerID = self.setTimeout("GoogleContacts_CheckingImportedEmails()", GoogleContacts_delay)
}


var GoogleContacts_handleSuccess = function(o){
	if(o.responseText !== undefined){
		var res=o.responseText;
		if ( res.length>10 ){
			document.getElementById('prijatelji').innerHTML= res;

		clearTimeout(GoogleContacts_timerID);
		}
	}
}

var GoogleContacts_handleFailure = function(o){
	
	if(o.responseText !== undefined){
				document.getElementById('container').innerHTML=o.responseText;
	}
}

var GoogleContacts_callback =
{
  success:GoogleContacts_handleSuccess,
  failure: GoogleContacts_handleFailure,
  argument: { foo:"foo", bar:"bar" }
};