function cTemplate()
{this.templates=[];this.templatesClean=[];this.loadTemplate=function(markup)
{markup=markup.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");var templates=markup.split("</ctemp>");for(var key in templates)
{var template=templates[key].replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");if(template)
{var firstGreaterThan=template.indexOf(">");var startTag=template.substring(0,firstGreaterThan);var templateMarkup=template.substr(firstGreaterThan+1);var templateName=startTag.split(":")[1];this.templates[templateName]=templateMarkup;this.templatesClean[templateName]=templateMarkup;}}}
this.addVariable=function(templateName,variable,value)
{if(variable.constructor.toString().indexOf("Array")!=-1)
{if(variable.length!=value.length)
{alert("Input array sizes do not match: "+templateName);}
else
{var templateMarkup=this.templates[templateName];if(templateMarkup==undefined)
{alert(templateName+" is empty or doesn't exist.");return undefined;}
for(var key in variable)
{templateMarkup=templateMarkup.replace(new RegExp("<cvar:"+variable[key]+" />","g"),value[key]);templateMarkup=templateMarkup.replace(new RegExp("@var:"+variable[key]+"@","g"),value[key]);}
this.templates[templateName]=templateMarkup;}}
else
{var templateMarkup=this.templates[templateName];if(templateMarkup==undefined)
{alert(templateName+" is empty or doesn't exist.");return undefined;}
templateMarkup=templateMarkup.replace(new RegExp("<cvar:"+variable+" />","g"),value);templateMarkup=templateMarkup.replace(new RegExp("@var:"+variable+"@","g"),value);this.templates[templateName]=templateMarkup;}}
this.addVariableToAll=function(variable,value)
{alert('method not defined yet');}
this.getHTML=function(templateName,preserveEmptyVars)
{var templateMarkup=this.templates[templateName];if(templateMarkup==undefined)
{alert(templateName+" is empty or doesn't exist.");return undefined;}
if(preserveEmptyVars!=true)
{templateMarkup=templateMarkup.replace(/<cvar:.*\/>/,"");templateMarkup=templateMarkup.replace(/@var:.*@/,"");templateMarkup=templateMarkup.replace(/<coption:.*?>/g,"");templateMarkup=templateMarkup.replace(/<\/coption:.*?>/g,"");}
return templateMarkup;}
this.resetHTML=function(templateName)
{this.templates[templateName]=this.templatesClean[templateName];}
this.repeater=function(templateName,values,hideOptions)
{var htmlBuffer="";if(values.constructor.toString().indexOf("Array")==-1)
{alert("Call to repeater on template "+templateName+" failed - values must BE AN ARRAY.");return"";}
for(var key in values)
{if(values[key].constructor.toString().indexOf("Array")==-1)
{alert("Call to repeater on template "+templateName+" failed - values must CONTAIN ARRAYS.");}
else
{for(var varName in values[key])
{var varValue=values[key][varName];if(varName=='hideoption')
{this.hideOption(templateName,varValue);}
else
{this.addVariable(templateName,varName,varValue);}}
if(hideOptions&&hideOptions.constructor.toString().indexOf("Array")!=-1)
{for(var option in hideOptions)
{this.hideOption(templateName,hideOptions[option]);}}
htmlBuffer+=this.getHTML(templateName);this.resetHTML(templateName);}}
return htmlBuffer;}
this.hideOption=function(templateName,optionName)
{templateMarkup=this.templates[templateName];if(templateMarkup==undefined)
{alert(templateName+" is empty or doesn't exist.");return undefined;}
templateMarkup=templateMarkup.replace(new RegExp("<coption:"+optionName+">[\\s\\S]*<\/coption:"+optionName+">","g"),"");this.templates[templateName]=templateMarkup;}}