// JavaScript Document
function OpenFileWindow(url)
{ 
	window.open(url, 'ProjectFileWindow', 'width=600,height=400,resizable,scrollbars,status');
}



window.onload = function(){embedUploader();};


function embedUploader()
{
	//init variables
	var requiredFlashVersion = "9.0.28";				   
	//set up and embed the uploader for zip files
	var flashvars_script = {};
	
	flashvars_script.configFile = "xml/uploadConfig_script_"+getTier()+".xml";
	//flashvars_script.DownloadID = document.getElementById('downloadid').value;
	flashvars_script.location = document.getElementById('location').value;
	//flashvars_script.locationid = document.getElementById('locationid').value;
	var params_script = {};
	params_script.play = true;
	params_script.bgcolor = "#FFFFFF";
	params_script.wmode = "transparent";
	var attributes_script = {};
	attributes_script.name = "scriptUpload";
	swfobject.embedSWF("/shared/Flash/CodeGalleryUploader.swf", "scriptUpload", "300", "35", requiredFlashVersion, "/Shared/JSApps/swfobject_2.0/expressInstall.swf", flashvars_script, params_script, attributes_script);		
}



function getTier(){
	var domain = window.location.toString().split(".");
	var subDomain = domain[0];
	var tier = "prd";
	if(subDomain.indexOf("dev") >= 0)
		tier = "dev";
	else if(subDomain.indexOf("stg") >= 0)
		tier = "stg";	
		
	return tier;
}

function newUploadStarted(caller){
	document.getElementById('UploadStartimg').style.display = "block";
	//flashvars_script.location = document.getElementById('location').value;
	var theDiv = getMessageDiv(caller);
	//showing Ajax Loader
	theDiv.innerHTML = "";
	thisDiv.style.display = "none";
}


function fileSizeViolation(caller, eventObject, maxFileSize){
var theDiv = getMessageDiv(caller);
theDiv.innerHTML = "The file you have chosen is TOO LARGE.<br/>The maximum file size is 30 MB";
}


function uploadError(caller, eventObject, data){
	var theDiv = getMessageDiv(caller);
	theDiv.innerHTML = "We are sorry but there was a problem. Please try again later.";
}

function singleFileUpload(caller, eventObject, data, reference){
	document.getElementById('UploadStartimg').style.display = "none";
	var theForm = document.forms['submitform'];
	theForm.downloadfile.value = data.serverfile;
	theForm.downloadsize.value = data.serverfilesize;
	var theDiv = getMessageDiv(caller);
	theDiv.className = "message";
	theDiv.innerHTML = "The file has been uploaded and will be included with your request after the form is submitted.";

}

function IOError(caller, error){
	var theDiv = getMessageDiv(caller);
	theDiv.innerHTML = "We are sorry but there is a problem connecting to the server.<br/>Please try again shortly.";
}

function SecurityError(caller, error){
	var theDiv = getMessageDiv(caller);
	theDiv.innerHTML = "We are sorry but there is a problem connecting to the server.<br/>Please try again later.";
}

function toKilobytes(_size){
	var kb = String(Math.round(_size/1024));
	return kb;
}

function getMessageDiv(caller){
	var msDiv = "";
	if(caller == "scriptUpload"){
		msDiv = document.getElementById('scriptMessage');
		msDiv.style.display = "block";
	}
	return msDiv;
}	



String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}