/*-------------------------------------------
	pandora vod upload interface
	oPandora.open()
	parameta
	[0] = secret key : string
	[1] = user id : string
	[2] = return url : string
	[3] = vod title : string
	[4] = vod description : string
	[5] = adult check flag : string - y / n
	
	ex)
		1. oPandora.open("a1b2c3d4", "userid", "return url", "motor cycle")
		2. oPandora.open("a1b2c3d4", "guest", "return url", "motor cycle", "description", "y")
-------------------------------------------*/

var oPandora = new PANDORA();

function PANDORA() {
	this.url = "http://up.pandora.tv/outbound/upload.ptv";
	this.form = null;
	this.vodInfo = {prgid:"", title:"", url:"", thumbnail:"", regDate:"", chkAdult:"", content:""};
	this.vodTag = new Array();
	
	this.vodWidth = 448;
	this.vodHeight = 361;

	this.rtnFunction = null;

	this.open = function() {
		if(this.rtnFunction == null) {
			alert("Enter function that refers video play related HTML tag after upload.");
		}

		var key = arguments[0];
		var userid = arguments[1] ? arguments[1] : "blank";
		var pathReturn = arguments[2];
		var subject = arguments[3] ? arguments[3] : "";
		var description = arguments[4] ? arguments[4] : subject;
		var chkAdult = arguments[5] ? arguments[5].toLowerCase() : "n";

		this.form = document.createElement("FORM");
		this.appendInput("scrkey", key);
		this.appendInput("tuserid", userid);
		this.appendInput("returnpath", pathReturn);
		this.appendInput("subject", subject);
		this.appendInput("body", description);
		this.appendInput("adult", chkAdult);
		this.appendInput("lan", "gb");

		var winPandoraUpload = window.open("about:blank", "winPandoraUpload", "width=580, height=505");
		with(this.form) {
			action = this.url;
			target = "winPandoraUpload";
			method = "post";
		}
		document.body.appendChild(this.form);
		
		this.form.submit();
		this.clearElement();
	}
	
	
	this.clearElement = function() {
		var oInputs = this.form.childNodes;
		for(var i=oInputs.length-1;i>=0;i--) {
			this.form.removeChild(oInputs[i]);
		}
		var oParent = this.form.parentElement;
		oParent.removeChild(this.form);
	}
	
	
	this.appendInput = function(argName, argValue) {
		var oInput = document.createElement("INPUT");
		with(oInput) {
			type = "hidden";
			name = argName;
			value = argValue;
		}
		
		this.form.appendChild(oInput);
	}


	this.setVodInfo = function() {
		this.vodInfo.url = arguments[0];
		this.vodInfo.title = arguments[1];
		this.vodInfo.thumbnail = arguments[2];
		this.vodInfo.regDate = arguments[3];
		this.vodInfo.chkAdult = arguments[4].toUpperCase();
		this.vodInfo.prgid = arguments[5] ? arguments[5] : "";
		this.vodInfo.content = arguments[6] ? arguments[6] : "";
		
		this.setEmbedTag();
		this.rtnFunction();
	}
	
	
	this.setEmbedTag = function() {
		var idValue = (new Date()).getTime();
		this.vodTag[0] = "<object" +
		               " classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"" +
		               " id=\"id_" + idValue + "\"" +
		               " codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\"" +
		               " width=\"" + this.vodWidth + "\"" +
		               " height=\"" + this.vodHeight + "\"" +
		               " align=\"middle\"" +
		               ">\n" +
		               "	<param name=\"quality\" value=\"high\" />\n" +
		               "	<param name=\"movie\" value=\"" + this.vodInfo.url + "\" />\n" +
		               "	<param name=\"allowScriptAccess\" value=\"always\" />\n" +
		               "	<param name=\"allowFullScreen\" value=\"true\" />\n" +
		               "	<param name=\"play\" value=\"1\" />\n" +
		               "	<embed" +
		               "	 src=\"" + this.vodInfo.url + "\"" +
		               "	 width=\"" + this.vodWidth + "\"" +
		               "	 height=\"" + this.vodHeight + "\"" +
		               "	 name=\"id_" + idValue + "\"" +
		               "	 allowFullScreen=\"true\"" +
		               "	 pluginspage=\"http://www.macromedia.com/go/getflashplayer\"" +
		               "	 type=\"application/x-shockwave-flash\"" +
		               "	 allowScriptAccess=\"always\"" +
		               "	 />\n" +
		               "</object>";

		this.vodTag[1] = "<embed "+
		               " src=\"" + this.vodInfo.url + "\"" +
		               " width=\"" + this.vodWidth + "\"" +
		               " height=\"" + this.vodHeight + "\"" +
		               " name=\"id_" + idValue + "\"" +
		               " allowFullScreen=\"true\"" +
		               " pluginspage=\"http://www.macromedia.com/go/getflashplayer\"" +
		               " type=\"application/x-shockwave-flash\"" +
		               " allowScriptAccess=\"always\"" +
		               " />";
	}
	
	
	
	this.setVodSize = function(argWidth, argHeight) {
		if(argWidth && isNaN(argWidth) == false) this.vodWidth = argWidth;
		if(argHeight && isNaN(argHeight) == false) this.vodHeight = argHeight;
	}
	
	
	this.getEmbedTag = function(argIdx) {
		return this.vodTag[argIdx-1];
	}
	
	
	this.getVodInfo = function() {
		return this.vodInfo;
	}
}
