// JavaScript Document
<!--
ajaxObject = function() {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e){
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e){
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){
try { return new XMLHttpRequest() } catch(e){
throw new Error( "This browser does not support XMLHttpRequest." );
}}}}}}


if(ajaxObj == null){
	var ajaxObj = new ajaxObject();
}

function setSmall(photoID, sessionID, address)
{
    photoID = photoID + "";
    sessionID = sessionID + "";
	setValue(photoID + "_width", 80);
	setValue(photoID + "_height", 60);	
	updateInput(sessionID, photoID + "_width", address);
	setTimeout("updateInput('"+ sessionID+"','"+ photoID + "_height', '" + address+ "');", 1000);
	checkPhotoUpdate(photoID, 80, 60)	
}

function setMedium(photoID, sessionID, address)
{
    photoID = photoID + "";
    sessionID = sessionID + "";
	setValue(photoID + "_width", 200);
	setValue(photoID + "_height", 150);	
	updateInput(sessionID, photoID + "_width", address);
	setTimeout("updateInput('"+ sessionID+"','"+ photoID + "_height', '" + address+ "');", 1000);
	checkPhotoUpdate(photoID, 200, 150)	
}

function setLarge(photoID, sessionID, address)
{
    photoID = photoID + "";
    sessionID = sessionID + "";
	setValue(photoID + "_width", 400);
	setValue(photoID + "_height", 300);	
	updateInput(sessionID, photoID + "_width", address);
	setTimeout("updateInput('"+ sessionID+"','"+ photoID + "_height', '" + address+ "');", 1000);

	checkPhotoUpdate(photoID, 400, 300)	
}


function checkPhotoUpdate(photoID, width, height)
{
	width = width + "";
	height = height + "";

	if(document.getElementById(photoID + "_width_error").innerHTML == "Updating..."
	 || document.getElementById(photoID + "_height_error").innerHTML == "Updating..."){

		setTimeout("checkPhotoUpdate('"+ photoID + "', '" + width + "','"+ height+ "');", 100);
	} else {		
		document.getElementById(photoID).width = width;
		document.getElementById(photoID).height = height;
	}
}

function updateParent( fileID, parent_DIV, inputID, img_width, img_height)
{
	alert("Image upload successful");
	inputID = inputID + "";
	if(window.parent.document.getElementById(parent_DIV + "_error") != null){
		window.parent.document.getElementById(parent_DIV + "_error").style.display = "none";
	}
	var image_html = window.parent.document.getElementById(parent_DIV);
	if(image_html != null){
		var image_html_innerHTML = "<img id=\""+inputID+"\" src=\"" + fileID + "\" onClick=\"showhide('"+ inputID +"_settings');\" "; 
		if(img_width > 0 || img_height > 0){
			image_html_innerHTML = image_html_innerHTML + "onLoad=\"photo_resize(this, '"+img_width +"', '"+img_height+"', true); \" />";
		} else {
			image_html_innerHTML = image_html_innerHTML + " />";		
		}
		image_html.innerHTML = image_html_innerHTML;
	}
	//parent.document.getElementById(inputID + "_settings").style.display = "";
}
 
 function removePhoto(sessionID, photoID, address, maxwidth, maxheight, maxcode)
 {
// 	result = document.getElementById(photoID).src;
 	photoID = photoID + "";
	updateInput(sessionID, photoID, address, "", false);
	//document.getElementById(photoID + "_DIV").innerHTML = "File has been deleted. Please close window and open again to upload a new file.";
	AddPhoto_Ajax(sessionID, photoID, address, maxwidth, maxheight, maxcode);
 }

function AddPhoto_Ajax(sessionID, photoID, address, maxwidth, maxheight, maxcode){
	if(ajaxObj.readyState > 0 && ajaxObj.readyState < 4  || ajaxObj_finishupdating == 0){
		setTimeout("AddPhoto_Ajax('"+ sessionID + "','" + photoID + "','" + address +"','" + maxwidth + "','" + maxheight + "','" + maxcode+"');", 10);	
		if(ajaxObj_finishupdating == 0 && ajaxObj.readyState == 4){
   			handleResponse();
   		}
	} else {
		ajaxObj_elementtype = 1;
		
		var a1b2;
		if(document.getElementById("a1b2") != null){
			a1b2 = document.getElementById("a1b2").innerHTML;
		}
		
		ajaxObj_finishupdating = 0;
		var params = 'wizardID=' + wizardID + '&sessionID=' + sessionID + '&ID=' + photoID + '&action=ajax_photo&a1b2=' + a1b2 + '&maxheight=' + maxheight+ '&maxwidth='+ maxwidth+'&maxcode='+ maxcode+'&';
		ajaxObj.open('post', address + 'loadPhoto.php');
		ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxObj.setRequestHeader("Content-length", params.length);
		ajaxObj.setRequestHeader("Connection", "close");
		
		ajaxObj.send(params);	
		ajaxObj_onerrorupdate = false;
		if( navigator.appName == "Microsoft Internet Explorer"){
			setTimeout("handleResponse()", 10);
		} else {
			ajaxObj.onreadystatechange = handleResponse();
		}
	}
}

function photo_resize(obj, width, height, preserve_ratio){
if(preserve_ratio){
	img_aspect_ratio = obj.width / obj.height;
	if(img_aspect_ratio > 1){
		newheight = width / img_aspect_ratio;
		obj.height = newheight;
		obj.width = width;
		return;
	} else {
		newwidth = img_aspect_ratio * height;
		obj.width = newwidth;
		obj.height = height;
	}
} else {
	obj.width = width;
	obj.height = height; 
}
}

//-->
