//jsCloneValues.js//NEW 11Sep2007 *DS*//this is to allow the easy "duplication" of the values in the doc currently being edited,//especially helpful for Sandy as she enters 2 or 3 country locations for a similar AgSoft or MachineryManufacturer record.//NOTE: the "Clone" button (onclick="doClone()") is visible only if the document is in edit mode (i.e. is not being newly-created)//alert('LATER.' + strType)function getFieldName(o){	if(!o)return "";	return (o.name?o.name:(o.length?o[0].name:""));};function getFieldValues(o,bSkipHidden){	var rv="";	if(o)	{		var strType=(o.type?o.type:(o.length?o[0].type:""));		switch(strType)		{		case "text":		case "textarea":		case "password":			rv=[o.value];			break;		case "hidden":			if(!bSkipHidden)rv=[o.value];			break;		case "checkbox":		case "radio":			for(var i=0;i<o.length;i++)			{				rv[rv.length]=o[i].checked?1:0;			};			break;		case "select-one":			rv=[o.selectedIndex];			break;		case "select-multi":			//alert('LATER.' + strType)			break;		default:			break;		};	};	return rv;};function setFieldValues(o, arValues){	if(o)	{		var strType=(o.type?o.type:(o.length?o[0].type:""));		switch(strType)		{		case "text":		case "textarea":		case "password":		case "hidden":			o.value=arValues[0];			break;		case "checkbox":		case "radio":			for(var i=0;i<arValues.length;i++)			{				if(o[i])o[i].checked=(arValues[i]?true:false);			};			break;		case "select-one":			o.selectedIndex=arValues[0];			break;		case "select-multi":			//alert('LATER.' + strType)			break;		default:			break;		};	};	return false;};function getValuesToClone(){	//for each field, grab its value and store inside array GLO_FIELDS ( each element is [Field_Name, [field value1,field value2,field value3] ] );	var rv=[];	var oF=document.forms[0];	var strFieldName="";	bSkip=false;		if(oF && oF.elements)	{		var oField;		var oFieldInfo=[];		for(var i=0;i<oF.elements.length;i++)		{			oField=oF.elements[i];			strFieldName=getFieldName(oField);			bSkip=(GLO_SKIP_PREFIX && strFieldName.substring(0,GLO_SKIP_PREFIX.length)==GLO_SKIP_PREFIX);			if(!bSkip)bSkip=(GLO_SKIP.indexOf("`" + strFieldName + "`")!=-1);			if(!bSkip)			{				oFieldInfo=getFieldValues(oField,true);				if(oFieldInfo.length)rv[rv.length]=[strFieldName,oFieldInfo];			};		};	};	//return an array of arrays: [Field_Name, [field value1,field value2,field value3] ]	return rv;};function doClone(){	GLO_SKIP_PREFIX="\%\%";	GLO_SKIP="`__Click`\%\%ModDate`State`ButtonClickedTX`NotifyRequestorTX`";	GLO_SKIP+="ArchiveDate`DeleteDate`";	GLO_SKIP+="TypeField`Field7`Field5Lista`Field5Listb`";	GLO_SKIP+="DB2Field1`DB2Label1`DB2TSLabel1`";	GLO_SKIP+="DB2Field5`DB2Label5`DB2Field6`DB2ActiveDate`";	GLO_FIELDS=getValuesToClone();	if(!GLO_FIELDS)	{		alert("Clone failed -- no fields could be identified. (!?)");	}	else	{		//e.g. http://agdev09.agdev.gov.ab.ca/$directories/dcommdty.nsf/AllListings/lst12658?EditDocument&login		var strURL=document.location.href;		strURL=strURL.substring(0,strURL.toLowerCase().indexOf("?editdocument"));		strURL=strURL.substring(0,strURL.toLowerCase().indexOf(".nsf"));		if(strURL && intDocType)		{			strURL+=".nsf/Main?OpenForm&clone=1&type=" + intDocType;			GLO_WIN=window.open(strURL);			GLO_WIN.focus();			GLO_WIN.parentwin=self;		};	};	return false;};function cloneValues(){	//for each field in GLO_FIELDS, paste in the appropriate field value from GLO_VALUES	if(!GLO_WIN || !GLO_FIELDS)return false;	GLO_WIN.focus();		var oFieldInfo=[];	var oField;	for(var i=0;i<GLO_FIELDS.length;i++)	{		oFieldInfo=GLO_FIELDS[i];		oField=GLO_WIN.document.forms[0][oFieldInfo[0]];		if(oField)setFieldValues(oField,oFieldInfo[1]);	};	GLO_WIN.focus();	oField=GLO_WIN.document.forms[0]["TypeField"];	if(oField)oField.focus()	GLO_WIN.GLO_FIELDS=GLO_FIELDS;	GLO_WIN=null;	GLO_FIELDS=null;	GLO_SKIP=null;	GLO_SKIP_PREFIX=null;	return false;};
