function loadXMLString(txt) {
	try{ //Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(txt);
		return(xmlDoc);  
	}catch(e){
		try {//Firefox, Mozilla, Opera, etc.
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(txt,"text/xml");
			return(xmlDoc);
		}catch(e) {alert(e.message)}
	}
	return(null);
}
var countf = "546";   //Example: var count = "175";
function invite_limit(){
	var tex = document.openinviter.friend_msg_to_send.value;
	var len = tex.length;
	if(len > countf)	{
		tex = tex.substring(0,countf);
		document.openinviter.friend_msg_to_send.value =tex;
		return false;
	}
	document.openinviter.limitemail.value = countf-len;
}
//document.frm_ask.limit.value = count
	function update_dynamic_content(){
			content = document.openinviter.friend_msg_to_send.value;
			con=content.split("\n")
			con_str=''
			for(j=0;j<con.length;j++){	con_str+=con[j] + '<br />';		}
			document.getElementById('preview_dynamic_content').innerHTML = con_str; 
		}
	function toggleAll(element) {
			var form = document.forms.openinviter1, z = 0;
			for(z=0; z<form.length;z++){
				if(form[z].type == 'checkbox')
					form[z].checked = element.checked;
			}
	}
	function update_preview_to(){
					to_email_str = '';
						recieverEmail = eval("document.openinviter.contacte");
						if(recieverEmail.value!=''){
							to_email_str += recieverEmail.value + ", ";
						}
				
					document.getElementById('preview_to').innerHTML = to_email_str;
				}


	function do_process_Invites(){
		//alert(frm.value); return false;
		//document.openinviter_step2.offerid.value= document.frmAlert1.oID.value;
		/*var AJAX_SITE_REQUEST_URL = '';
		if(window.location.href.indexOf("vsharma")>0){
				SITE_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
		}else if(window.location.href.indexOf("66.148.13.116")>0){		
				SITE_URL = "http://" + window.document.domain + "/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/ajax_actions/offers/";
		}else{	SITE_URL = "http://" + window.document.domain + "/beta1/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/beta1/ajax_actions/offers/";		}
		*/
		queryString = '';
		with(document.openinviter_step2){
			for(i=0;i<document.openinviter_step2.elements.length;i++){
				key = document.openinviter_step2.elements[i].name;
				value = document.openinviter_step2.elements[i].value;
				if(document.openinviter_step2.elements[i].name.indexOf("[]")>0){
					if(document.openinviter_step2.elements[i].checked){
						queryString += "&" + key + "=" +value ;
						
					}
				}else{
					queryString += "&" + key + "=" +value ;
					
				}
			}
		}
		//alert(queryString);return false;
		$.ajax({ method: "post",
				/*url: AJAX_SITE_REQUEST_USERS_URL+"import_contacts_ver1.php",*/
				url: AJAX_SITE_REQUEST_OFFERS_URL+"import_contacts_ver1.php",
				data: queryString ,
				beforeSend: function(){}, //show loading just when link is clicked
				complete: function(){ }, //stop showing loading when the process is complete
				success: function(html){ //so, if data is retrieved, store it in html.
				$("#ImportContactsContent").html(html);
				//alert(url);
			}
		});
	}

 /* function invite_all(){
	var AJAX_SITE_REQUEST_URL = '';
	if(window.location.href.indexOf("vsharma")>0){
			SITE_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
	}else if(window.location.href.indexOf("66.148.13.116")>0){		
			SITE_URL = "http://" + window.document.domain + "/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/ajax_actions/offers/";
	}else{	SITE_URL = "http://" + window.document.domain + "/beta1/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/beta1/ajax_actions/offers/";		}
	queryString = '';
	with(document.openinviter_step2){
		   
		for(i=0;i<document.openinviter_step2.elements.length;i++){
			key = document.openinviter_step2.elements[i].name;
			
			value = document.openinviter_step2.elements[i].value;
			<!--invited=invite;-->
			if(document.openinviter_step2.elements[i].name.indexOf("[]")>0){
				if(document.openinviter_step2.elements[i].checked){
					
					queryString += "&" + key + "=" +value +"&" + "invite_action" + "=" + "send_email_contacts";
				   //alert(queryString);  + "invite"+ "="+invited 
				}
			}else{
				     
				queryString += "&" + key + "=" +value + "&" + "invite_action" + "= " + "send_email_contacts" ;
			    //alert(queryString);+ "invite"+ "="+invited 
			}
		}
	}
	$.ajax({ method: "post",
			url: AJAX_SITE_REQUEST_USERS_URL+"import_contacts1.php",
			data: queryString ,
			beforeSend: function(){}, //show loading just when link is clicked
			complete: function(){ }, //stop showing loading when the process is complete
			success: function(html){ //so, if data is retrieved, store it in html.
			$("#ImportContactsContent").html(html);
		}
	});
  }


function request_all(){
	var AJAX_SITE_REQUEST_URL = '';
	if(window.location.href.indexOf("vsharma")>0){
			SITE_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
	}else if(window.location.href.indexOf("66.148.13.116")>0){		
			SITE_URL = "http://" + window.document.domain + "/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/ajax_actions/offers/";
	}else{	SITE_URL = "http://" + window.document.domain + "/beta1/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/beta1/ajax_actions/offers/";		}
	queryString = '';
	with(document.openinviter_step2){
		for(i=0;i<document.openinviter_step2.elements.length;i++){
			key = document.openinviter_step2.elements[i].name;
			value = document.openinviter_step2.elements[i].value;
			<!--invited=request;-->
			if(document.openinviter_step2.elements[i].name.indexOf("[]")>0){
				if(document.openinviter_step2.elements[i].checked){
					
					queryString += "&" + key + "=" +value +"&" + "invite_action" + "=" + "send_request_to_all";
				   // + "invite"+ "="+invited 
				}
			}else{
				queryString += "&" + key + "=" +value +"&" + "invite_action" + "=" + "send_request_to_all" ;
			   // + "invite"+ "="+invited 
			}
		}
	}
	$.ajax({ method: "post",
			url: AJAX_SITE_REQUEST_USERS_URL+"import_contacts1.php",
			data: queryString ,
			beforeSend: function(){}, //show loading just when link is clicked
			complete: function(){ }, //stop showing loading when the process is complete
			success: function(html){ //so, if data is retrieved, store it in html.
			<!--$("#ImportContactsContent").html(html);-->
		     $("#importRequestAll").html("");
			$("#importRequestAll").slideUp();
			$("#importRequestAll").html(html);
			
			$("#importRequestAll").slideDown("slow");
		
		}
	});
  }


*/


///short Invitation
function do_short_Invites(){
	var AJAX_SITE_REQUEST_URL = '';
		/*if(window.location.href.indexOf("vsharma")>0){
				SITE_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
		}else if(window.location.href.indexOf("66.148.13.116")>0){		
				SITE_URL = "http://" + window.document.domain + "/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/ajax_actions/offers/";
		}else{	SITE_URL = "http://" + window.document.domain + "/beta1/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/beta1/ajax_actions/offers/";		}
		*/	
		$queryString = '';
		importWhich = "";
		with(document.openinviter){
			importWhich = contacte.value +friend_msg_to_send.value;
			queryString = 'action=user&task=invite&invite_action=invite&contacte='+contacte.value+"&friend_msg_to_send="+friend_msg_to_send.value;
			alert(queryString);
		}
		$.ajax({ method: "post",
			url: AJAX_SITE_REQUEST_OFFERS_URL+"short_invite.php",
			data: queryString ,
			beforeSend: function(){}, //show loading just when link is clicked
			complete: function(){ }, //stop showing loading when the process is complete
			success: function(){ //so, if data is retrieved, store it in html
			}
	});
}
///
  
   function add_request(email,tot){
    /*var AJAX_SITE_REQUEST_URL = '';
	if(window.location.href.indexOf("vsharma")>0){
				SITE_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
	}else if(window.location.href.indexOf("66.148.13.116")>0){		
			SITE_URL = "http://" + window.document.domain + "/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/ajax_actions/offers/";
	}else{		SITE_URL = "http://" + window.document.domain + "/beta1/";
				AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/beta1/ajax_actions/offers/";		}
	*/
	queryString = '';
	
	with(document.openinviter_step2){
		email=email;
	   // alert(email);
		//alert(tot);
      queryString='action=user&task=invite&invite_action=request&mail='+email;
	   alert(queryString);
	}
$.ajax({ method: "post",
			url: AJAX_SITE_REQUEST_OFFERS_URL+"add_friends.php",
			data: queryString ,
			beforeSend: function(){ $("#import_message_processing1").show("fast")}, //show loading just when link is clicked
			complete: function(){ $("#import_message_processing1").hide("fast") },  
			
			success: function(html){ //so, if data is retrieved, store it in html
			$("#importMessageProcessing1" + tot).html("");
			$("#importMessageProcessing1" + tot).slideUp();
			$("#importMessageProcessing1" + tot).html(html);
			
			$("#importMessageProcessing1" + tot).slideDown("slow");
			$("#btnAdd"+tot).hide("fast");
			}
	});	
 }

function invite_friend(email,cnt){
  	/*var AJAX_SITE_REQUEST_URL = '';
	if(window.location.href.indexOf("vsharma")>0){
			SITE_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
	}else if(window.location.href.indexOf("66.148.13.116")>0){		
			SITE_URL = "http://" + window.document.domain + "/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/ajax_actions/offers/";
	}else{	SITE_URL = "http://" + window.document.domain + "/beta1/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/beta1/ajax_actions/offers/";		}
	*/
	queryString = '';
	
	with(document.openinviter_step2){
		email=email;
	    //alert(email);
		//alert(cnt);
      queryString='action=user&task=invite&invite_action=invite&mail='+ email;
	    // alert(queryString);
	}
            $.ajax({ method: "post",
			/*url: AJAX_SITE_REQUEST_USERS_URL+"add_friends.php",*/
			url: AJAX_SITE_REQUEST_OFFERS_URL+"add_friends.php",
			data: queryString ,
			beforeSend: function(){ $("import_message_processing").show("fast")}, //show loading just when link is clicked
			complete: function(){ $("#import_message_processing").hide("fast") }, 
			complete: function(){ }, //stop showing loading when the process is complete
			success: function(html){ //so, if data is retrieved, store it in html
			$("#importMessageProcessing"+ cnt).html("");
			$("#importMessageProcessing"+ cnt).slideUp();
			$("#importMessageProcessing" + cnt).html(html);
			
			$("#importMessageProcessing" + cnt).slideDown("slow");
			$("#btnRequest"+cnt).hide("slow");
			//alert("hi");
			//alert(html);
			}
	});	
 }	

function do_back_invites(frm){
	$("#importContactsOf").html("");
	$("#importContactsOf").hide();
	$("#inviterFormRight").slideDown("slow");
	$("#ImportContactsContent").slideUp();
	
}
function do_preview_invitation(frm){
	$("#ImportContactsContent").slideUp("slow");
	$("#inviterFormRight").slideUp("slow");
}
if(typeof("toggleAll_ver1")!="function"){
	function toggleAll_ver1(frm){
		with(frm){
			todo_status = toggle_all.checked
			if(elements.length>0){
				for(i=0;i<elements.length;i++){
					if(elements[i].type.toLowerCase()=='checkbox'){
						elements[i].checked = todo_status;
					}
				}
			}// End If
		}// End With
	}
}

$(document).ready(function(){
	/*var AJAX_SITE_REQUEST_URL = '';
	if(window.location.href.indexOf("vsharma")>0){
			SITE_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/bolega/ajax_actions/offers/";
	}else if(window.location.href.indexOf("66.148.13.116")>0){		
			SITE_URL = "http://" + window.document.domain + "/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/ajax_actions/offers/";
	}else{	SITE_URL = "http://" + window.document.domain + "/beta1/";
			AJAX_SITE_REQUEST_USERS_URL = "http://" + window.document.domain + "/beta1/ajax_actions/offers/";		}
	*/
	$("#btnImportContacts").click(function(event){
		event.preventDefault(); 
		$queryString = '';
		importWhich = "";
		with(document.openinviter1){
			//importWhich = username.value + "@"+domain.value;
			queryString = 'action=user&task=invite&invite_action=invite&email_box='+username.value+"&provider_box="+provider_box.value+"&password_box="+password.value+"&step="+step.value;
			//alert(queryString);	return false;
		}
       	
		
		$.ajax({	method: "post",
					/*url: AJAX_SITE_REQUEST_USERS_URL+"import_contacts_ver1.php",*/
					url: AJAX_SITE_REQUEST_OFFERS_URL+"import_contacts_ver1.php",
					
					data: queryString ,
					beforeSend: function(){ $("#importContactsOf").html(importWhich); $("#importContactsOf").show();  $("#import_contacts_processing").show()}, //show loading just when link is clicked
					complete: function(){ $("#import_contacts_processing").hide() }, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
						$("#ImportContactsContent").html("");
						$("#inviterFormRight").slideUp();
						$("#ImportContactsContent").html(html);
						$("#ImportContactsContent").slideDown("slow");
						
						//alert(url);
					}
					
		    });
	   });
    $("#btnImportsContact").click(function(event){
		event.preventDefault(); 
		$queryString = '';
		importWhich = "";
		with(document.openinviter1){
			importWhich = username.value + "@"+domain.value;
			queryString = 'action=user&task=invite&invite_action=invite&username='+username.value+"&domain="+domain.value+"&password="+password.value;
			//alert(queryString);
		}
    $.ajax({	method: "post",
					/*url: AJAX_SITE_REQUEST_USERS_URL+"import_contacts1.php",*/
					url: AJAX_SITE_REQUEST_OFFERS_URL+"import_contacts1.php",
					data: queryString ,
					beforeSend: function(){ $("#importContactsOf").html(importWhich); $("#importContactsOf").show();  $("#import_contacts_processing").show()}, //show loading just when link is clicked
					complete: function(){ $("#import_contacts_processing").hide() }, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
						$("#ImportContactsContent").html("");
						$("#inviterFormRight").slideUp();
						$("#ImportContactsContent").html(html);
						$("#ImportContactsContent").slideDown("slow");
					}
		    });
	   });										   
   
});
