
var formId;
var myresponse = "";

function fileUpload(form, action_url, div_id)
{
		loadingGif(div_id+"_loading");
		
		
		// Create the iframe...
		var iframe = document.createElement("iframe");
		var content = "";
		
		iframe.setAttribute("id",div_id + "_iframe");
		iframe.setAttribute("name",div_id + "_iframe");
		//iframe.setAttribute("src", "ajs/test.php");
		iframe.setAttribute("width","0");
		iframe.setAttribute("height","0");
		iframe.setAttribute("border","0");
		
		iframe.setAttribute("style","width: 0; height: 0; border: none; display: none;");
		//iframe.setAttribute("onload", "fileUploadResponse('upload1')");
		//iframe.setAttribute("load", "fileUploadResponse('upload1')");
		
		// Add to document...
		form.parentNode.appendChild(iframe);
		window.frames[div_id + '_iframe'].name=div_id + "_iframe";
		
		iframeId = document.getElementById(div_id + "_iframe");
		
		// Add event...
		var eventHandler = function()  
		{
		
			if (iframeId.detachEvent)
				iframeId.detachEvent("onload", eventHandler);
			else
				iframeId.removeEventListener("load", eventHandler, false);
			
			// Message from server...
			if (iframeId.contentDocument) 
			{
				//alert("option 1");
				content = iframeId.contentDocument.body.innerHTML;
				fileUploadResponse('upload1');
			} 
			else if (iframeId.contentWindow) 
			{
				//alert("option 2");
				content = iframeId.contentWindow.document.body.innerHTML;
				//alert("content is: " + content);
				fileUploadResponse('upload1');
			}
			else if (iframeId.document) 
			{
				//alert("option 3");
				content = iframeId.document.body.innerHTML;
				fileUploadResponse('upload1');
			}else{
				//alert("option 4");
			}
			
			//alert("look: "+div_id);
			
			if(document.getElementById(div_id))
			{
				document.getElementById(div_id).innerHTML = content;
			}
			//alert("here: "+content);
			// Del the iframe...
			setTimeout('iframeId.parentNode.removeChild(iframeId)', 250);
		}
		
		if (iframeId.addEventListener) 
		{
			iframeId.addEventListener("load", eventHandler, true);
		}
		if (iframeId.attachEvent) 
		{
			iframeId.attachEvent("onload", eventHandler);
		}
		// Set properties of form...
		form.setAttribute("target",div_id + "_iframe");
		form.setAttribute("action", action_url);
		form.setAttribute("method","post");
		form.setAttribute("enctype","multipart/form-data");
		form.setAttribute("encoding","multipart/form-data");
	
		
		// Submit the form...
		form.submit();
		
		if (document.getElementById(div_id)) {
			document.getElementById(div_id).innerHTML = "Uploading...";
		}
}


function fileUploadResponse(myDivEle)
{
	//alert("fileUploadResponse called");
	var myele = document.getElementById(myDivEle+"_iframe");
	myresponse = myele.contentWindow.document.body.innerHTML;
	//contentWindow.document.body.innerHTML (ie wants this)
	
	if(myresponse != "")
	{
		document.getElementById(myDivEle + "_submit").disabled = false;
		loadingDone(myDivEle+"_loading");
	}
	return myresponse;
}

function fileUploadConfirm(myDivEle)
{
	var myele = document.getElementById(myDivEle+"_iframe");
	//alert("here: " + myele.id.tostring());
	var myresponse = myele.contentWindow.document.body.innerHTML;
	if(myresponse != "")
	{
		//alert("enable submit");
		document.getElementById(myDivEle + "_submit").disabled = false;
		loadingDone(myDivEle+"_loading");
	}
	
}

	
function apply(id)
{
	//Declare form element
	var formEle = document.getElementById(id);
	var name 	= formEle.elements["name"].value;
	var email 	= formEle.elements["email"].value;
	var phone 	= formEle.elements["phone"].value;
	var checkCount = 0;
	//var resume 	= formEle.elements["resume"].value;
	
	//alert(formEle.elements["name"].value);
	
	//set url, getstring, boxId, showload
	var url = "/ajs/resume_thanks.php";
	var getString ='';
		getString +='&name=' + formEle.elements["name"].value;
		getString +='&email=' + formEle.elements["email"].value;
		getString +='&phone=' + formEle.elements["phone"].value;
		getString +='&resume=' + myresponse;
		getString +='&submitted=1';
		
		for(i = 0; i < formEle.opening.length; i++)
		{
			if(formEle.opening[i].checked)
			{
				checkCount++;
				getString += '&opening'+checkCount+'='+formEle.opening[i].value;
			}
		}
		getString += '&applications='+checkCount;
	var thisBoxId = "applyBlock_" + id;
	var showLoad = true;
	
	
	//alert(url + "\n"+ getString +"\n"+ thisBoxId +"\n"+ showLoad);
	//call the ajax page
	getTextResponse(url, getString, thisBoxId, showLoad);
	
}

function applyLoad(id)
{
	
	//Declare form element
	var formEle = document.getElementById(id);
	
	var checkCount = 0;
	//var resume 	= formEle.elements["resume"].value;
	
	//alert(formEle.elements["name"].value);
	
	//set url, getstring, boxId, showload
	var url = "/ajs/resume_thanks.php";
	var getString ='';
	var thisBoxId = "applyBlock_" + id;
	var showLoad = true;
	
	
	
	//call the ajax page
	getTextResponse(url, getString, thisBoxId, showLoad);
	
}



function loadingGif(divLoad)
{
	//alert("loading");
	var loadEle = document.getElementById(divLoad);
	loadEle.src = '/images/loading.gif';
	
}

function loadingDone(divLoad)
{
	//alert("done");
	var loadEle2 = document.getElementById(divLoad);
	loadEle2.src = '/images/tick.png';
}

