//function tp_template(form, msg, list, listType, next, prev, arrValidationMarkers, arrRequired) {
function tp_template(form, msg, list, arrValidationMarkers, arrRequired) {
	this.form = $(form);
	this.msg = $(msg);
	this.validationListID = list;
	this.validationList = $(list);
//	this.listType = listType;
//	this.nextPage=next;
//	this.prevPage=prev;
	this.currentTarget="";
	this.currentButtonID="";
	this.currentButtonDisabledCSSClass="";
	this.currentButtonEnabledCSSClass="";
	this.Required = new Array();
	this.validationMarkers = new Array();
	if (tp_template.arguments[3]){this.validationMarkers=arrValidationMarkers;} 
	if (tp_template.arguments[4]){this.Required=arrRequired;} 
}

tp_template.prototype.clearDate = function(id) {
	try{var month = $(id+'_month');month.selectedIndex=0;}catch(e){}
	try{var day = $(id+'_day');day.selectedIndex=0;}catch(e){}
	try{var year = $(id+'_year');year.selectedIndex=0;}catch(e){}	
	}
	
tp_template.prototype.Respond = function(listHTML,aValidations)
{ 
 
var redir=true;
if (tp_template.Respond.arguments[3]){if(tp_template.Respond.arguments[3]=="1"){redir=false;}}
if (tp_template.Respond.arguments[2]) {
	if(tp_template.Respond.arguments[2]!="empty"){this.msg.innerHTML = tp_template.Respond.arguments[2];this.msg.style.display="block";}
	if (redir==true && this.currentTarget.length > 0){
		if(this.currentTarget!="remoteparent"){location.href=this.currentTarget;}
		else{parent.tp_remoteMgr.closeAndSwitch(tp_template.Respond.arguments[4]);}
		}
	}
else {	
	this.validationList.innerHTML=listHTML;	
	this.validationList.style.display="block";	


 	this.clearValidationMarkers();
//	var valMarkers = $(this.validationMarkers.join(","));
//	Element.show("'"+arrValidations.join("','")+"'");
		for(i=0; i<aValidations.length; i++)
		{
			if ($(aValidations[i]))
				{$(aValidations[i]).style.display="inline";}
		}
	}	
if(tp_template.Respond.arguments[2]!="empty"){self.scrollTo(0, 0);}
}
tp_template.prototype.clearValidationMarkers = function()
{
//		Element.hide("'"+this.validationMarkers.join("','")+"'");
		for(i=0; i<this.validationMarkers.length; i++)
		{
			if ($(this.validationMarkers[i]))
				{$(this.validationMarkers[i]).style.display="none";}
		}
}

tp_template.prototype.Save = function(t,b) {
	
	this.msg.style.display="none";
	this.clearValidationMarkers();
	if (tp_template.Save.arguments[0]){this.currentTarget=tp_template.Save.arguments[0];}
	if (tp_template.Save.arguments[1]){
		this.currentButtonID=tp_template.Save.arguments[1];
		if (tp_template.Save.arguments[2]){ 
			this.currentButtonEnabledCSSClass=tp_template.Save.arguments[2]; 
			}else{this.currentButtonEnabledCSSClass="";} 
		if (tp_template.Save.arguments[3]){
			this.currentButtonDisabledCSSClass=tp_template.Save.arguments[3];	
			}else{this.currentButtonDisabledCSSClass=""; }
		
		try	{
			var bt=$(this.currentButtonID)
			bt.disabled=true;
			if (this.currentButtonDisabledCSSClass!=""){try	{bt.className=this.currentButtonDisabledCSSClass;}catch(e){}}
			}
		catch(e){}
		}else{this.currentButtonID="";} 	
	this.validationList.style.display="none";	
	var url = "/community/app/reg/tptwiz/callback/step.aspx";
	var u="";
	try {var u=tp_uid} catch(e){}
	var args = "u="+u+"&tp_isrequired="+this.Required.join("|")+this.getFormElements();	
	
	PostURL(url,args,0,"tp_template.ParseResponse")
}

tp_template.prototype.UpdatePwd = function(){
  		var e=$("tp_n_LoginEmail");
  		if (!e){e=$("tp_n_Email")}
 		if (!e){alert("Sorry, this function will not work without an email address field.");}
 		else{
 			if(e.value==""){alert("Please enter your email address.");}
 			else{
 			var args="rs=1&em="+e.value;
 	 			PostURL("/reader/app/callback/login.aspx",args,0,"tp_template.ParseResponseString")
 			}
 		}
  		}
  		
//tp_template.prototype.setRegionElement = function(c){
//	if (tp_template.setRegionElement.arguments[1])
//		{ 
//		var myAjax = new Ajax.Request("/community/app/reg/tptwiz/callback/regionitems.aspx?tp_element="+tp_template.setRegionElement.arguments[1]+"&tp_div="+tp_template.setRegionElement.arguments[2]+"&tp_cc="+c),{method: 'get', parameters: "", onComplete: this.LoadRegions2.bind(this)});
//		}
//  	}   		
tp_template.prototype.onCountryChange = function(cc){
	if (tp_template.onCountryChange.arguments[1])
		{ 
		GetURL("/community/app/reg/tptwiz/callback/regionitems.aspx?tp_cc="+cc,0,"tp_template.LoadRegions","'"+tp_template.onCountryChange.arguments[1]+"','"+tp_template.onCountryChange.arguments[2]+"'")
		}
  		} 
//tp_template.prototype.LoadRegions2 = function(r){
//try{
//	var tp_ret = r.evalJSON();
//	alert(tp_ret.regions);
//	alert(tp_ret.element);
//	alert(tp_ret.div);
//	
////	if (!tp_html.html){throw("no HTML");}
//}
  		
tp_template.prototype.LoadRegions = function(stream,el,d){
try{
	var r=unescape(stream);
	var rdd=$(el);
	if (tp_template.LoadRegions.arguments[2]!=""){var od=$(d);}
	if (r=="none"){rdd.length = 1;rdd[0].text="    ---------    ";try{od.style.display="none";}catch(e){}}
	else{rdd.length = 0;
	var regions = r.split("|");
	
	rdd.length=regions.length;
    for (i=0; i<regions.length; i++)
    {
	  var c=regions[i].split("%");
	  rdd[i].value = c[0];
      rdd[i].text = c[1];
     
    }
    try{od.style.display="inline";}catch(e){}
    if (rdd[0].value=="-2"){try{od.style.display="none";}catch(e){}}
    }
    }
    catch(e){}
}   
 		 		
tp_template.prototype.ParseResponseString = function(stream){
	try {
	 this.Respond('','',unescape(stream),'1'); }
	catch (e){}	
}		
tp_template.prototype.ParseResponse = function(stream){
	try { 
		
		if (this.currentButtonID!=""){
		try	{
			var bt=$(this.currentButtonID);
			bt.disabled=false;
	
			if (this.currentButtonEnabledCSSClass!=""){try{bt.className=this.currentButtonEnabledCSSClass;}catch(e){}}
			}        
		catch(e){}
		}
	str= new String(unescape(stream));
	
	str.evalScripts();
	// Parse Scripts if failing under Safari...
	//parseScript(x); 
	}
	catch (e){/*alert('evalScripts / parseScript error?');*/}	
}

tp_template.prototype.getFormElements = function(){ 
	var s = "";
	for(i=0; i<this.form.elements.length; i++)
	{
	if (this.form.elements[i].type=="radio")
		{if (this.form.elements[i].checked==true)
			{s = s+"&"+this.form.elements[i].id+"="+this.form.elements[i].value;}// alert(this.form.elements[i].id+'='+this.form.elements[i].value+'\n');}
		}
	if (this.form.elements[i].type=="checkbox")
		{if (this.form.elements[i].value != "")
			{ if (this.form.elements[i].checked==true)
				{s = s+"&"+this.form.elements[i].id+"=on";}
			  else
			  	{s = s+"&"+this.form.elements[i].id+"=off";}
			}
		 else {
				if (this.form.elements[i].checked==true)
					{s = s+"&"+this.form.elements[i].id+"=on";}
				else {s = s+"&"+this.form.elements[i].id+"=off";}	
			  }
		}		
	if (this.form.elements[i].type!="radio" && this.form.elements[i].type!="checkbox")
		{s = s+"&"+this.form.elements[i].id+"="+encodeURIComponent(this.form.elements[i].value);}	
	}
	return s;
}

tp_template.prototype.onTextBlur = function (ctrl)
{
    var regex=/<\/[c-g\d]+>|<\/[i-o\d]+>|<\/[a\d]+>|<\/[q-z\d]+>|<[cg]+[^>]*>|<[i-o]+[^>]*>|<[q-z]+[^>]*>|<[a]+[^>]*>|<\/[C-G\d]+>|<\/[I-O\d]+>|<\/[A\d]+>|<\/[Q-Z\d]+>|<[CG]+[^>]*>|<[I-O]+[^>]*>|<[Q-Z]+[^>]*>|<[A]+[^>]*>|<[Pp]>|<[b|B][R|r]>|<[Div|div|DIV]+[^>]*>$/
	if(regex.test(ctrl.value))
	{
		alert('HTML is not allowed. Please correct the text.');
		ctrl.focus();
	}
}