var vHttp = null;

if (window.XMLHttpRequest) { 
	vHttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){
	vHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function doGetSerialFromTransactionID(inObjectID, inTransaction){
	var vElem = document.getElementById(inObjectID);
	
	if (inTransaction == "BAD") {
		
		vElem.innerHTML = "<br>";
		vElem = document.getElementById('loginPassword');	
		vElem.innerHTML = "Operation Canceled<br>"; 	
		return false;
		
	} else {
		vRequest =  "../getCommandCount.php?command=getSerial&transactionid="+inTransaction;
		vHttp.open("GET", vRequest, false);
		vHttp.send(null);		
		if (vElem!=null) {
			var vHttpReq = vHttp.responseText;
			if (vHttpReq == "NotAllowed"){
				//return false;	 
			} else {
				var vHeight = 40;
				var vTop = 0;
				displaySerials(vTop, vHeight, vElem, vHttpReq);
			}
		}
		//return true;
	} 
}

function displaySerials(vTop, vHeight, vElem, vHttpReq) {

	var vProductList = vHttpReq.split("|");
	var vNbProduct = vProductList.length-1;
	var vHTML = "";	
	vHTML += "<table>";
	for (var i=0; i<vNbProduct; i++)
	{
		var vProductObj = vProductList[i].split(";");
		var vProductName = vProductObj[0];
		var vProductSerial = vProductObj[1];
		var vIdLogiciel = vProductObj[2];
		//var vEditorComments = vProductObj[3];	
		if (vProductName!="END"){
			vHTML += "<tr>";
			 
				vHTML +="<td rowspan=2 class='iconDisplay'>";
				if( vProductObj[2] != -1 ) //not the invoice
					vHTML +="<img width=30 src='/images/"+vIdLogiciel+"/"+vIdLogiciel+"_icone.jpg'></img>";
				vHTML +="</td>";
				
				vHTML +="<td class='nameDisplay'>";
				vHTML += vProductName;
				vHTML +="<td>";
			vHTML +='</tr>';
			vHTML += "<tr>";
				vHTML +="<td><div class='idDisplay'>";
				
				
				vHTML += vProductSerial;// + " " + vEditorComments;
				//vHTML += vProductSerial;
			/*	if ((vIdLogiciel == '114') || (vIdLogiciel == '116')){
						vHTML += "<br>-------------------------------- <br> You will need to go to our website and register the serial: <br> <a href='http://www.softpress.com/support/register.php'>http://www.softpress.com/support/register.php</a> <br>";
						vHTML += "And then download the latest update:<br> <a href='http://www.softpress.com/support/updates.php'>http://www.softpress.com/support/updates.php</a> <br> --------------------------------<br>";
					 } */
				vHTML +="</div></td>";
			vHTML +='</tr>';
			vHTML += "<tr style='height:20px'>";
			vHTML +="<td></td><td></td>";
			vHTML +='</tr>';
		}	 
		vTop = vTop + vHeight;	 	
	}
	vHTML += "</table>";
	vElem.innerHTML = vHTML; 
}

function doGetSerialFromUserID(inObjectID,userId,userMdp){
	
	vRequest =  "../getCommandCount.php?command=getSerialFromAuthentification&pseudo_transmis="+userId+"&mot_passe_transmis="+userMdp;
	vHttp.open("GET", vRequest, false);
	vHttp.send(null);
	
	vElem = document.getElementById(inObjectID);
	
	if (vElem!=null){
		var vHeight = 40;
		var vTop = 0;
		var vHttpReq = vHttp.responseText;
		
		if (vHttpReq == "Not allowed\n") {
				vElem.innerHTML = "<center>Login or Password incorrect.</center>";
		} else {
			displaySerials(vTop, vHeight, vElem, vHttpReq);
		}
		
	}
	
}

function getHTMLSerial( productSerial, editorComments ) {
	var htmlText = "";
	isSerial = ( productSerial != "EDITOR_MANUAL_MAIL" );
	isSerial = isSerial && ( productSerial != "ERROR" );
	//isSerial = isSerial && ( vProductSerial != "EDITOR_MANUAL_MAIL" );
	if( isSerial ) {
		htmlText = productSerial;
	} else {
		htmlText = "Please allow up to 72hours for the email to be sent to you.";
		htmlText += "<br>If you didn't get the serial by email by then,";
		htmlText += "<br>please contact <a href='mailto:"+editorEmail+"'>"+editorEmail+"</a><br>";
		htmlText += editorComments;
	}
	return htmlText;
}