function loadXMLString(txt) {
	try{ //Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(txt);
		return(xmlDoc);  
	}catch(e){
		try {
			parser=new DOMParser();			xmlDoc=parser.parseFromString(txt,"text/xml");			return(xmlDoc);
		}catch(e) {alert(e.message)}
	}
	return(null);
}

$(document).ready(function(){
	$("#btnShortRegistrationSubmit").click(function(event){
		event.preventDefault(); 
		queryString = '';
	    redirect_url='';
		with(document.frmShortRegistration){
			postData = {email: email.value, nickname: nickname.value, password:	password.value,  regCode: regCode.value, sort_flag: "Y",registration_action:"short"}
			redirect_url=document.frmShortRegistration.action_pending_after_register.value;
		}
		if(redirect_url==''){redirect_url=SITE_URL+'index.php?action=user&task=complete_profile&first_time_flag=1'; }
		$.ajax({	method: "post",
					url: AJAX_SITE_REQUEST_USERS_URL+"register_short.php",
					data: postData,//queryString ,
					beforeSend: function(){$("#short_registration_processing").show("fast");}, //show loading just when link is clicked
					complete: function(){ $("#short_registration_processing").hide("fast");}, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
						xmlDoc=loadXMLString(html);
						x=xmlDoc.documentElement.childNodes;
						can_register = 'no'; errors =''; total_errors=0; headerInfo='';
						for (i=0;i<x.length;i++){
							switch(x[i].nodeName){
								case 'state' :			can_register = x[i].childNodes[0].nodeValue; break;
								case 'errors' :			errors = x[i].childNodes[0].nodeValue; break;
								case 'errors_count' : 	total_errors = x[i].childNodes[0].nodeValue;break;
								case 'headerInfo'	: 	headerInfo = x[i].childNodes[0].nodeValue;break;
							}
						}  
						if(can_register=='yes'){
							$("#short_registration_processing").show("slow");
							if(self.parent.document.getElementById("headerWelcomeColumn")){
								eleRef = self.parent.document.getElementById("headerWelcomeColumn")
								eleRef.innerHTML = headerInfo;
							};
							//self.parent.location.href=redirect_url;
							self.parent.box_remove();
							jsfunc = document.frmShortRegistration.pending_jsfunc.value
							frmref = document.frmShortRegistration.jsfunc_frmname.value
								if(jsfunc!=''){ 
								eval( "self.parent." + jsfunc + "(self.parent.document." + frmref+ ") ");
							}else{	
								self.parent.location.href=SITE_URL+'index.php?action=user&task=complete_profile&first_time_flag=1';
							}
						}else{
							while(errors.indexOf("~")>=0){		errors = errors.replace(/~/,"<br />");	}
							$("#short_registration_result").slideUp();
							$("#short_registration_result").html(errors); //show the html inside .content div
							$("#short_registration_result").slideDown(); //animation
						}
					}
			   });
		});
						
});


/// register short key press function

function register_keypress(event){
	if(event.keyCode==13){
		queryString = '';
	    redirect_url='';
		with(document.frmShortRegistration){
			postData = {email: email.value, nickname: nickname.value, password:	password.value, regCode: regCode.value, sort_flag: "Y",registration_action:"short"}
			redirect_url=document.frmShortRegistration.action_pending_after_register.value;
		}

		if(redirect_url==''){redirect_url=SITE_URL+'index.php?action=user&task=complete_profile&first_time_flag=1'; }
		$.ajax({	method: "post",
					url: AJAX_SITE_REQUEST_USERS_URL+"register_short.php",
					data: postData,//queryString ,
					beforeSend: function(){$("#short_registration_processing").show("fast");}, //show loading just when link is clicked
					complete: function(){ $("#short_registration_processing").hide("fast");}, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
						xmlDoc=loadXMLString(html);
						x=xmlDoc.documentElement.childNodes;
						can_register = 'no'; errors =''; total_errors=0; headerInfo='';
						for (i=0;i<x.length;i++){
							switch(x[i].nodeName){
								case 'state' :			can_register = x[i].childNodes[0].nodeValue; break;
								case 'errors' :			errors = x[i].childNodes[0].nodeValue; break;
								case 'errors_count' : 	total_errors = x[i].childNodes[0].nodeValue;break;
								case 'headerInfo'	: 	headerInfo = x[i].childNodes[0].nodeValue;break;
							}
						}
						if(can_register=='yes'){
							$("#short_registration_processing").show("slow");
							if(self.parent.document.getElementById("headerWelcomeColumn")){
								eleRef = self.parent.document.getElementById("headerWelcomeColumn")
								eleRef.innerHTML = headerInfo;
							};
							//self.parent.location.href=redirect_url;
							self.parent.box_remove();
							jsfunc = document.frmShortRegistration.pending_jsfunc.value
							frmref = document.frmShortRegistration.jsfunc_frmname.value
								if(jsfunc!=''){ 
								//alert(eval(" self.parent.document."+frmref));return false;
								eval( "self.parent." + jsfunc + "(self.parent.document." + frmref+ ") ");
							}else{	
								self.parent.location.href=SITE_URL+'index.php?action=user&task=complete_profile&first_time_flag=1';
							}
						}else{
							while(errors.indexOf("~")>=0){		errors = errors.replace(/~/,"<br />");	}
							$("#short_registration_result").slideUp();
							$("#short_registration_result").html(errors); //show the html inside .content div
							$("#short_registration_result").slideDown(); //animation
						}
					}
			   });
	}
		
}//function end