pwFormsRollover_onImages=new Array();
function pwFormsLabelItem (objN,label,tip)
{
	frm = d.getElementsByTagName("form");
	for(i=0;i<frm.length;i++) {
		c = frm[i].elements;
		for(j=0;j<c.length;j++) {
			if(c[j].getAttribute("name")==objN) {
				obj=c[j];
				obj.pwLabel=label;
				obj.pwTip=tip;
				break;
				}
			}
		}
}
function pwFormsSubmit(obj)
{
	subfunc=obj.onsubmit;
	if (typeof(subfunc)=="function")
		obj.onsubmit();
	else
		obj.submit();
	
}
function pwFormsSetValue(objN,val)
{
	frm = document.getElementsByTagName("form");
	for(i=0;i<frm.length;i++) {
		c = frm[i].elements;
		for(j=0;j<c.length;j++) {
			if(c[j].getAttribute("name")==objN) {
				obj=c[j];
				obj.pwfrm=frm[i];
				break;
				}
			}
		}
	if (!obj)
		return;
	obj.value=val;
}
function pwFormsCheck (objN,checktype,mode,arg1,arg2,acceptnull)
{
	d=document;
	obj=new Object();
	frm = d.getElementsByTagName("form");
	for(i=0;i<frm.length;i++) {
		c = frm[i].elements;
		for(j=0;j<c.length;j++) {
			if(c[j].getAttribute("name")==objN) {
				obj=c[j];
				obj.pwfrm=frm[i];
				break;
				}
			}
		}
	if (!obj)
		return;
	if (!obj.pwfrm.pwcheckon)
	{
		obj.pwfrm.pwcheckon=new Array();
		subfunc=obj.pwfrm.onsubmit;
		if (typeof(subfunc)=="function")
			obj.pwfrm.onsubmit=function() {if (!pwFormsCheckForm(this)) return false; subfunc();this.submit();}
		else
			obj.pwfrm.onsubmit=function() {if (!pwFormsCheckForm(this)) return false;this.submit();}
		
	}
	obj.pwfrm.pwcheckon.push(obj);
	chfunc=obj.onchange;
	if (typeof(chfunc)=="function")
		obj.onchange=function (){if (!pwFormsCheckItem(this)) return false; chfunc();}
	else
		obj.onchange=function (){if (!pwFormsCheckItem(this)) return false;}
	obj.pwCheckMode=mode;
	obj.pwCheckType=checktype;
	obj.pwArg1=arg1;
	obj.pwArg2=arg2;
	obj.pwAcceptNull=acceptnull;
	
}
function pwFormsCheckForm(obj)
{
	var error="";
	for(i=0;i<obj.pwcheckon.length;i++) {
		if (!pwFormsSilentCheckItem(obj.pwcheckon[i])){
			error+=obj.pwcheckon[i].errormsg;
			error+="\n";
			}
		}
	if (error!="")
	{
		alert(error);
		return false;
	}
	return true;
}
function pwFormsCheckItem(obj)
{
	if (!pwFormsSilentCheckItem(obj))
	{
		alert(obj.errormsg);
		return false;
	}
	return true;	
}
function pwFormsSilentCheckItem(obj)
{
	error=false;
	if (obj.pwAcceptNull && obj.value=="")
		return true;
	switch (obj.pwCheckMode)
	{
		case "Alpha":
			switch (obj.pwCheckType)
			{
				case "Min":
					if (obj.value<obj.pwArg1)
						error=true;
					break;
				case "Max":
					if (obj.value>obj.pwArg1)
						error=true;
					break;
				case "Range":
					if (obj.value<obj.pwArg1 || obj.value>obj.pwArg2)
						error=true;
					break;
			}
			break;
		case "Int":
		{
			val=parseInt(obj.value);
			if (obj.value!=val)
			{
				error=true;
				break;
			}
			if (isNan(val))
			{
				error=true;
				break;
			}
			switch (obj.pwCheckType)
			{
				case "Min":
					if (val<parseInt(obj.pwArg1))
						error=true;
					break;
				case "Max":
					if (val>parseInt(obj.pwArg1))
						error=true;
					break;
				case "Range":
					if (val<parseInt(obj.pwArg1) || val>parseInt(obj.pwArg2))
						error=true;
					break;
			}
			break;
		}
		case "Real":
		{
			val=parseFloat(obj.value);
			if (isNan(val))
			{
				error=true;
				break;
			}
			switch (obj.pwCheckType)
			{
				case "Min":
					if (val<parseFloat(obj.pwArg1))
						error=true;
					break;
				case "Max":
					if (val>parseFloat(obj.pwArg1))
						error=true;
					break;
				case "Range":
					if (val<parseFloat(obj.pwArg1) || val>parseFloat(obj.pwArg2))
						error=true;
					break;
			}
			break;
		}
	}
	if (error)
	{
		if (obj.pwLabel)
			obj.errormsg=obj.pwLabel+": ";
		else
			obj.errormsg=obj.name+": ";
		switch(obj.pwCheckMode)
		{
			case "Alpha":
				obj.errormsg+="Must be an aplhanumeric string, ";
				break;
			case "Int":
				obj.errormsg+="Must be an integer number, ";
				break;
			case "Real":
				obj.errormsg+="Must be a real number, ";
				break;
			
		}
		switch(obj.pwCheckType)
		{
			case "Min":
				obj.errormsg+="greater or equal than "+obj.pwArg1;
				break;
			case "Max":
				obj.errormsg+="little or equal than "+obj.pwArg1;
				break;
			case "Range":
				obj.errormsg+="between (inclusive) "+obj.pwArg1+" and "+obj.pwArg2;
				break;
		}
		obj.value=obj.defaultValue;
		return false;
	}
	return true;
}
function pwFormsSrcRollover(objN,imgOver)
{
	d=document;
	obj=new Object();

	all=d.getElementsByName(objN)
	for (i=0;i<all.length;i++){
		obj=all[i];
		if (!obj.src)
			continue;
		obj.pwOver=new Image();
		obj.pwOver.src=imgOver;
		obj.pwNormalSrc=obj.src;
		over=obj.onmouseover;
		if (typeof(over)=="function")
			obj.onmouseover=function (){this.src=this.pwOver.src; over();}
		else
			obj.onmouseover=function (){this.src=this.pwOver.src;}
	
		out=obj.onmouseout;
		if (typeof(out)=="function")
			obj.onmouseout=function (){this.src=this.pwNormalSrc; out();}
		else
			obj.onmouseout=function (){this.src=this.pwNormalSrc;}
	}			
}

function pwFormsCreateImageElement (objN,on,off,autosub)
{
	d=document;
	obj=new Object();
	events = new Array("onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup");
	// a reference var to all the forms in the document
	frm = d.getElementsByTagName("form");
	for(i=0;i<frm.length;i++) {
		c = frm[i].elements;
		for(j=0;j<c.length;j++) {
			if(c[j].getAttribute("name")==objN) {
				obj=c[j];
				obj.frmIndex=i;
				break;
				}
			}
		}
	if (!obj)
		return;
	obj.onSrc=on;
	obj.offSrc=off;
	obj.style.display = "none";
	n = d.createElement("img");
	n.frmIndex=obj.frmIndex;
// 	n.setAttribute("class","chk");
	n.offSrc=obj.offSrc;
	n.onSrc=obj.onSrc;
	n.setAttribute ("title",obj.getAttribute("title"));
	n.setAttribute ("alt",obj.getAttribute("alt"));
				
	if(obj.checked == false) {
		n.setAttribute("src",n.offSrc);
		n.ison=false;
	} else {
		n.setAttribute("src",n.onSrc);
		n.ison=true;
	}
	frm = d.getElementsByTagName("form");
	n.xid = obj.getAttribute("name");
	n.onclick = function() { pwFormsImageElementRoll(this,0,autosub);return false; }
	obj.parentNode.insertBefore(n,obj.nextSibling)
	obj.objRef = n;
				// assign the checkbox objects event handlers to its replacement image
	for(e=0;e<events.length;e++) if(eval('obj.' +events[e])) eval('n.' + events[e] + '= obj.' + events[e]);
	fn = obj.onchange;
	if(typeof(fn) == "function") {
		obj.onchange = function() { fn(); pwFormsImageElementRoll(this.objRef,1); return false; }
	} else {
		obj.onchange = function () { pwFormsImageElementRoll(this.objRef,1); return false; }
	}

}

function pwFormsImageElementRoll(imgObj,caller,autosub) {
	d=document;
	// if caller is 1, this method has been called from the onchange event of the checkbox, which means
	// the user has clicked the label element. Dont change the checked status of the checkbox in this instance
	// or we'll set it to the opposite of what the user wants. caller is 0 if coming from the onclick event of the image
	
	// reference to the form object
	formObj = d.forms[imgObj.frmIndex];
	// the name of the checkbox we're changing
	objName = imgObj.xid;
	/// change the checked status of the checkbox if coming from the onclick of the image
	if(!caller)formObj.elements[objName].checked = !formObj.elements[objName].checked?true:false;
	// finally, update the image to reflect the current state of the checkbox.
// 	n.setAttribute ("title",c[j].getAttribute("title");
// 	n.setAttribute ("alt",c[j].getAttribute("alt");
	if(imgObj.ison) {
		imgObj.setAttribute("src",imgObj.offSrc);
// 		imgObj.setAttribute("title","click here to select this option.");
// 		imgObj.setAttribute("alt","click here to select this option.");
		imgObj.ison=false;
	} else {
		imgObj.setAttribute("src",imgObj.onSrc);
// 		imgObj.setAttribute("title","click here to deselect this option.");
// 		imgObj.setAttribute("alt","click here to deselect this option.");
		imgObj.ison=true;
	}
	if (autosub)
		pwFormsSubmit(formObj);
// 		formObj.submit();
}











function pwFormsCreateImageElementRadio (objId,on,off,autosub)
{
	d=document;
	obj=new Object();
	events = new Array("onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup");
	// a reference var to all the forms in the document
	frm = d.getElementsByTagName("form");
	for(i=0;i<frm.length;i++) {
		c = frm[i].elements;
		for(j=0;j<c.length;j++) {
			if(c[j].id==objId) {
				obj=c[j];
				obj.frmIndex=i;
				break;
				}
			}
		}
	if (!obj)
		return;
	obj.onSrc=on;
	obj.offSrc=off;
	obj.style.display = "none";
	n = d.createElement("img");
	n.frmIndex=obj.frmIndex;
	n.offSrc=obj.offSrc;
	n.onSrc=obj.onSrc;
	n.setAttribute ("title",obj.getAttribute("title"));
	n.setAttribute ("alt",obj.getAttribute("alt"));
				
	if(obj.checked == false) {
		n.setAttribute("src",n.offSrc);
		n.ison=false;
	} else {
		n.setAttribute("src",n.onSrc);
		n.ison=true;
	}
	frm = d.getElementsByTagName("form");
	n.xid = obj.id;
	n.onclick = function() { pwFormsImageElementRoll(this,0,autosub);return false; }
	obj.parentNode.insertBefore(n,obj.nextSibling)
	obj.objRef = n;
				// assign the checkbox objects event handlers to its replacement image
	for(e=0;e<events.length;e++) if(eval('obj.' +events[e])) eval('n.' + events[e] + '= obj.' + events[e]);
	fn = obj.onchange;
	if(typeof(fn) == "function") {
		obj.onchange = function() { fn(); pwFormsImageElementRollRadio(this.objRef,1); return false; }
	} else {
		obj.onchange = function () { pwFormsImageElementRollRadio(this.objRef,1); return false; }
	}

}
function pwFormsImageElementRollRadio(imgObj,caller,autosub) {
	d=document;
	// if caller is 1, this method has been called from the onchange event of the checkbox, which means
	// the user has clicked the label element. Dont change the checked status of the checkbox in this instance
	// or we'll set it to the opposite of what the user wants. caller is 0 if coming from the onclick event of the image
	
	// reference to the form object
	formObj = d.forms[imgObj.frmIndex];
	// the name of the checkbox we're changing
	objId = imgObj.xid;
	/// change the checked status of the checkbox if coming from the onclick of the image
	if(!caller && !d.getElementById(objId).checked ) d.getElementById(objId).checked = true;
	
	// finally, update the image to reflect the current state of the checkbox.
// 	n.setAttribute ("title",c[j].getAttribute("title");
// 	n.setAttribute ("alt",c[j].getAttribute("alt");
	if(imgObj.ison) {
		imgObj.setAttribute("src",imgObj.offSrc);
		imgObj.ison=false;
	} else {
		imgObj.setAttribute("src",imgObj.onSrc);
		imgObj.ison=true;
	}
	if (autosub && d.getElementById(objId).checked)
		pwFormsSubmit(formObj);
}

