var MyForm={emailstr:/^.+@.+\..{2,3}$/,illegalemailchar:/[\(\)\<\>\,\;\:\'\"\\\[\]\/\s]/,decimal:/^\d+[.]?\d*$/,integer:/^\d+$/,usernamestr:/^[a-zA-Z_0-9]+$/,validate:function(thisform)
{var elements=thisform.elements;var strEmptyFields=new Array();var focuselement=null;for(var i=0;i<elements.length;i++)
{var type=elements[i].type;var id=elements[i].id;var value=elements[i].value;if(id.indexOf("!")>-1)
continue;if((type=="text"||type=="password"||type=="textarea"||type=="select-one"||type=="file")&&id.indexOf("*")>-1&&(value==null||value==''))
{if(focuselement==null)
{focuselement=elements[i];}
var name=elements[i].getAttribute("alt");if(name==null||name==''){name=elements[i].getAttribute("title");}
if(name&&name!='')
strEmptyFields.push(name);else
strEmptyFields.push(elements[i].name);}
else if(type=="text"&&id.indexOf("#")>-1&&!this.checkInteger(value,elements[i]))
return false;else if(type=="text"&&id.indexOf("@")>-1&&!this.checkEmail(value,elements[i]))
return false;else if(type=="text"&&id.indexOf("%")>-1&&!this.checkDecimal(value,elements[i]))
return false;}
if(strEmptyFields.length>0)
{if(focuselement!=null)
{focuselement.focus();if(focuselement.type=="text")
focuselement.select();}
var stralert="The "+strEmptyFields.length+" required field(s) are empty : \n"+"----------------------------\n\n"+strEmptyFields.join('\n')+"\n----------------------------\n\n"+"Please enter the required data.\n\n";alert(stralert);return false;}
return true;},getValues:function(theform)
{var elements=theform.elements;var ob=new Object();for(var i=0;i<elements.length;i++)
{var type=elements[i].type;var name=elements[i].name;var id=elements[i].id;if(type!="button"&&type!="submit"&&type!="reset"&&type!="image"&&type!="checkbox"&&name!='')
{if(id.indexOf('_FCK')>-1)
{var name2=id.substring(0,id.indexOf('_FCK'));var editor=FCKeditorAPI.GetInstance(id);ob[name2]=editor.GetXHTML(true);}
else
{ob[name]=elements[i].value;}}
else if(type=="checkbox"&&name!='')
{ob[name]=elements[i].checked;}}
return ob;},setValues:function(theform,ob)
{var elements=theform.elements;for(var i=0;i<elements.length;i++)
{var type=elements[i].type;var name=elements[i].name;var id=elements[i].id;if(type!="button"&&type!="submit"&&type!="reset"&&type!="image"&&type!="checkbox"&&ob[name])
{if(id.indexOf('_FCK')>-1)
{var name2=id.substring(0,id.indexOf('_FCK'));var editor=FCKeditorAPI.GetInstance(id);editor.SetHTML(ob[name2],true);}
else
{elements[i].value=ob[name];}}
else if(type=="checkbox")
{elements[i].checked=ob[name];}}},checkValidEmailFormat:function(email)
{if(email&&email.match(this.emailstr)!=null)
return true;return false;},checkIllegalEmailCharacter:function(email)
{if(email&&email.match(this.illegalemailchar)!=null)
return true;return false;},checkEmail:function(email,textbox)
{if(email!=''&&email!=null)
{if(MyForm.checkIllegalEmailCharacter(email))
{textbox.focus();textbox.select();window.alert("The email contains invalid character(s).");return false;}
if(!MyForm.checkValidEmailFormat(email))
{textbox.focus();textbox.select();window.alert("The email input is invalid.");return false;}}
return true;},checkNumber:function(value,input,expression)
{if(value!=''&&value!=null)
{if(value.match(expression)==null)
{input.focus();input.select();var alt=input.getAttribute('alt');if(alt!=null&&alt!='')
window.alert("Please enter the "+alt+" in correct format.");else
window.alert("Please enter the number in correct format.");return false;}}
return true;},checkInteger:function(value,input)
{return this.checkNumber(value,input,this.integer);},checkDecimal:function(value,input)
{return this.checkNumber(value,input,this.decimal);},checkUsername:function(value,input)
{if(value.match(this.usernamestr)==null)
{input.focus();input.select();var alt=input.getAttribute('alt');if(alt!=null&&alt!='')
window.alert("Please enter the "+alt+" in correct format.");else
window.alert("Please enter the username in correct format.");return false;}
return true;}};var MyTable={createRow:function(table,rowIndex,id,className)
{var row=table.insertRow(rowIndex);row.id=id;row.className=className;return row;},createRowAt:function(tableid,rowIndex,id,className)
{var table=$(tableid);return this.createRow(table,rowIndex,id,className);},createRowBefore:function(tableid,locationid,id,className)
{var rowIndex=$(locationid).rowIndex;return this.createRow($(tableid),rowIndex,id,className);},createRowAfter:function(tableid,locationid,id,className)
{var rowIndex=$(locationid).rowIndex;return this.createRow($(tableid),rowIndex+1,id,className);},createCellById:function(rowid,className)
{var row=$(rowid);return this.createCell(row,className);},createCell:function(row,className)
{return this.createCellByIndex(row,0,className);},createCellByIndex:function(row,index,className)
{var col=row.insertCell(index);col.className=className;return col;},createCells:function(row,numOfCell,className)
{var cols=new Array(numOfCell);for(var i=0;i<numOfCell;i++)
{cols[i]=this.createCellByIndex(row,i,className);}
return cols;},deleteRow:function(tableid,rowid)
{var table=$(tableid);var row=$(rowid);if(table!=null&&row!=null)
table.deleteRow(row.rowIndex);}};var SpanForm={create:function(id,fields,form)
{for(var i=0;i<fields.length;i++)
{var name=fields[i];var span=$(name+'_'+id);var input=form.elements[name];span.innerHTML=this.getHTMLCode(input);}},restore:function(id,fields,ob)
{for(var i=0;i<fields.length;i++)
{var name=fields[i];var span=$(name+'_'+id);span.innerHTML=ob[name];}},restoreUsingProperties:function(id,fields,ob,properties)
{for(var i=0;i<fields.length;i++)
{var name=fields[i];var property=properties[i];var span=$(name+'_'+id);if(property.indexOf('.')>=0)
eval(('span.innerHTML = ob.'+property));else
span.innerHTML=ob[property];}},emptyTags:{"IMG":true,"BR":true,"INPUT":true,"META":true,"LINK":true,"PARAM":true,"HR":true},getHTMLCode:function(elem){if(document.all||elem.outerHTML)
{return elem.outerHTML;}
else
{var attrs=elem.attributes;var str="<"+elem.tagName;for(var i=0;i<attrs.length;i++)
str+=" "+attrs[i].name+"=\""+attrs[i].value+"\"";if(this.emptyTags[elem.tagName])
return str+"/>";return str+">"+elem.innerHTML+"</"+elem.tagName+">";}
return"";}};
