// JavaScript Documentvar xmlHttp
var xmlHttp

function do_import(){
	var importer=document.getElementById('importer').value;
	var login=document.getElementById('login').value;
	var password=document.getElementById('password').value;
	var icontact= document.getElementById('contact');	
	var xmlhttp = GetXmlHttpObject();
	  //xmlhttp = xmlhttp_init();
	  xmlhttp.open("GET", "tools.php?iact=clogin&id="+importer+"&login="+login+"&pass="+password,true);
	  xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) 
		{
			icontact.innerHTML=xmlhttp.responseText;
			alert(xmlhttp.responseText);
		}
	  }
	  xmlhttp.send(null)		
}

function showLoginForm(importer){
	
	var iform = document.getElementById('login_form_div');
	
	var xmlhttp = GetXmlHttpObject();
	  //xmlhttp = xmlhttp_init();
	  xmlhttp.open("GET", "tools.php?iact=cform&id="+importer,true);
	  xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) 
		{
			iform.innerHTML=xmlhttp.responseText;
			//alert(xmlhttp.responseText);
		}
	  }
	  xmlhttp.send(null)		
}

function setVisible(id,visible){
		
  //var xmlhttp = "";
	  var xmlhttp = GetXmlHttpObject();
	  //xmlhttp = xmlhttp_init();
	  xmlhttp.open("GET", "tools.php?iact=visible&id="+id+"&visible="+visible,true);
	  xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) 
		{
			window.location.reload();
	
		}
	  }
	  xmlhttp.send(null)		
}

function ihelp(id){
		var ihelp = document.getElementById('ihelp');	
  //var xmlhttp = "";
	  	var xmlhttp = GetXmlHttpObject();
	  //xmlhttp = xmlhttp_init();
	  xmlhttp.open("GET", "tools.php?iact=help&id="+id,true);
	  xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) 
		{
			ihelp.innerHTML="<p align=\"justify\">"+xmlhttp.responseText;+"</p>";
	
		}
	  }
	  xmlhttp.send(null)	
}

function purge_mail(){
	var xmlhttp = GetXmlHttpObject();
	  //xmlhttp = xmlhttp_init();
	  xmlhttp.open("GET", "tools.php?iact=purge",true);
	  xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) 
		{
			alert(xmlhttp.responseText);
	
		}
	  }
	  xmlhttp.send(null)	
}


function SetReadTag(id,memberid)
{
  //var xmlhttp = "";
  var xmlhttp = GetXmlHttpObject();
  //xmlhttp = xmlhttp_init();
  xmlhttp.open("GET", "readtag.php?id="+id+"&member="+memberid,true);
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) 
    {
		window.location.reload();
    }
  }
  xmlhttp.send(null)
}



function squeeze(){
	
	//alert('hi');
	
	var jsdiv = document.getElementById('js_div');
	id= document.getElementById('productID').value;
	email= document.getElementById('email').value;
  	var xmlhttp = GetXmlHttpObject();
  //xmlhttp = xmlhttp_init();
  xmlhttp.open("GET", "squ3rdparty.php?id="+id+"&email="+email,true);
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) 
    {
			
		var rt_split = 	xmlhttp.responseText;
		
		ar_temp=rt_split.split("[]");
		
		if (ar_temp[0]=='addnew'){	
			jsdiv.innerHTML=xmlhttp.responseText;
			document.form_post.submit();
		} 
		
		if (ar_temp[0]=='postnew'){		
			document.form_squeeze.submit();
		} 
		
		if (ar_temp[0]=='postoto'){		
			window.location.href=ar_temp[1];
		}
		
    }
  }
  xmlhttp.send(null)

}

function register(id,memberid,oto,pname)
{
  //var xmlhttp = "";
  var jsdiv = document.getElementById('js_div');
  var wait = document.getElementById('wait'+id);
  var xmlhttp = GetXmlHttpObject();
  //xmlhttp = xmlhttp_init();
  xmlhttp.open("GET", "reg3rdparty.php?id="+id+"&member="+memberid,true);
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) 
    {
		
		wait.innerHTML='';
		jsdiv.innerHTML=xmlhttp.responseText;
		
		if (xmlhttp.responseText!='none' && xmlhttp.responseText!='addnew'){			
			alert('We have sent you an email to confirm your your registration of this product. When you click the verification link in it, your new product will be added to your collection.\n\nIn the meantime, please read the following page carefully...');	
			window.open(oto,'','');
			document.form_post.submit();
		} 
		
		if (xmlhttp.responseText=='addnew'){		
		alert('We have sent you an email to confirm your your registration of this product. Please look out for it in your inbox. In the meantime, please read the following page carefully.');
			window.open(oto,'','');
			window.location.reload();	
		} 
    } else
	{
		wait.innerHTML='<img src="images/indicator.gif">';		
	}
  }
  xmlhttp.send(null)
}

function showField(tp,id)
{
	var opdf = document.getElementById('onlinepdf');
	if (tp=='PDFONLINE'){	
  //var xmlhttp = "";
	  var xmlhttp = GetXmlHttpObject();
	  //xmlhttp = xmlhttp_init();
	  xmlhttp.open("GET", "showfield.php?id="+id,true);
	  xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) 
		{
			//window.location.reload();
			opdf.innerHTML=xmlhttp.responseText;
			//window.open(oto,'','');
			
			
			showDiv('PDFONLINE');
	
		}
	  }
	  xmlhttp.send(null)
	} else {
		opdf.innerHTML="";
		showDiv('REBRANDER');
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


