// Default vars
var mailre = /[-\w.,]+@[-\w.,]{2,}\.([0-9]{1,3}|[A-Za-z]{2,6})/i;
var centerX;
var centerY;
var windowW;
var windowH;
var dd_datas;
var xmlSocket;
var xmlDoc;
var xmlDatas;

function isLeapYear(year){
	// February has 29 days in any year evenly divisible by four, exept for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? true : false );
}
function numberFormat(number,thousandsep,decimalsep,decimals){
	var output = "";
	var sNumber = "";
	var aNumber = null;
	var zeroPad = "000000";

	if(!thousandsep)
		thousandsep = ".";
	if(!decimalsep)
		decimalsep = ",";
	
	sNumber = number.toString();
	sNumber = strReplace(sNumber,".","D");
	sNumber = strReplace(sNumber,",","D");
	aNumber = sNumber.split("D");

	tmp = "";
	
	if(aNumber.length >= 1){
		
		integer = aNumber[0];
		// reverse the digits with regexp which works from left to right.
		for(var i=integer.length-1; i>=0; i--){
	      	tmp += integer.charAt(i);
		}
		tmp = tmp.replace(/(\d{3})/g, "$1" + thousandsep);
		if(tmp.slice(-thousandsep.length) == thousandsep)
     		tmp = tmp.slice(0, -thousandsep.length);
		for(var i=tmp.length-1; i>=0; i--){
			output += tmp.charAt(i);
		}

		if(aNumber.length > 1){
			fraction = aNumber[1];
			output += decimalsep + fraction;
			if(decimals && fraction.length < decimals)
				output += zeroPad.substr(0,decimals-fraction.length);
		}
		else if(decimals && decimals > 0){
			output += decimalsep + zeroPad.substr(0,decimals);
		}
	}
	 return output;
}
function formatNumber(number, currency, display, prefix, suffix){
	// Javascript port of the /control/view.cfc formatNumber function
	// display arguments: 0=no display, 1=sign, 2=text

	var sNumber = "";
	var sTmp = "";
	var sThousandSeparator = "";
	var sDecimalSeparator = "";
	var decimalCount = 0;
	var sPrefix = "";
	var sSuffix = "";
	var roundMask = "1000000000";

	switch(currency.toUpperCase()){
		case "EUR":
			sThousandSeparator = ".";
			sDecimalSeparator = ",";
			decimalCount = 2;
			sPrefix = "";
			sSuffix = " &euro;"
			break;
		case "USD":
			sThousandSeparator = ",";
			sDecimalSeparator = ".";
			decimalCount = 2;
			sPrefix = "$";
			sSuffix = ""
			break;
		case "CAD":
			sThousandSeparator = ",";
			sDecimalSeparator = ".";
			decimalCount = 2;
			sPrefix = "$";
			sSuffix = ""
			break;
		case "AUD":
			sThousandSeparator = ",";
			sDecimalSeparator = ".";
			decimalCount = 2;
			sPrefix = "$";
			sSuffix = ""
			break;
		case "GBP":
			sThousandSeparator = ",";
			sDecimalSeparator = ".";
			decimalCount = 2;
			sPrefix = "&pound; ";
			sSuffix = ""
			break;
		case "CHF":
			sThousandSeparator = ",";
			sDecimalSeparator = ".";
			decimalCount = 2;
			sPrefix = "SFr ";
			sSuffix = ""
			break;
		default:
			break;
	}
	
	if(decimalCount != 0)
		number = Math.round(number * parseInt(roundMask.substr(0,decimalCount+1))) / parseInt(roundMask.substr(0,decimalCount+1));
	sNumber = numberFormat(number,sThousandSeparator,sDecimalSeparator,decimalCount);
	if(display == 0){
		sPrefix = "";
		sSuffix = "";
	}
	else if(display == 2){
		sPrefix = currency.toUpperCase() + " ";
		sSuffix = "";
	}
	if(prefix)
		sPrefix = prefix;
	if(suffix)
		sSuffix = suffix;
	
	sNumber = sPrefix + sNumber + sSuffix;

	return(sNumber);
}
function daysInMonth(monthStr,yearStr){
	var output = 0;
	var month = parseInt(monthStr);
	var year = parseInt(yearStr);
	if(month == 2 && isLeapYear(year))
		output = 29;
	else if(month == 2)
		output = 28;
	else if(month==4 || month==6 || month==9 || month==11)
		output = 30;
	else
		output = 31;
	return(output);
}
function getFileName(fileStr) {
	// arguments: fileStr[absolute or relative file path]
	// returntype: string
	// usage: extract filename from path
	var backslach = fileStr.lastIndexOf("\\");
	var slach = fileStr.lastIndexOf("/");
	
	if(backslach == -1 && slach == -1){
		return fileStr.toLowerCase();
	}
	else if(backslach > slach){
		return fileStr.substring(backslach+1, fileStr.length).toLowerCase();
	}
	else{
		return fileStr.substring(slach+1, fileStr.length).toLowerCase();
	}
}
function getFileExt(fileStr) {
	// arguments: fileStr[absolute or relative file path]
	// returntype: string
	// usage: extract extension from path
	var dot = fileStr.lastIndexOf(".");
	
	if(dot == -1){
		return fileStr.toLowerCase();
	}
	else{
		return fileStr.substring(dot+1, fileStr.length).toLowerCase();
	}
}
function strReplace(string, subStr, replStr, mode){
	var output = "" + string;
	var charIdx = output.indexOf(subStr);
	while(charIdx != -1){
		output = output.replace(subStr, replStr);
		charIdx = output.indexOf(subStr);
	}
	return(output);	
}
function isDate(str){ 
	var output = false;
	var sep = "/";
	var check = null;
	// arguments: str[string to check], sep[separator]
	// returntype: boolean
	// usage: check string to see if it is a valid date
	if(arguments.length == 2)
		sep = arguments[2];
	check = str.split(sep);
	if(check.length == 3){
		day = check[0];
		month = check[1];
		year = check[2];
		checkday = daysInMonth(month,year);
		
		if(day > 0 && day <= checkday && month > 0 && month <= 12)
			output = true;
	}
	return(output);
}

function isEmail(str){
	check = str.match(mailre);
	if(check == null)
		return false;
	else
		return true;
}
function checkOrder(formObj){
	var output = false;
	var errormsg = "";
	if(formObj && formObj.formName){
		switch(formObj.formName.value){
			case "cartShipTo":
				if(!hasCheckbox(formObj,'shippingID')) {errormsg = ERROR_SELECT_SHIPPING_ADDRESS; }
				break;
			case "cartBillTo":
				if(!hasCheckbox(formObj,'billingID')) {errormsg = ERROR_SELECT_BILLING_ADDRESS; }
				break;
			case "cartShipMethod":
				if(!hasCheckbox(formObj,'shippingMethod')) {errormsg = ERROR_FORM_MANDATORYFIELD_MISSING; }
				break;
			case "cartPaymentMethod":
				if(!hasCheckbox(formObj,'paymentMethod')) {errormsg = ERROR_PAYMENT_METHOD_EMPTY; }
				break;
			case "cartPayment":
				if(formObj['cardOwner'].value == ""){errormsg = ERROR_PAYMENT_CARD_OWNER_EMPTY; }
				else if(formObj['cardNumber'].value == ""){errormsg = ERROR_PAYMENT_CARD_NUMBER_EMPTY; }
				else if(parseInt(formObj['cardExpYear'].value) < today.getFullYear() || (parseInt(formObj['cardExpYear'].value) == today.getFullYear() && parseInt(formObj['cardExpMonth'].value) < today.getMonth()+1)){errormsg = ERROR_PAYMENT_CARD_EXP_INVALID; }
				else if(formObj['cardVerifCode'].value == ""){errormsg = ERROR_FORM_MANDATORYFIELD_MISSING; }
				else if(isNaN(parseInt(formObj['cardVerifCode'].value))){errormsg = ERROR_PAYMENT_CARD_VERIF_INVALID; }
				if(errormsg == ""){
					document.getElementById("paymentform").style.display = "none";
					document.getElementById("progressbar").style.display = "block";
				}
				break;
			default: break;	
		}
	}
	if(errormsg != "")
		alert(errormsg);
	else
		output = true;
	return(output);
}
function checkMyPicture(formObj){
	var output = false;
	var errormsg = "";
	if(formObj && formObj.formName){
		switch(formObj.formName.value){
			case "pictureCollectionEdit":
				if(formObj.name.value == "") {errormsg = ERROR_FORM_MANDATORYFIELD_MISSING; }
				break;
			case "pictureList":
				if(!hasCheckbox(formObj,'pictureIDList')) {errormsg = ERROR_FORM_SELECT_BEFORE_ACTIONS; }
				break;
			case "pictureCopy":
			case "pictureMove":
				if(isCheckedRadio(formObj,'newPictureCollection','true') && formObj.newPictureCollectionName.value == "") {errormsg = ERROR_FORM_MANDATORYFIELD_MISSING; }
				break;
			case "pictureEdit":
				if(formObj['pictureIDList']){
					idlist = formObj['pictureIDList'].value.split(",");
					for(var i=0; i<idlist.length; i++){
						if(formObj['name_' + idlist[i]].value == ""){
							errormsg = ERROR_FORM_MANDATORYFIELD_MISSING;
							break;
						}
					}
				}
				break;
			default: break;	
		}
	}
	if(errormsg != "")
		alert(errormsg);
	else
		output = true;
	return(output);
}
function checkStart(formObj){
	var output = false;
	var errormsg = "";
	if(formObj && formObj.wizardName){
		step = formObj.wizardName.value + "_start";
		switch(step){
			case "notebook_start":
			case "notepad_start":
			case "postcard_start":
			case "calendar_start":
			case "picturebook_start":
			case "greetingcard_start":
				if(isCheckedRadio(formObj,'wizardmode','new') && formObj.name.value == "") {errormsg = ERROR_FORM_MANDATORYFIELD_MISSING; }
				else if(isCheckedRadio(formObj,'wizardmode','edit') && formObj.id.value == "") {errormsg = ERROR_FORM_SELECT_PRODUCT; }
				break;
			default: break;	
		}
	}
	if(errormsg != "")
		alert(errormsg);
	else
		output = true;
	return(output);
}
function checkWizard(formObj){
	var output = false;
	var errormsg = "";
	if(formObj && formObj.wizardName && formObj.formName){
		step = formObj.wizardName.value + "_" + formObj.formName.value;
		switch(step){
			case "notebook_name":
			case "notepad_name":
			case "postcard_name":
			case "calendar_name":
			case "picturebook_name":
			case "greetingcard_name":
				if(formObj.name.value == "") {errormsg = ERROR_FORM_MANDATORYFIELD_MISSING; }
				break;
			case "calendar_pictures":
				if(!isfullassignedPictures(formObj, "page")) {errormsg = ERROR_WIZARD_CALENDAR_SETALLMONTHPICTURES; }
				break;
			default: break;	
		}
	}
	if(errormsg != "")
		alert(errormsg);
	else
		output = true;
	return(output);
}
function checkUpload(formObj){
	var output = false;
	var errormsg = "";
	if(formObj && formObj.wizardName && formObj.formName){
		step = formObj.wizardName.value + "_" + formObj.formName.value;
		switch(step){
			case "pictureUploader_pictureAdd":
				if(isCheckedRadio(formObj,'newPictureCollection','true') && formObj.newPictureCollectionName.value == "") {errormsg = ERROR_FORM_MANDATORYFIELD_MISSING; }
				break;
			case "pictureUploader_pictureAddH":
				if(formObj['uploadMaxCount']){
					haspicture = false;
					errorlist = "";
					for(var i=0; i<parseInt(formObj['uploadMaxCount'].value); i++){
						if(formObj['file_'+i] && formObj['file_'+i].value != ""){
							fileExt = getFileExt(formObj['file_'+i].value);
							if(fileExt != "jpg" && fileExt != "jpeg" && fileExt != "pjpg" && fileExt != "pjpeg"){
								errorlist = errorlist + "-" + i + " " + getFileName(formObj['file_'+i].value) + "\n";
							}
							else{
								haspicture = true;	
							}
						}
					}
					if(!haspicture)
						errormsg = ERROR_FORM_MANDATORYFIELD_MISSING;
					else if(errorlist != "")
						errormsg = strReplace(ERROR_PICTURE_UPLOAD_INVALID,"{0}",errorlist);
				}
				if(errormsg == ""){
					document.getElementById("uploader").style.display = "none";
					document.getElementById('progressbar').style.display = "block";
				}
			default: break;	
		}
	}
	if(errormsg != "")
		alert(errormsg);
	else
		output = true;
	return(output);
}
function checkEvent(formObj){
	var output = false;
	// arguments: formObj[form object]
	// returntype: boolean
	// usage: check value of the text field
	if(formObj){
		dateStr = formObj.day.value + "/" + formObj.month.value + "/2008"; // We pass a leap year
		if(formObj.text.value == "")
			alert(ERROR_FORM_MANDATORYFIELD_MISSING);
		else if(!isDate(dateStr))
			alert(ERROR_DATE_MONTHDAY_INVALID);
		else
			output = true;
	}
	return output;
}
function checkEmail(formObj){
	var output = false;
	// arguments: formObj[form object]
	// returntype: boolean
	// usage: check value of the email field
	if(formObj){
		if(!isEmail(formObj.email.value))
			alert(ERROR_USER_EMAIL_INVALID);
		else
			output = true;
	}
	return output;
}
function checkAddress(formObj){
	var output = false;
	// arguments: formObj[form object]
	// returntype: boolean
	// usage: check value of the email field
	if(formObj){
		if(!isEmail(formObj.email.value))
			alert(ERROR_USER_EMAIL_INVALID);
		else if(formObj.email.value != formObj.ccemail.value)
			alert(ERROR_USER_EMAIL_NOMATCH);
		else if(formObj.zipcode.value.length < 4)
			alert(ERROR_FORM_MANDATORYFIELD_MISSING);
		else if(formObj.salutation.selectedIndex <= 0 || formObj.firstname.value == "" || formObj.lastname.value == "" || 
				formObj.address.value == "" || formObj.zipcode.value == "" || formObj.city.value == "" || formObj.country.selectedIndex <= 0)
			alert(ERROR_FORM_MANDATORYFIELD_MISSING);
		else
			output = true;
	}
	return output;
}
function checkRegistration(formObj){
	var output = false;
	// arguments: formObj[form object]
	// returntype: boolean
	// usage: check value of the email field
	if(formObj){
		if(!isEmail(formObj.email.value))
			alert(ERROR_USER_EMAIL_INVALID);
		else if(formObj.email.value != formObj.ccemail.value)
			alert(ERROR_USER_EMAIL_NOMATCH);
		else if(formObj.password.value.length == 0)
			alert(ERROR_USER_PASSWORD_EMPTY);
		else if(formObj.password.value.length < passwordMinimumLength)
			alert(ERROR_USER_PASSWORD_TOOSHORT);
		else if(formObj.password.value != formObj.ccpassword.value)
			alert(ERROR_USER_PASSWORD_NOMATCH);
		else if(formObj.salutation.selectedIndex <= 0 || formObj.firstname.value == "" || formObj.lastname.value == "" || formObj.country.selectedIndex <= 0)
			alert(ERROR_FORM_MANDATORYFIELD_MISSING);
		else
			output = true;
	}
	return output;
}
function checkPassChange(formObj){
	var output = false;
	// arguments: formObj[form object]
	// returntype: boolean
	// usage: check value of the email field
	if(formObj){
		if(formObj.newPassword.value.length == 0)
			alert(ERROR_USER_PASSWORD_EMPTY);
		else if(formObj.newPassword.value.length < passwordMinimumLength)
			alert(ERROR_USER_PASSWORD_TOOSHORT);
		else if(formObj.newPassword.value != formObj.newCCpassword.value)
			alert(ERROR_USER_PASSWORD_NOMATCH);
		else
			output = true;
	}
	return output;
}
function checkQuickReg(formObj){
	var output = false;
	// arguments: formObj[form object]
	// returntype: boolean
	// usage: check value of the email field
	if(formObj){
		if(!isEmail(formObj.email.value))
			alert(ERROR_USER_EMAIL_INVALID);
		else
			output = true;
	}
	return output;
}
function checkLogin(formObj){
	var output = false;
	// arguments: formObj[form object]
	// returntype: boolean
	// usage: check the input values of a login form and display alerts
	if(formObj){
		if(!isEmail(formObj.email.value))
			alert(ERROR_USER_EMAIL_INVALID);
		else if(formObj.password.value.length == 0)
			alert(ERROR_USER_PASSWORD_EMPTY);
		else if(formObj.password.value.length < passwordMinimumLength)
			alert(ERROR_USER_PASSWORD_TOOSHORT);
		else
			output = true;
	}
	return output;
}
function jumpto(actionStr){
	if(actionStr != ""){
		window.location.href = "/index.cfm?action=" + actionStr;
	}
}
function confirmAction(messageStr, actionStr) {
	if(window.confirm(messageStr)){
		window.location.href = actionStr;
	}
}
function openViewer(locationStr, width, height, allowResize){
	// arguments: formObj[form object], actionStr[form action], checckfuntion[function to execute before submit]
	// returntype: boolean or none
	// usage: validate and submit a form
	var winargs = "";
	var winname = "viewer";
	var winwidth = (width && parseInt(width) > 0)?parseInt(width):640;
	var winheight = (height && parseInt(height) > 0)?parseInt(height):580;
	
	winargs = "width=" + winwidth + ", height=" + winheight;
	winname = winname + winwidth;
	
	if(allowResize){
		winargs = winargs + ", resizable=1";
	}
	if(locationStr){
		eval("winname = window.open(locationStr, winname, winargs);");
	}
	try {
		eval("winname.focus();");
	}
	catch(e){
	}
}
function openViewerAction(formObj, actionStr, checkfunction, allowResize, width, height){
	// arguments: formObj[form object], actionStr[form action], checckfuntion[function to execute before submit]
	// returntype: boolean or none
	// usage: validate and submit a form
	var winargs = "";
	var winname = "viewer";
	var winwidth = (width && parseInt(width) > 0)?parseInt(width):640;
	var winheight = (height && parseInt(height) > 0)?parseInt(height):580;
	
	winargs = "width=" + winwidth + ", height=" + winheight;
	winname = winname + winwidth;
	
	if(allowResize){
		winargs = winargs + "resizable=1";
	}
	if(checkfunction){
		check = checkfunction(formObj);
		if(check){
			if(formObj){
				oldTarget = formObj.target;
				oldAction = formObj.action;
				formObj.target = winname;
				formObj.action = actionStr;
				eval("winname = window.open('', winname, winargs);");
				formObj.submit();
			}
			else if(actionStr){
				eval("winname = window.open(actionStr, winname, winargs);");
			}
		}
	}
	else{
		if(formObj){
			oldTarget = formObj.target;
			oldAction = formObj.action;
			formObj.target = winname;
			formObj.action = actionStr;
			eval("winname = window.open('', winname, winargs);");
			formObj.submit();
		}
		else if(actionStr){
			eval("winname = window.open(actionStr, winname, winargs);");
		}
	}
	try {
		if(formObj){
			formObj.target = oldTarget;
			formObj.action = oldAction;
		}
		eval("winname.focus();");
	}
	catch(e){
	}
}
function closeViewerAction(formObj, actionStr){
	if(formObj && actionStr){
		//formObj.target = parent;
		doFormAction(formObj, actionStr);
	}
	else if(actionStr){
		parent.opener.location.href = actionStr;
	}
	parent.opener.focus();
	window.close();
}
function doFormAction(formObj, actionStr, checkfunction, returncheck){
	// arguments: formObj[form object], actionStr[form action], checckfuntion[function to execute before submit], returncheck[return checckfuntion result]
	// returntype: boolean or none
	// usage: validate and submit a form
	if(checkfunction){
		check = checkfunction(formObj);
		if(check){
			formObj.action = actionStr;
			formObj.submit();
		}
		if(returncheck){
			return check;
		}
	}
	else{
		formObj.action = actionStr;
		formObj.submit();
	}
}
function confirmFormAction(formObj, actionStr, messageStr, checkfunction, returncheck){
	// arguments: formObj[form object], actionStr[form action], checckfuntion[function to execute before submit], returncheck[return checckfuntion result]
	// returntype: boolean or none
	// usage: validate and submit a form
	if(checkfunction){
		check = checkfunction(formObj);
		if(check && messageStr){
			check = window.confirm(messageStr);
			if(check){
				formObj.action = actionStr;
				formObj.submit();
			}
		}
		else if(check){
			formObj.action = actionStr;
			formObj.submit();
		}
		if(returncheck){
			return check;
		}
	}
	else if(messageStr){
		if(window.confirm(messageStr)){
			formObj.action = actionStr;
			formObj.submit();
		}
	}
	else{
		formObj.action = actionStr;
		formObj.submit();
	}
}
function setMessageParam(messageStr){
	var output = "";
	output = messageStr;
	if(arguments.length > 1){
		for(var i=0; i<arguments.length-1; i++){
			check = "{" + i + "}";
			if(messageStr.indexOf(check) > 0){
				output = messageStr.substr(0,messageStr.indexOf(check)) + arguments[i+1] + messageStr.substr(messageStr.indexOf(check)+check.length,messageStr.length);
			}
		}
	}
	return(output);
}
function getHex(color){
	var output = "";
	if(color.substr(0,1) == "#"){
		output = color;
	}
	if(color.substr(0,3) == "rgb"){
		tmp = color.substr(4,color.length-5);
		rgb = tmp.split(", ");
		output = "#" + (parseInt(rgb[0]) < 16 ? '0' : '') + parseInt(rgb[0]).toString(16);
		output += (parseInt(rgb[1]) < 16 ? '0' : '') + parseInt(rgb[1]).toString(16);
		output += (parseInt(rgb[2]) < 16 ? '0' : '') + parseInt(rgb[2]).toString(16);
	}
	return(output);
}
function hasStyle(objId){
	var output = false;
	var target = document.getElementById(objId);
	if(target && target.currentStyle){
		output = true;
	}
	else if(window.getComputedStyle){
		output = true;
	}
	return(output);
}
function getStyle(objId,styleName,IEstyleProp,MOZstyleProp){
	var target = document.getElementById(objId);
	var style = "";
	if(target.currentStyle){
		styleProp = IEstyleProp;
		style = target.currentStyle[styleProp];
	}
	else if(window.getComputedStyle){
		styleProp = (MOZstyleProp)?MOZstyleProp:IEstyleProp;
		style = document.defaultView.getComputedStyle(target,null).getPropertyValue(styleProp);
	}
	else if(document.styleSheets && document.styleSheets[0]){
		style = null;
		// TODO: Verifiy this version for Opera browsers //
		/*if(document.styleSheets[0].cssRules && document.styleSheets[0].cssRules[0]){
			for(var s=0; s<document.styleSheets[0].cssRules.length; s++){
				if(document.styleSheets[0].cssRules[s].selectorText == styleName){
					styleProp = (MOZstyleProp)?MOZstyleProp:IEstyleProp;
					style = document.styleSheets[0].cssRules[s].style[styleProp];
					break;	
				}
			}
		}*/
	}
	return style;
}
function initFlashTitles(){
	var divs = document.getElementsByTagName("CITE");
	for(var d=0; d<divs.length; d++){
		var titleObj = divs[d];
		var titleId = "title_" + d;
		if(divs[d].innerHTML != ""){
			try{
				
				titleObj.setAttribute("id",titleId);
				var titleClass = null;
				
				var titleBgColor = getStyle(titleId,titleClass,"backgroundColor","background-color");
				var titleTxtColor = getStyle(titleId,titleClass,"color");
				var titleTxtSize = getStyle(titleId,titleClass,"fontSize","font-size");
				
				if(titleTxtSize){
					titleTxtSize = (titleTxtSize != "")?parseInt(titleTxtSize)+2:17;
					titleObj.style.fontSize = titleTxtSize + "px";
				}
				
				if(titleObj.offsetWidth)
					var titleWidth = parseInt(titleObj.offsetWidth)+6;
				else
					var titleWidth = getStyle(titleId,titleClass,"max-width");
				
				var titleHeight = getStyle(titleId,titleClass,"height");
					
				var titlePaddingLeft = getStyle(titleId,titleClass,"paddingLeft","padding-left");
				var titlePaddingBottom = getStyle(titleId,titleClass,"paddingBottom","padding-bottom");
				var titlePaddingRight = getStyle(titleId,titleClass,"paddingRight","padding-right");
				var titlePaddingTop = getStyle(titleId,titleClass,"paddingTop","padding-top");

				flashWidth = (titleWidth != "")?parseInt(titleWidth):100;
				flashHeight = (titleHeight != "")?parseInt(titleHeight):20;
				flashBgcolor = (titleBgColor != "")?getHex(titleBgColor):"#ffffff";
				flashTxtColor = (titleTxtColor != "")?getHex(titleTxtColor):"#000000";
				flashTxtSize = titleTxtSize;
				flashTxt =  "<font color='" + flashTxtColor + "'>" + titleObj.innerHTML + "</font>";
				
				if(titleWidth){
					flashObj = new SWFObject("/view/images/titles/title.swf?v=3", "titleObj_" + d, flashWidth, flashHeight, "7.0.14", flashBgcolor);
					flashObj.addVariable("bgalpha",100);
					flashObj.addVariable("bgcolor",flashBgcolor);
					flashObj.addVariable("fontsize",flashTxtSize);
					flashObj.addVariable("textcolor",flashTxtColor);
					flashObj.addVariable("txt", flashTxt);
					if(titlePaddingLeft != ""){ flashObj.addVariable("paddingLeft",parseInt(titlePaddingLeft)); }
					if(titlePaddingBottom != ""){ flashObj.addVariable("paddingBottom",parseInt(titlePaddingBottom)); }
					if(titlePaddingRight != ""){ flashObj.addVariable("paddingRight",parseInt(titlePaddingRight)); }
					if(titlePaddingTop != ""){ flashObj.addVariable("paddingTop",parseInt(titlePaddingTop)); }
					flashObj.write("title_" + d);
				}
				titleObj.style.width = flashWidth + "px";
				
			}
			catch(e){
				if(divs[d].offsetWidth)
					divs[d].style.width = parseInt(divs[d].offsetWidth)+6 + "px";
			}
		}
		divs[d].style.visibility = "visible";
	}
}
function showrow(rowid,classname){
	if(document.getElementById(rowid)){
		document.getElementById(rowid).className = classname;	
	}
}
function hiderow(rowid,classname){
	if(document.getElementById(rowid)){
		document.getElementById(rowid).className = classname;	
	}
}
function setVisible(objidlist){
	var objList = objidlist.split(",");
	if(objList){
		for(var i=0; i<objList.length; i++){
			if(document.getElementById(objList[i]) && document.getElementById(objList[i]).style)
				document.getElementById(objList[i]).style.visibility = "visible";
		}
	}
}
function setHidden(objidlist){
	var objList = objidlist.split(",");
	if(objList){
		for(var i=0; i<objList.length; i++){
			if(document.getElementById(objList[i]) && document.getElementById(objList[i]).style)
				document.getElementById(objList[i]).style.visibility = "hidden";
		}
	}
}
function revealblock(formObj,formField,hideOthers){
	if(formObj && formObj[formField]){
		for(var i=0; i<formObj[formField].length; i++){
			
			if(document.getElementById(formObj[formField].options[i].value)){
				if(i == formObj[formField].selectedIndex)
					document.getElementById(formObj[formField].options[i].value).style.display = "block";
				else
					document.getElementById(formObj[formField].options[i].value).style.display = "none";
			}
		}
	}
}
function setFontName(formObj, formField, value, actionStr){
	var haschanged = false;
	if(document.getElementById(formField + ".selector")){
		padObj = document.getElementById(formField + ".selector");
		fontList = padObj.getElementsByTagName("li");
		if(fontList && fontList.length > 0){
			idStr = "font_" + value;
			for(var i=0; i < fontList.length; i++){ 
				thisPad = fontList[i].getElementsByTagName("a");
				if(fontList[i].getAttribute("value") == idStr)
					thisPad[0].className = "current";
				else
					thisPad[0].className = "";
			}
		}
	}
	if(formObj && formObj[formField]){
		if(formObj[formField].value != value){
			formObj[formField].value = value;
			haschanged = true;
		}
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
}
function setFontAlign(formObj, formField, value, actionStr){
	var haschanged = false;
	if(document.getElementById(formField + ".selector")){
		padObj = document.getElementById(formField + ".selector");
		alignList = padObj.getElementsByTagName("li");
		if(alignList && alignList.length > 0){
			idStr = "align_" + value;
			for(var i=0; i < alignList.length; i++){ 
				thisPad = alignList[i].getElementsByTagName("a");
				if(alignList[i].getAttribute("value") == idStr)
					thisPad[0].className = "current";
				else
					thisPad[0].className = "";
			}
		}
	}
	if(formObj && formObj[formField]){
		if(formObj[formField].value != value){
			formObj[formField].value = value;
			haschanged = true;
		}
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
}
function setColor(formObj, formField, value, actionStr){
	var haschanged = false;
	if(document.getElementById(formField + ".selector")){
		padObj = document.getElementById(formField + ".selector");
		colorList = padObj.getElementsByTagName("li");
		if(colorList && colorList.length > 0){
			idStr = "color_" + value;
			for(var i=0; i < colorList.length; i++){ 
				thisPad = colorList[i].getElementsByTagName("a");
				if(colorList[i].getAttribute("value") == idStr)
					thisPad[0].className = "current";
				else
					thisPad[0].className = "";
			}
		}
	}
	if(formObj && formObj[formField]){
		if(formObj[formField].value != value){
			formObj[formField].value = value;
			haschanged = true;
		}
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
}
function setTextEditorDefaults(formObj,formGroup,actionStr){
	if(formObj){
		formObj[formGroup + ".fontname"].value = "-";
		formObj[formGroup + ".fontsize"].value = "-";
		formObj[formGroup + ".fontcolor"].value = "-";
		formObj[formGroup + ".alignH"].value = "-";
	}
	if(actionStr){
		doFormAction(formObj, actionStr);
	}
}
function selectModelFormat(formObj, formField, value, actionStr, previewImg){
	var haschanged = false;
	if(formObj && formObj[formField]){
		selectRadio(formObj, formField, value);
		haschanged = true;
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
	if(previewImg && haschanged){
		if(document.getElementById("preview")){
			document.getElementById("preview").src = previewImg;
		}
	}
}
function selectStyle(formObj, formField, value, actionStr, previewImg){
	var haschanged = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].value != value){
			formObj[formField].value = value;
			haschanged = true;
		}
	}
	if(document.getElementById("selector")){
		selObj = document.getElementById("selector");
		if(selObj.scrollTop && selObj.scrollTop > 0)
			actionStr = actionStr + "&st=" + selObj.scrollTop;
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
	if(previewImg && haschanged){
		if(document.getElementById("preview")){
			document.getElementById("preview").src = previewImg;
		}
		if(document.getElementById("styleselector")){
			selectorObj = document.getElementById("styleselector");
			selectorList = selectorObj.getElementsByTagName("li");
			thisId = "style_" + value;
			if(selectorList && selectorList.length > 0){
				for(var i=0; i < selectorList.length; i++){
					if(formObj["displayMode"] && formObj["displayMode"].value == "compact"){
						thisItem = selectorList[i].getElementsByTagName("span");
						if(selectorList[i].getAttribute("id") == thisId)
							thisItem[1].className = "current";
						else if(selectorList[i].getAttribute("id"))
							thisItem[1].className = "title";
					}
					else{
						thisItem = selectorList[i].getElementsByTagName("a");
						if(selectorList[i].getAttribute("id") == thisId)
							thisItem[0].className = "current";
						else if(selectorList[i].getAttribute("id"))
							thisItem[0].className = "";
					}
				}
			}
		}
	}
}
function selectCover(formObj, formField, value, actionStr, previewImg){
	var haschanged = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].value != value){
			formObj[formField].value = value;
			haschanged = true;
		}
	}
	if(document.getElementById("selector")){
		selObj = document.getElementById("selector");
		if(selObj.scrollTop && selObj.scrollTop > 0)
			actionStr = actionStr + "&st=" + selObj.scrollTop;
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
	if(previewImg && haschanged){
		if(document.getElementById("preview")){
			document.getElementById("preview").src = previewImg;
		}
		if(document.getElementById("coverselector")){
			selectorObj = document.getElementById("coverselector");
			selectorList = selectorObj.getElementsByTagName("li");
			thisId = "cover_" + value;
			if(selectorList && selectorList.length > 0){
				for(var i=0; i < selectorList.length; i++){
					if(formObj["displayMode"] && formObj["displayMode"].value == "compact"){
						thisItem = selectorList[i].getElementsByTagName("span");
						if(selectorList[i].getAttribute("id") == thisId)
							thisItem[1].className = "current";
						else if(selectorList[i].getAttribute("id"))
							thisItem[1].className = "title";
					}
					else{
						thisItem = selectorList[i].getElementsByTagName("a");
						if(selectorList[i].getAttribute("id") == thisId)
							thisItem[0].className = "current";
						else if(selectorList[i].getAttribute("id"))
							thisItem[0].className = "";
					}
				}
			}
		}
	}
}
function selectGrid(formObj, formField, value, actionStr, previewImg){
	var haschanged = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].value != value){
			formObj[formField].value = value;
			haschanged = true;
		}
	}
	if(document.getElementById("selector")){
		selObj = document.getElementById("selector");
		if(selObj.scrollTop && selObj.scrollTop > 0)
			actionStr = actionStr + "&st=" + selObj.scrollTop;
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
	if(previewImg && haschanged){
		if(document.getElementById("preview")){
			document.getElementById("preview").src = previewImg;
		}
		if(document.getElementById("gridselector")){
			selectorObj = document.getElementById("gridselector");
			selectorList = selectorObj.getElementsByTagName("li");
			thisId = "grid_" + value;
			if(selectorList && selectorList.length > 0){
				for(var i=0; i < selectorList.length; i++){ 
					if(formObj["displayMode"] && formObj["displayMode"].value == "compact"){
						thisItem = selectorList[i].getElementsByTagName("span");
						if(selectorList[i].getAttribute("id") == thisId)
							thisItem[1].className = "current";
						else if(selectorList[i].getAttribute("id"))
							thisItem[1].className = "title";
					}
					else{
						thisItem = selectorList[i].getElementsByTagName("a");
						if(selectorList[i].getAttribute("id") == thisId)
							thisItem[0].className = "current";
						else if(selectorList[i].getAttribute("id"))
							thisItem[0].className = "";
					}
				}
			}
		}
	}
}
function selectPicture(formObj, formField, value, actionStr){
	var haschanged = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].value != value){
			formObj[formField].value = value;
			haschanged = true;
		}
	}
	if(document.getElementById("selector")){
		selObj = document.getElementById("selector");
		if(selObj.scrollTop && selObj.scrollTop > 0)
			actionStr = actionStr + "&st=" + selObj.scrollTop;
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
}
function toggleSelection(formObj, formField, value){
	var isFound = -1;
	if(formObj && formObj[formField]){
		if(formObj[formField].value != "")
			selectList = formObj[formField].value.split(",");
		else
			selectList = new Array();
		
		for(var i=0; i<selectList.length; i++){
			if(selectList[i] == value){
				isFound = i;
				break;
			}
		}
		selectObj = formField + '.' + value;
		if(document.getElementById(selectObj)){
			if(isFound >= 0){
				document.getElementById(selectObj).className = "";
				selectList.splice(isFound,1);
			}
			else if(value != ""){
				document.getElementById(selectObj).className = "selected";
				selectList.push(value);
			}
		}
		formObj[formField].value = selectList.toString();
	}
}
function removeSelection(formObj, formField, value){
	var isFound = -1;
	if(formObj && formObj[formField]){
		if(formObj[formField].value != "")
			selectList = formObj[formField].value.split(",");
		else
			selectList = new Array();
		
		for(var i=0; i<selectList.length; i++){
			if(selectList[i] == value){
				isFound = i;
				break;
			}
		}
		selectObj = formField + '.' + value;
		if(document.getElementById(selectObj)){
			if(isFound >= 0){
				document.getElementById(selectObj).className = "";
				selectList.splice(isFound,1);
			}
		}
		formObj[formField].value = selectList.toString();
	}
}
function clearSelection(formObj, formField){
	if(formObj && formObj[formField] && formObj[formField].value != ""){
		clearList = formObj[formField].value.split(",");
		for(var i=0; i<clearList.length; i++){
			selectObj = formField + '.' + clearList[i];
			if(document.getElementById(selectObj)){
				document.getElementById(selectObj).className = "";
			}
		}
		formObj[formField].value = "";
	}
}
function addSelection(formObj, formField, value){
	var isFound = -1;
	if(formObj && formObj[formField]){
		if(formObj[formField].value != "")
			selectList = formObj[formField].value.split(",");
		else
			selectList = new Array();
		
		try{
			for(var i=0; i<selectList.length; i++){
				if(value && selectList[i] == value){
					isFound = i;
					break;
				}
			}
			selectObj = formField + '.' + value;
			if(document.getElementById(selectObj)){
				if(isFound < 0 && value != ""){
					document.getElementById(selectObj).className = "selected";
					selectList.push(value);
				}
			}
		}
		catch(e){
			
		}
		formObj[formField].value = selectList.toString();
	}
}
function selectPreview(formObj, formField, value, imgId, imgSrc, imgWidth, imgHeight){
	if(document.getElementById("previewselector")){
		previewObj = document.getElementById("previewselector");
		previewList = previewObj.getElementsByTagName("li");
		if(previewList && previewList.length > 0){
			for(var i=0; i < previewList.length; i++){ 
				thisPreview = previewList[i].getElementsByTagName("a");
				if(previewList[i].getAttribute("id") == imgId)
					thisPreview[0].className = "current";
				else
					thisPreview[0].className = "";
			}
		}
	}
	if(formObj && formObj[formField]){
		formObj[formField].value = value;
	}
	if(document.getElementById("preview")){
		previewImg = document.getElementById("preview");
		previewImg.src = imgSrc;
		previewImg.style.width = imgWidth + "px";
		previewImg.style.height = imgHeight + "px";
		previewContainer = document.getElementById("previewcontainer");
		if(previewContainer){
			previewContainer.style.width = imgWidth + "px";
			previewContainer.style.height = imgHeight + "px";
		}
	}
}
function swapPicture(formObj, source, target){
	var swap = new Object();
		swap.picture = "";
		swap.pictureCollection = "";
		swap.src = "";
		swap.width = "";
		swap.height = "";
		swap.marginTop = "";
		swap.marginBottom = "";
	if(formObj){
		if(formObj[source + '.picture'].value != "" || formObj[target + '.picture'].value != ""){
			sourceImg = document.getElementById(source + '.thumb');
			targetImg = document.getElementById(target + '.thumb');
			
			sourceImg.style.visibility = "hidden";
			targetImg.style.visibility = "hidden";
			
			swap.picture = formObj[target + '.picture'].value;
			swap.pictureCollection = formObj[target + '.pictureCollection'].value;
			swap.width = targetImg.style.width;
			swap.height = targetImg.style.height;
			swap.marginTop = targetImg.style.marginTop;
			swap.marginBottom = targetImg.style.marginBottom;
			swap.src = targetImg.src;
			
			formObj[target + '.picture'].value = formObj[source + '.picture'].value;
			formObj[target + '.pictureCollection'].value = formObj[source + '.pictureCollection'].value;
			targetImg.style.width = sourceImg.style.width;
			targetImg.style.height = sourceImg.style.height;
			targetImg.style.marginTop = sourceImg.style.marginTop;
			targetImg.style.marginBottom = sourceImg.style.marginBottom;
			targetImg.src = sourceImg.src;
			
			formObj[source + '.picture'].value = swap.picture;
			formObj[source + '.pictureCollection'].value = swap.pictureCollection;
			sourceImg.style.width = swap.width;
			sourceImg.style.height = swap.height;
			sourceImg.style.marginTop = swap.marginTop;
			sourceImg.style.marginBottom = swap.marginBottom;
			sourceImg.src = swap.src;
		
			targetImg.style.visibility = "visible";
			sourceImg.style.visibility = "visible";
		}
	}
}
function assignPicture(formObj, source, target){
	if(formObj){
		if(formObj[source + '.picture'].value != "" && formObj[source + '.pictureCollection'].value != ""){
			sourceImg = document.getElementById(source + '.thumb');
			targetImg = document.getElementById(target + '.thumb');
			formObj[target + '.picture'].value = formObj[source + '.picture'].value;
			formObj[target + '.pictureCollection'].value = formObj[source + '.pictureCollection'].value;
			targetImg.style.visibility = "hidden";
			targetImg.style.width = sourceImg.style.width;
			targetImg.style.height = sourceImg.style.height;
			targetImg.style.marginTop = sourceImg.style.marginTop;
			targetImg.style.marginBottom = sourceImg.style.marginBottom;
			targetImg.src = sourceImg.src;
			targetImg.style.visibility = "visible";
		}
		else{
			unassignPicture(formObj, target);
		}
	}
}
function assignPictures(formObj, sourceField, targetField, targetValue){
	var i = 0;
	if(formObj && formObj[sourceField] && formObj[targetField + '.length']){
		if(formObj[sourceField].value != "")
			sourceList = formObj[sourceField].value.split(",");
		else
			sourceList = new Array();
		for(var i=0; i<sourceList.length; i++){
			if(targetValue <= parseInt(formObj[targetField + '.length'].value)){
				sourceObj = sourceField + "." + sourceList[i];
				targetObj = targetField + "." + targetValue;
				assignPicture(formObj, sourceObj, targetObj);
				targetValue++;
			}
		}
		clearSelection(formObj, sourceField);
		clearSelection(formObj, targetField);
	}
}
function autofillPictures(formObj, sourceField, targetField){
	var i = 0;
	var targetIdx = 0;
	if(formObj && formObj[sourceField] && formObj[targetField + '.length']){
		if(formObj[sourceField].value != "")
			sourceList = formObj[sourceField].value.split(",");
		else
			sourceList = new Array();
		for(var i=0; i<sourceList.length; i++){
			while(targetIdx < parseInt(formObj[targetField + '.length'].value)){
				targetIdx++;
				if(formObj[targetField + "." + targetIdx + '.picture'].value == ""){
					sourceObj = sourceField + "." + sourceList[i];
					targetObj = targetField + "." + targetIdx;
					assignPicture(formObj, sourceObj, targetObj);
					break;
				}
			}
		}
		clearSelection(formObj, sourceField);
		clearSelection(formObj, targetField);
	}
}
function isfullassignedPictures(formObj, targetField){
	var output = true;
	var i = 0;
	var targetIdx = 0;
	for(var i=0; i<parseInt(formObj[targetField + '.length'].value); i++){
		targetIdx++;
		if(formObj[targetField + "." + targetIdx + '.picture'].value == ""){
			output = false;
			break;
		}
	}
	return(output);
}
function unassignPicture(formObj, target){
	if(formObj){
		targetImg = document.getElementById(target + '.thumb');
		formObj[target + '.picture'].value = "";
		formObj[target + '.pictureCollection'].value = "";
		targetImg.style.visibility = "hidden";
		targetImg.style.width = "96px";
		targetImg.style.height = "96px";
		targetImg.style.marginTop = "0px";
		targetImg.style.marginBottom = "0px";
		targetImg.src = "/view/images/common/shim.gif";
		targetImg.style.visibility = "visible";
	}
}
function unassignPictures(formObj, targetField){
	if(formObj && formObj[targetField] && formObj[targetField].value != ""){
		clearList = formObj[targetField].value.split(",");
		for(var i=0; i<clearList.length; i++){
			targetObj = targetField + "." + clearList[i];
			unassignPicture(formObj, targetObj);
		}
		clearSelection(formObj, targetField);
	}
}
function editPreview(formObj, formField, actionStr){
	var iseditable = false;
	if(formObj && formObj[formField]){
		if(parseInt(formObj[formField].value) > 0){
			actionStr = actionStr + "&step=" + formObj[formField].value;
			iseditable = true;
		}
	}
	if(actionStr && iseditable){
		doFormAction(formObj, actionStr);
	}
	else{
		alert(ERROR_WIZARD_NOEDIT);
	}
}
function isCheckedRadio(formObj, formField, value){
	var ischecked = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].length){
			for(var i=0; i<formObj[formField].length; i++){
				if(formObj[formField][i].value == value && formObj[formField][i].checked){
					ischecked = true;
					break;
				}
			}
		}
		else if(formObj[formField].value == value && formObj[formField].checked){
			ischecked = true;
		}
	}
	return(ischecked);
}
function getRadio(formObj, formField){
	var output = "";
	if(formObj && formObj[formField]){
		if(formObj[formField].length){
			for(var i=0; i<formObj[formField].length; i++){
				if(formObj[formField][i].checked){
					output = formObj[formField][i].value;
					break;
				}
			}
		}
		else if(formObj[formField].value){
			output = formObj[formField].value;
		}
	}
	return(output);
}
function clearRadio(formObj, formField){
	if(formObj && formObj[formField]){
		if(formObj[formField].length){
			for(var i=0; i<formObj[formField].length; i++){
				formObj[formField][i].checked = false;
			}
		}
	}
}
function getDropDown(formObj, formField){
	var output = "";
	if(formObj && formObj[formField]){
		if(formObj[formField].options && formObj[formField].options.length >= 1){
			thisField = formObj[formField];
			output = formObj[formField][formObj[formField].selectedIndex].value;
		}
		else if(formObj[formField].value){
			output = formObj[formField].value;
		}
	}
	return(output);
}
function isDropDown(formObj, formField){
	var output = null;
	if(formObj && formObj[formField]){
		if(formObj[formField].options && formObj[formField].options.length > 1){
			output = true;
		}
		else{
			output = false;
		}
	}
	return(output);
}
function selectRadio(formObj, formField, value, actionStr){
	var haschanged = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].length){
			for(var i=0; i<formObj[formField].length; i++){
				if(formObj[formField][i].value == value && !formObj[formField][i].checked){
					formObj[formField][i].checked = true;
					haschanged = true;
					break;
				}
			}
		}
		else if(formObj[formField].value == value){
			formObj[formField].checked = true;
		}
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
}
function hasCheckbox(formObj, formField){
	var haschecked = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].length){
			for(var i=0; i<formObj[formField].length; i++){
				if(formObj[formField][i].checked == true){
					haschecked = true;
					break;
				}
			}
		}
		else if(formObj[formField].checked == true){
			haschecked = true;
		}
	}	
	return(haschecked);
}
function selectCheckbox(formObj, formField, value, actionStr){
	if(formObj && formObj[formField]){
		if(formObj[formField].length){
			for(var i=0; i<formObj[formField].length; i++){
				if(value == true){
					formObj[formField][i].checked = true;
				}
				else if(value == false){
					formObj[formField][i].checked = false;
				}
				else if(formObj[formField][i].value == value){
					formObj[formField][i].checked = true;
					break;
				}
			}
		}
		else if(value == true){
			formObj[formField].checked = true;
		}
		else if(value == false){
			formObj[formField].checked = false;
		}
		else if(formObj[formField].value == value){
			formObj[formField].checked = true;
		}
		else if(!value){
			formObj[formField].checked = !formObj[formField].checked;
		}
	}
	if(actionStr){
		doFormAction(formObj, actionStr);
	}
}
function toggleCheckbox(formObj, formField, value, actionStr){
	if(formObj && formObj[formField]){
		if(formObj[formField].length){
			for(var i=0; i<formObj[formField].length; i++){
				if(value == true && value.toString() == "true"){
					formObj[formField][i].checked = !formObj[formField][i].checked;
				}
				else if(formObj[formField][i].value == value){
					formObj[formField][i].checked = !formObj[formField][i].checked;
					break;
				}
			}
		}
		else if(value == true){
			formObj[formField].checked = !formObj[formField].checked;
		}
		else if(formObj[formField].value == value){
			formObj[formField].checked = !formObj[formField].checked;
		}
	}
	if(actionStr){
		doFormAction(formObj, actionStr);
	}
}
function setBooleanCheckbox(formObj, formField, value, actionStr){
	if(formObj && formObj[formField]){
		formObj[formField].value = value;
	}
	if(actionStr){
		doFormAction(formObj, actionStr);
	}
}
function selectDropDown(formObj, formField, value, actionStr){
	if(formObj && formObj[formField]){
		if(formObj[formField].options){
			for(var i=0; i<formObj[formField].options.length; i++){
				if(formObj[formField].options[i].value == value){
					formObj[formField].selectedIndex = i;
					break;
				}
			}
		}
	}
	if(actionStr){
		doFormAction(formObj, actionStr);
	}
}
function nextSelectOption(formObj, formField, actionStr){
	var haschanged = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].length && formObj[formField].selectedIndex < formObj[formField].length-1){
			formObj[formField].selectedIndex++;
			haschanged = true;
		}
		else if(formObj[formField].length && formObj[formField].selectedIndex == formObj[formField].length-1){
			formObj[formField].selectedIndex = 0;
			haschanged = true;
		}
		if(actionStr && haschanged){
			doFormAction(formObj, actionStr);
		}
	}
}
function previousSelectOption(formObj, formField, actionStr){
	var haschanged = false;
	if(formObj && formObj[formField]){
		if(formObj[formField].length && formObj[formField].selectedIndex > 0){
			formObj[formField].selectedIndex--;
			haschanged = true;
		}
		else if(formObj[formField].length && formObj[formField].selectedIndex == 0){
			formObj[formField].selectedIndex = formObj[formField].length-1;
			haschanged = true;
		}
		if(actionStr && haschanged){
			doFormAction(formObj, actionStr);
		}
	}
}
function nextThumb(formObj, itemField, collectionField, actionStr){
	var haschanged = false;
	var currentIdx = 0;
	var currentId = "";
	var currentObj = null;
	if(formObj && formObj[itemField]){
		valueList = formObj[itemField + 'list'].value.split(",");
		for(var i=0; i<valueList.length; i++){
			if(valueList[i] == formObj[itemField].value){
				currentIdx = i;
				break;
			}
		}
		
		if(currentIdx < valueList.length-1){
			currentIdx++;
		}
		else if(currentIdx == valueList.length-1){
			if(isDropDown(formObj, collectionField)){
				nextSelectOption(formObj, collectionField, actionStr);
			}
			else{
				currentIdx = 0;
			}
		}
		currentId = itemField + "_" + valueList[currentIdx];
		currentObj = document.getElementById(currentId);
		if(currentObj){
			thisPreview = currentObj.getElementsByTagName("a");
			if(thisPreview && thisPreview[0] && thisPreview[0].getAttribute("onclick"))
				eval(getAttributeValue(thisPreview[0],"onclick"));
		}
	}
}
function previousThumb(formObj, itemField, collectionField, actionStr){
	var haschanged = false;
	var currentIdx = 0;
	var currentId = "";
	var currentObj = null;
	if(formObj && formObj[itemField]){
		valueList = formObj[itemField + 'list'].value.split(",");
		for(var i=0; i<valueList.length; i++){
			if(valueList[i] == formObj[itemField].value){
				currentIdx = i;
				break;
			}
		}
		if(currentIdx > 0){
			currentIdx--;
		}
		else if(currentIdx == 0){
			if(isDropDown(formObj, collectionField)){
				previousSelectOption(formObj, collectionField, actionStr);
			}
			else{
				currentIdx = valueList.length-1;
			}
		}
		currentId = itemField + "_" + valueList[currentIdx];
		currentObj = document.getElementById(currentId);
		if(currentObj){
			thisPreview = currentObj.getElementsByTagName("a");
			if(thisPreview && thisPreview[0] && thisPreview[0].getAttribute("onclick"))
				eval(getAttributeValue(thisPreview[0],"onclick"));
		}
	}
}

function getAttributeValue(obj, key){
	var output = "";
	var attribStr;
	var isFunction;
	if(obj && obj.getAttribute(key)){
		attribStr = obj.getAttribute(key).toString();
		attribStr = strReplace(attribStr, "\n", "");
		attribStr = strReplace(attribStr, "\r", "");
		isFunction = attribStr.split("{");
		if(isFunction.length > 1){
			output = strReplace(isFunction[1],"}","");
		}
		else{
			output = attribStr;
		}
	}
	return(output);
}
function setWizardMode(formObj, value, actionStr){
	var haschanged = false;
	if(formObj && formObj['wizardmode']){
		if(formObj['wizardmode'].length){
			for(var i=0; i<formObj['wizardmode'].length; i++){
				if(formObj['wizardmode'][i].value == value && !formObj['wizardmode'][i].checked){
					formObj['wizardmode'][i].checked = true;
					haschanged = true;
					break;
				}
			}
		}
		else if(formObj['wizardmode'].value == value){
			formObj['wizardmode'].checked = true;
		}
	}
	if(value == "new" && formObj['id']){
		formObj['id'].value = "";	
	}
	if(actionStr && haschanged){
		doFormAction(formObj, actionStr);
	}
}
function getWizardStep(formObj){
	if(formObj && stepbar){
		doFormAction(formObj, stepbar.list[stepbar.current-1].href);
	}
}
function setWizardStepBar(formObj, step){
	if(formObj && document.getElementById("stepbar") && stepbar){
		stepbar.current = step;
		for(var i=0; i<stepbar.list.length; i++){
			idx = i+1;
			label = document.getElementById("stepbarlabel_" + idx);
			digit = document.getElementById("stepbardigit_" + idx);
			href = document.getElementById("stepbarlink_" + idx);
			if(idx == stepbar.current){
				label.className = "text_product";
				label.style.cursor = "default";
				label.onclick = "";
				digit.className = "product";
				digit.style.backgroundImage = "url(/view/images/digits/medium/line2dots_CCCCCC.gif)";
				href.style.cursor = "default";
				href.onclick = "";
				href.className = "d" + idx + "on";
			}
			else if(idx < stepbar.current){
				label.className = "link_stepBack";
				label.style.cursor = "pointer";
				eval("label.onclick = function() { doFormAction(document.theform, '" + stepbar.list[i].href + "'); }");
				digit.className = "neutral";
				digit.style.backgroundImage = "url(/view/images/digits/medium/line_CCCCCC.gif)";
				href.style.cursor = "pointer";
				eval("href.onclick = function() { doFormAction(document.theform, '" + stepbar.list[i].href + "'); }");
				href.className = "d" + idx + "on";
			}
			else{
				label.className = "link_stepNext";
				label.style.cursor = "pointer";
				eval("label.onclick = function() { doFormAction(document.theform, '" + stepbar.list[i].href + "'); }");
				digit.className = "neutral";
				digit.style.backgroundImage = "url(/view/images/digits/medium/dots_CCCCCC.gif)";
				href.style.cursor = "pointer";
				eval("href.onclick = function() { doFormAction(document.theform, '" + stepbar.list[i].href + "'); }");
				href.className = "d" + idx + "off";
			}
		}
	}
}
function newCalendarEvent(formObj){
	if(formObj){
		formObj["event.addInMyEvent"].value = 1;
		formObj["event.day"].disabled = false;
		setHidden("calendareditor");
		setVisible("eventeditor,eventselector");
	}
}
function cancelCalendarEventAdd(formObj){
	if(formObj){
		formObj["event.day"].selectedIndex = 0;
		formObj["event.text"].value = "";
		setColor(formObj, "event.color", "-");
		setHidden("eventselector,eventeditor");
		setVisible("calendareditor");
	}
}
function editCalendarEvent(formObj, day){
	if(formObj && formObj["event." + day + ".day"]){
		selectDropDown(formObj, "event.day", formObj["event." + day + ".day"].value);
		formObj["event.day"].disabled = true;
		formObj["event.text"].value = formObj["event." + day + ".text"].value;
		formObj["event.addInMyEvent"].value = 0;
		setColor(formObj, "event.color", formObj["event." + day + ".color"].value);
		setHidden("calendareditor,eventselector");
		setVisible("eventeditor");
	}
}
function deleteCalendarEvent(formObj, day, messageStr, actionStr){
	if(formObj && formObj["event." + day + ".day"] && window.confirm(messageStr)){
		selectDropDown(formObj, "event.day", formObj["event." + day + ".day"].value);
		formObj["event.text"].value = "";
		setColor(formObj, "event.color", formObj["event." + day + ".color"].value);
	}
	if(actionStr){
		doFormAction(formObj, actionStr);
	}
}
function addCalendarEvent(formObj, actionStr){
	if(formObj){
		if(hasCheckbox(formObj, "event.selectedMyEventList") || (formObj["event.day"].selectedIndex > 0 && formObj["event.text"].value != "")){
			currenday = formObj["event.day"].options[formObj["event.day"].selectedIndex].value;
			if(formObj["event." + currenday + ".text"] && formObj["event.day"].disabled == false){
				formObj["event.text"].value = formObj["event." + currenday + ".text"].value + " - " + formObj["event.text"].value;
				formObj["event.addInMyEvent"].value = 0;
			}
			formObj["event.day"].disabled = false;
			doFormAction(formObj, actionStr);
		}
		else{
			alert(ERROR_FORM_MANDATORYFIELD_MISSING);
		}
	}
}
function setCartQuantity(formObj, formField, value, minValue, maxValue, stepValue, warnmsgStr, delmsgStr, actionStr){
	if(formObj && formObj[formField]){
		if(value){
			checkValue = parseInt(formObj[formField].value) + parseInt(value);
		}
		else{
			checkValue = parseInt(formObj[formField].value);
		}
		if (isNaN(checkValue)) {
			checkValue = minValue;
		}
		if (maxValue > 1 && checkValue > maxValue) {
			checkValue = maxValue;
		}
		if(stepValue > 1) {
			var tmpValue = checkValue - minValue;
			if (tmpValue > 0) {
				if ((tmpValue % stepValue) > 0) {
					checkValue = minValue + ((parseInt(tmpValue / stepValue) + 1) * stepValue);
				}
			}
		}
		if (checkValue < minValue) {
			messageStr = setMessageParam(warnmsgStr,minValue) + "\n\n" + delmsgStr;
			if(window.confirm(messageStr)){
				checkValue = 0;
			}
			else{
				checkValue = minValue;
			}
		}
		formObj[formField].value = checkValue;
	}
	if(actionStr){
		doFormAction(formObj, actionStr);
	}
}
function clearCartItem(formObj, formField, messageStr, actionStr){
	if(formObj && formObj[formField]){
		if(actionStr && window.confirm(messageStr)){
			formObj[formField].value = 0;
			doFormAction(formObj, actionStr);
		}
	}
}
function setAllPhotoprints(resp){
	response = parseData(resp);
	if(response && response.data && response.data.length){
		for(var j=0; j<response.data.length; j++){

			thisForm = document["itemform_" + response.data[j].id];
			if(response.ispreview && response.ispreview == "true"){
				
				document.getElementById("qualitylabel_" + response.data[j].id).innerHTML = response.data[j].dpiqualityxlat;
				document.getElementById("qualitydot_" + response.data[j].id).className = "q" + (Math.floor(parseInt(response.data[j].dpiqualitypercent)/10));
				if(response.data[j].bordercolor != "-"){
					document.getElementById("colordot_" + response.data[j].id).style.backgroundColor = response.data[j].bordercolor;
					document.getElementById("colordot_" + response.data[j].id).style.visibility = "visible";
				}
				else{
					document.getElementById("colordot_" + response.data[j].id).style.visibility = "hidden";
				}
				
				document.getElementById("thumb_" + response.data[j].id).src = response.data[j].url;
				document.getElementById("thumb_" + response.data[j].id).width = response.data[j].width;
				document.getElementById("thumb_" + response.data[j].id).height = response.data[j].height;
				document.getElementById("thumb_" + response.data[j].id).style.marginTop = Math.round(7 + (96 - response.data[j].height) / 2) + "px";
				
				selectDropDown(thisForm, "modelFormat", response.data[j].modelformat);
				selectDropDown(thisForm, "borderColor", response.data[j].bordercolor);
				selectRadio(thisForm, "paper", response.data[j].paper);
				selectRadio(thisForm, "isCropped", response.data[j].iscropped);
				
			}
			if(response.isprice && response.isprice == "true"){
				document["itemform_" + response.data[j].id].quantity.value = response.data[j].quantity;
				document["itemform_" + response.data[j].id].previousQuantity.value = response.data[j].quantity;
				document.getElementById("total_" + response.data[j].id).innerHTML = formatNumber(response.data[j].totalprice * parseFloat(document.theform.currencyRate.value) * parseFloat(document.theform.fullVATRate.value), document.theform.currency.value, 1);
			}
			thisForm.backprint.value = response.data[j].backprint;

		}
		if(response.isprice && response.isprice == "true"){
			// Rebuild Totals
			var totalTaxIn = 0;
			var tableObj = document.createElement("table");
			var tableBdy = document.createElement("tbody");
			tableObj.setAttribute("id","totaldetails");
			tableObj.setAttribute("cellpadding",0);
			tableObj.setAttribute("cellspacing",0);
			tableObj.setAttribute("align","right");
			for(var i=0; i<response.list.total.length; i++){
				var tr = document.createElement("tr");
				var td = document.createElement("td");
					td.className = "subcell";
					td.style.textAlign = "right";
				if(response.list.total.length == 1)
					td.innerHTML = strReplace(document.theform.XLAT_MyPhotoprintTotal.value,"{0}",response.list.total[i].quantity) + " " + response.list.total[i].format + ":";
				else if(i == 0)
					td.innerHTML = strReplace(document.theform.XLAT_MyPhotoprintTotal.value,"{0}",response.list.total[i].quantity) + " " + document.theform.XLAT_where.value + " " + response.list.total[i].quantity + " " + document.theform.XLAT_prints.value + " " + response.list.total[i].format + ":";
				else
					td.innerHTML = response.list.total[i].quantity + " " + document.theform.XLAT_prints.value + " " + response.list.total[i].format + ":";
				tr.appendChild(td);
				var td = document.createElement("td");
					td.className = "subcell";
					td.style.textAlign = "right";
					td.innerHTML = formatNumber(response.list.total[i].totalprice * parseFloat(document.theform.currencyRate.value) * parseFloat(document.theform.fullVATRate.value), document.theform.currency.value, 1);
					totalTaxIn += response.list.total[i].totalprice;
				tr.appendChild(td);
				tableBdy.appendChild(tr);
			}
			var tr = document.createElement("tr");
			var td = document.createElement("td");
				td.className = "subcell";
				td.style.textAlign = "right";
				td.innerHTML = document.theform.XLAT_TotalTaxIn.value + ":";
			tr.appendChild(td);
			var td = document.createElement("td");
				td.className = "subcell";
				td.style.textAlign = "right";
				td.innerHTML = "<div style='width: 80px;'><strong>" + formatNumber(totalTaxIn * parseFloat(document.theform.currencyRate.value) * parseFloat(document.theform.fullVATRate.value), document.theform.currency.value, 1) + "</strong></div>";
			tr.appendChild(td);
			tableBdy.appendChild(tr);
			
			tableObj.appendChild(tableBdy);

			theTotals = document.getElementById("totals");
			oldTotals = document.getElementById("totaldetails");
			theTotals.removeChild(oldTotals);
			theTotals.appendChild(tableObj);

		}
		document.body.style.cursor = "default";
		document.getElementById("applyall").style.cursor = "pointer";
	}
}
function setPhotoprintItem(resp){
	response = parseData(resp);
	if(response && response.data && response.data.id){
		if(response.data.quantity == 0){
			thisItem = document.getElementById("item_" + response.data.id);			
			thisItem.parentNode.removeChild(thisItem);
		}
		else{
			thisForm = document["itemform_" + response.data.id];
			if(response.data.ispreview && response.data.ispreview == "true"){
				document.getElementById("qualitylabel_" + response.data.id).innerHTML = response.data.dpiqualityxlat;
				document.getElementById("qualitydot_" + response.data.id).className = "q" + (Math.floor(parseInt(response.data.dpiqualitypercent)/10));
				if(response.data.bordercolor != "-"){
					document.getElementById("colordot_" + response.data.id).style.backgroundColor = response.data.bordercolor;
					document.getElementById("colordot_" + response.data.id).style.visibility = "visible";
				}
				else{
					document.getElementById("colordot_" + response.data.id).style.visibility = "hidden";
				}
				document.getElementById("thumb_" + response.data.id).src = response.data.url;
				document.getElementById("thumb_" + response.data.id).width = response.data.width;
				document.getElementById("thumb_" + response.data.id).height = response.data.height;
				document.getElementById("thumb_" + response.data.id).style.marginTop = Math.round(7 + (96 - response.data.height) / 2) + "px";
	
				for(var i=0; i<thisForm.modelFormat.options.length; i++){
					if(thisForm.modelFormat.options[i].value == response.data.modelformat){
						thisForm.modelFormat.selectedIndex = i;
						//break;
					}
				}
			}
			thisForm.backprint.value = response.data.backprint;
		}
		if(response.data.isprice && response.data.isprice == "true"){
			for(var i=0; i<response.list.price.length; i++){
				document["itemform_" + response.list.price[i].i].quantity.value = response.list.price[i].q;
				document["itemform_" + response.list.price[i].i].previousQuantity.value = response.list.price[i].q;
				document.getElementById("total_" + response.list.price[i].i).innerHTML = formatNumber(response.list.price[i].t * parseFloat(document.theform.currencyRate.value) * parseFloat(document.theform.fullVATRate.value), document.theform.currency.value, 1);
			}
			// Rebuild Totals
			var totalTaxIn = 0;
			var tableObj = document.createElement("table");
			var tableBdy = document.createElement("tbody");
			tableObj.setAttribute("id","totaldetails");
			tableObj.setAttribute("cellpadding",0);
			tableObj.setAttribute("cellspacing",0);
			tableObj.setAttribute("align","right");
			for(var i=0; i<response.list.total.length; i++){
				var tr = document.createElement("tr");
				var td = document.createElement("td");
					td.className = "subcell";
					td.style.textAlign = "right";
				if(response.list.total.length == 1)
					td.innerHTML = strReplace(document.theform.XLAT_MyPhotoprintTotal.value,"{0}",response.list.total[i].quantity) + " " + response.list.total[i].format + ":";
				else if(i == 0)
					td.innerHTML = strReplace(document.theform.XLAT_MyPhotoprintTotal.value,"{0}",response.list.total[i].quantity) + " " + document.theform.XLAT_where.value + " " + response.list.total[i].quantity + " " + document.theform.XLAT_prints.value + " " + response.list.total[i].format + ":";
				else
					td.innerHTML = response.list.total[i].quantity + " " + document.theform.XLAT_prints.value + " " + response.list.total[i].format + ":";
				tr.appendChild(td);
				var td = document.createElement("td");
					td.className = "subcell";
					td.style.textAlign = "right";
					td.innerHTML = formatNumber(response.list.total[i].totalprice * parseFloat(document.theform.currencyRate.value) * parseFloat(document.theform.fullVATRate.value), document.theform.currency.value, 1);
					totalTaxIn += response.list.total[i].totalprice;
				tr.appendChild(td);
				tableBdy.appendChild(tr);
			}
			var tr = document.createElement("tr");
			var td = document.createElement("td");
				td.className = "subcell";
				td.style.textAlign = "right";
				td.innerHTML = document.theform.XLAT_TotalTaxIn.value + ":";
			tr.appendChild(td);
			var td = document.createElement("td");
				td.className = "subcell";
				td.style.textAlign = "right";
				td.innerHTML = "<div style='width: 80px;'><strong>" + formatNumber(totalTaxIn * parseFloat(document.theform.currencyRate.value) * parseFloat(document.theform.fullVATRate.value), document.theform.currency.value, 1) + "</strong></div>";
			tr.appendChild(td);
			tableBdy.appendChild(tr);
			
			tableObj.appendChild(tableBdy);

			theTotals = document.getElementById("totals");
			oldTotals = document.getElementById("totaldetails");
			theTotals.removeChild(oldTotals);
			theTotals.appendChild(tableObj);

		}
	}
}
function setPhotoprintQuantity(formObj, formField, previousValue, messageStr){
	if(formObj && formObj[formField]){
		if(parseInt(formObj[formField].value) == 0){
			if(window.confirm(messageStr)){
				formObj[formField].value = 0;
				updatePhotoprintItem(formObj);
			}
			else{
				formObj[formField].value = previousValue;
				updatePhotoprintItem(formObj);
			}
		}
		else{
			updatePhotoprintItem(formObj);
		}
	}
}
function clearPhotoprintItem(formObj, formField, messageStr){
	if(formObj && formObj[formField]){
		if(window.confirm(messageStr)){
			formObj[formField].value = 0;
			updatePhotoprintItem(formObj);
		}
	}
}
function updatePhotoprintItem(formObj){
	if(formObj && formObj['formAction']){
		if(formObj['modelFormat']){
			if(getDropDown(formObj, 'modelFormat') == "PPA" || getDropDown(formObj, 'modelFormat') == "PPD")
				formObj['modelFormat'].selectedIndex++;
		}
		var vars = toQueryString(formObj);
		var myAjax = new Ajax.Request(
			formObj['formAction'].value, 
			{
				parameters: vars, 
				onComplete: setPhotoprintItem
			});
	}
}
function updateAllPhotoprints(formObj){
	if(formObj && formObj['formAction']){
		if(getDropDown(formObj, 'modelFormat') != "" || getDropDown(formObj, 'borderColor') != "" || getRadio(formObj, "paper") != "" || getRadio(formObj, "isCropped") != "" || formObj['backprint'].value != "" || getDropDown(formObj, "quantity") != ""){   
			document.body.style.cursor = "wait";
			document.getElementById("applyall").style.cursor = "wait";
			if(formObj['modelFormat']){
				if(getDropDown(formObj, 'modelFormat') == "PPA" || getDropDown(formObj, 'modelFormat') == "PPD")
					formObj['modelFormat'].selectedIndex++;
			}
			var vars = toQueryString(formObj);
			var myAjax = new Ajax.Request(
				formObj['formAction'].value, 
				{
					parameters: vars, 
					onComplete: setAllPhotoprints
				});
			resetPhotoprintForm(formObj);
		}
	}
}
function resetPhotoprintForm(formObj){
	if(formObj && formObj['formName']){
		if(formObj['formName'].value == "picturePrintApplyAll"){
			formObj['modelFormat'].selectedIndex = 0;
			formObj['borderColor'].selectedIndex = 0;
			clearRadio(formObj,'paper');
			clearRadio(formObj,'isCropped');
			formObj['backprint'].value = "";
			formObj['quantity'].selectedIndex = 0;
		}
	}
}
function uploaderPreview(formObj, fieldIdx) {
	if(formObj){
		var formField = "file_" + fieldIdx;
		if(formObj[formField] && formObj[formField].value != ""){

			var previewObj = document.getElementById('preview_' + fieldIdx);
			var previewName = document.getElementById('name_' + fieldIdx);
			
			if(navigator.userAgent.indexOf('MSIE') != -1){
				previewObj.src = "file://" + formObj[formField].value;
			}
			else{
				previewObj.src = "/view/images/common/nopic_F31058_FFFFFF.gif";
			}
			previewName.innerHTML = getFileName(formObj[formField].value);
		}
	}
}

function dd_dataInit(formObj, drag_items, nodrag_items){
	this.startx = 0;
	this.starty = 0;
	this.formObj = formObj;
	this.formField = "";
	this.source = null;
	this.target = null;
	this.hover = null;
	this.parent = null;
}
function dd_saveItem(dd_obj){
	var itemData = null;
	if(dd_obj){
		itemData = new Object();
		itemData.obj = dd_obj;
		itemData.name = dd_obj.name;
		itemData.params = itemData.name.split(".");
		itemData.field = itemData.params[0];
		itemData.value = itemData.params[1];
		if(dd_datas.formObj[itemData.field + ".type"])
			itemData.type = dd_datas.formObj[itemData.field + ".type"].value;
		else
			itemData.type = "";
	}
	return(itemData);
}
function dd_attachChilds(formObj, sourceField){
	if(formObj && formObj[sourceField] && dd_datas.parent){
		if(formObj[sourceField].value != "")
			sourceList = formObj[sourceField].value.split(",");
		else
			sourceList = new Array();
		if(sourceList.length > 1){
			for(var i=1; i<sourceList.length; i++){
				dd.elements[dd_datas.parent.name].addChild(dd.elements[sourceField + "." + sourceList[i]])
			}
		}
	}
}
function dd_detachChilds(formObj, sourceField){
	if(formObj && formObj[sourceField] && dd_datas.parent){
		if(formObj[sourceField].value != "")
			sourceList = formObj[sourceField].value.split(",");
		else
			sourceList = new Array();
		if(sourceList.length > 1){
			for(var i=1; i<sourceList.length; i++){
				dd.elements[dd_datas.parent.name].detachChild(dd.elements[sourceField + "." + sourceList[i]])
			}
		}
		dd_datas.parent = null;
	}
}

function dd_dragItem(){
	
	dd_datas.source = dd_saveItem(dd.obj);
	dd_datas.parent = dd_datas.source.name;
	
	addSelection(dd_datas.formObj,dd_datas.source.field,dd_datas.source.value);
		
	dd_datas.startx = dd_datas.source.obj.x;
	dd_datas.starty = dd_datas.source.obj.y;
	
	document.getElementById(dd_datas.source.name).className = "selected";
	document.getElementById(dd_datas.source.name).style.position = "absolute";
	
}
function dd_dropItem(){
	var isValidDrop = false;

	dd_datas.target = dd_saveItem(dd.obj.getEltBelow());
	
	if(dd_datas.target != null){
		
		if((dd_datas.source.type == "source" || dd_datas.source.type == "target") && dd_datas.target.type == "target"){
			
			isValidDrop = true;

			if(dd_datas.source.type == "target" && dd_datas.target.value == "bin"){
				unassignPictures(dd_datas.formObj,dd_datas.source.field);
			}
			else if(dd_datas.source.type == "target" && dd_datas.target.value != "bin"){
				swapPicture(dd_datas.formObj,dd_datas.source.name,dd_datas.target.name);
				clearSelection(dd_datas.formObj, dd_datas.source.field);
			}
			else if(dd_datas.source.type == "source" && dd_datas.target.value != "bin"){
				assignPictures(dd_datas.formObj,dd_datas.source.field,dd_datas.target.field,dd_datas.target.value);
			}
		}
		
		
		dd.obj.moveBy(dd_datas.startx-dd.obj.x,dd_datas.starty-dd.obj.y);
		
		if(dd_datas.source.value != "bin")
			document.getElementById(dd_datas.source.name).className = "";
		else
			document.getElementById(dd_datas.source.name).className = "bin";
			
		removeSelection(dd_datas.formObj,dd_datas.source.field,dd_datas.source.value);
		
		if(dd_datas.hover){
			dd.elements[dd_datas.hover.name].setBgColor("#ffffff");
		}
	}
	else{
		dd.obj.moveTo(dd_datas.startx,dd_datas.starty);
	}
	
}
function dd_moveItem(){
	var hoverObj = dd.obj.getEltBelow();
	
	if((dd_datas.hover && hoverObj && dd_datas.hover.name != hoverObj.name) || (dd_datas.hover && !hoverObj)){
		dd.elements[dd_datas.hover.name].setBgColor("#ffffff");
	}
	if(hoverObj){
		dd_datas.hover = dd_saveItem(hoverObj);
		if(dd_datas.hover.type == "target")
			dd.elements[dd_datas.hover.name].setBgColor("#cccccc");
		else
			dd_datas.hover = null;
	}
}

function dd_resizeItem(){
	//window.status = 'dd.elements.' + dd.obj.name + '.w  = ' + dd.obj.w + '	 dd.elements.' + dd.obj.name + '.h = ' + dd.obj.h;
}

function dd_dragInit(formObj, formField, dragId){

	var dragObj = formField + "." + dragId
	
	dd_datas.formObj = formObj;
	dd_datas.formField = formField;
	
	if(document.getElementById(dragObj) && !dd.elements[dragObj]){
		document.getElementById(dragObj).style.position = "absolute";
		ADD_DHTML(dragObj);
	}
}
function dd_scrollParent(objId, recordCount){
	alert(document.getElementById("scrollbar").offsetHeight + "-" + document.getElementById("scrollbar").scrollTop);
}
function focusField(){
	if(document.forms){
		for(var i=0; i<document.forms.length; i++){
			formObj = document.forms[i];
			if(formObj['formFocus']){
				if(formObj['formFocus'].value != "" && formObj[formObj['formFocus'].value])
					formObj[formObj['formFocus'].value].focus();
			}
		}
	}
}
function hideMessage(msgObj){
	if(window.timer)
		window.clearTimeout(timer);
	if(parseInt(msgObj.style.top) + msgObj.offsetHeight > 0){
		timer = window.setTimeout('hideMessage(msgObj)', sysmessageSpeed);
		msgObj.style.top = (parseInt(msgObj.style.top) - 1) + "px" ;
	}
	else{
		msgObj.style.visibility = "hidden";
	}
}
function revealMessage(msgObj){
	if(window.timer)
		window.clearTimeout(timer);
	if(parseInt(msgObj.style.top) < 0){
		timer = window.setTimeout('revealMessage(msgObj)', sysmessageSpeed);
		msgObj.style.top = (parseInt(msgObj.style.top) + 1) + "px" ;
	}
	else{
		check = msgObj.getElementsByTagName("TABLE");
		if(check && check[0] && check[0].className){
			if(check[0].className == "info")
				timer = window.setTimeout('hideMessage(msgObj)', sysmessageDelay);
		}
	}
}
function checkFloatingObjects(){
	if(document.getElementById("pictureselected") && getWinScrollY() > 0)
		dd.elements["pictureselected"].moveTo(dd.elements["pictureselected"].x,315+getWinScrollY());
}
function initScrolls(){
	if(document.getElementById("selector") && selector_t){
		document.getElementById("selector").scrollTop = selector_t;
	}
}
function closeMessage(msgId){
	if(document.getElementById(msgId)){
		msgObj = document.getElementById(msgId);
		hideMessage(msgObj);
	}
}
function initMessage(msgId){
	if(!centerX){
		initWinsize();
	}
	if(document.getElementById(msgId)){
		msgObj = document.getElementById(msgId);
		msgObj.style.left = (centerX - (msgObj.offsetWidth / 2)) + "px";
		msgObj.style.top = (-1 - (msgObj.offsetHeight)) + "px";
		msgObj.style.visibility = "visible";
		revealMessage(msgObj);
	}
}
function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function findPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function getWinScrollX(){
	var scrollX = 0;
	if (self.pageXOffset)
		scrollX = self.pageXOffset;
	else if(document.documentElement && document.documentElement.scrollLeft)
		scrollX = document.documentElement.scrollLeft;
	else if (document.body)
		scrollX = document.body.scrollLeft;
	return scrollX;
}
function getWinScrollY(){
	var scrollY = 0;
	if (self.pageYOffset)
		scrollY = self.pageYOffset;
	else if(document.documentElement && document.documentElement.scrollTop)
		scrollY = document.documentElement.scrollTop;
	else if (document.body)
		scrollY = document.body.scrollTop;
	return scrollY;
}
function initWinsize(){
	windowW = self.screen.availWidth;
	windowH = self.screen.availHeight;
	if(self.innerHeight){
		centerX = (self.innerWidth / 2);
		centerY = (self.innerHeight / 2);
	}
	else if(document.documentElement && document.documentElement.clientHeight){
		centerX = (document.documentElement.clientWidth / 2);
		centerY = (document.documentElement.clientHeight / 2);
	}
	else if(document.body){
		centerX = (document.body.clientWidth / 2);
		centerY = (document.body.clientHeight / 2);
	}
}
function getWinWidth(){
	var winWidth = 0;
	if (typeof(window.innerWidth) == 'number')
		winWidth = window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		winWidth = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		winWidth = document.body.clientWidth;
	return winWidth;
}
function getWinHeight(){
	var winHeight = 0;
	if (typeof(window.innerHeight) == 'number')
		winHeight = window.innerHeight;
	else if(document.documentElement && document.documentElement.clientHeight)
		winHeight = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		winHeight = document.body.clientHeight;
	return winHeight;
}
function init(){
	// Init Global Page Functions
	focusField();
	initMessage("sysmessage");
	initScrolls();
	if(self.pageInit)
		pageInit();
}
window.onload = init;
