//this file requires the prior loading of ajax.js

function CardGeneratorUploader(){

}

CardGeneratorUploader.prototype.handleResponseOfData = function()
{
	if (req.readyState==4)
	{
		//responsecontainer.innerHTML="";
		
		if (ajax_EnableDebug==true)
			ajax_OpenWindowWithText(req.responseText);
			
		if (saLanguage && saLanguage == "German")
		{
			var output = "<a href=\"mailto:yourname@youraddress.com?subject=Lern%20Es%20Fragen&body=";
			var mailbody = "&lt;studyaid://";
			
			var data = req.responseText;
			
			mailbody+=data;
			
			mailbody += "&gt;";
			output += escape(mailbody);
			output += "\">Klicke hier!</a><br/>";
			output += "Wenn du Apple Mail Client oder Outlook 2007 benutzt, dann versuche es &uuml;ber diesen Link:<br/>";
			output += "<a href=\"mailto:yourname@youraddress.com?subject=Lern%20Es%20Fragen&body=";
			output += "<studyaid://"+data+">\">Alternativer Link f&uuml;r Outlook und Apple Mail Client.</a><br/>";
			output+="Alternativ kannst du den folgenden Link in eine e-mail kopieren und eingef&uuml;gen:<br/>" + mailbody;
			//alert(output);
			window.StudyAidApp.TakeResult(output);
			
			//done. Now check for more requests
			if (pagerequestarray.length > 0 && AllowQueuingRequest==true)
			{
				isRequesting=false;
				GetPage(pagerequestarray[0].ResponseContainerObj,pagerequestarray[0].url,pagerequestarray[0].PostString);
				pagerequestarray.shift();
			}
			else
			{
				isRequesting=false;
			}
		}
		else
		{
			var output = "<a href=\"mailto:yourname@youraddress.com?subject=Study%20Aid%20Questions&body=";
			var mailbody = "&lt;studyaid://";
			
			var data = req.responseText;
			
			mailbody+=data;
			
			mailbody += "&gt;";
			output += escape(mailbody);
			output += "\">Click Here!</a><br/>";
			output += "If you use the Apple Mail Client or Outlook 2007, you might try this link instead:<br/>";
			output += "<a href=\"mailto:yourname@youraddress.com?subject=Study%20Aid%20Questions&body=";
			output += "<studyaid://"+data+">\">Alternative Link for Outlook and Apple Mail Client Users</a><br/>";
			output+="Alternatively, you can copy and paste the following into an e-mail:<br/>" + mailbody;
			//alert(output);
			window.StudyAidApp.TakeResult(output);
			
			//done. Now check for more requests
			if (pagerequestarray.length > 0 && AllowQueuingRequest==true)
			{
				isRequesting=false;
				GetPage(pagerequestarray[0].ResponseContainerObj,pagerequestarray[0].url,pagerequestarray[0].PostString);
				pagerequestarray.shift();
			}
			else
			{
				isRequesting=false;
			}
		}
			
	}
}

CardGeneratorUploader.prototype.postData = function(data)
{
	var escapedData = encodeURIComponent(data);//urlEncodePostData(data);
	GetPageWithHandler(this.handleResponseOfData,"studyAid.php","sa_insertData="+escapedData,null,false);
}

//the uploadCardData function assumes recieving a list
//of SACard objects with the following function defined in them:
//
//SACard.prototype.getDataValue = function()
//{
//return "@q:"+this.question+"@a:"+this.answer;
//}

CardGeneratorUploader.prototype.uploadCardData = function(CardList)
{
	var data = "";
	for (i=0;i < CardList.length;++i)
	{
		data+= CardList[i].getDataValue();
	}
	this.postData(data);
}