function loadXMLString(txt) {
	try{ //Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(txt);
		return(xmlDoc);  
	}catch(e){
		try {//Firefox, Mozilla, Opera, etc.
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(txt,"text/xml");
			return(xmlDoc);
		}catch(e) {alert(e.message)}
	}
	return(null);
}


$(document).ready(function(){
	$("input.inputHoverJS").focus(function(e){ $(e.target).addClass("inputHover");		});
	$("input.inputHoverJS").blur(function(e){	$(e.target).removeClass("inputHover");		});
	$("#btnShortLoginSubmit").click(function(event){
		event.preventDefault(); 
		queryString = '';
		redirect_url='';
		if(document.frmShortLogin.rem2.checked){
			with(document.frmShortLogin){
				queryString = "&rem2="+rem2.value+"&nickname="+nickname.value+"&password="+password.value+"&login_process_action=do_login";
				redirect_url=action_pending_after_login.value;
			}
		} else {
			with(document.frmShortLogin){
				queryString = "&nickname="+nickname.value+"&password="+password.value+"&login_process_action=do_login";
				//queryString = "&nickname="+nickname.value+"&password="+password.value+"&login_process_action=do_login&expertid="+expertid.value+"&mainForm="+mainForm.value;
				redirect_url=action_pending_after_login.value;
			}
		}
		
		if(redirect_url==''){redirect_url=SITE_URL+'index.php?action=user&task=myaccount'; }
		$.ajax({	method: "get",
					url: AJAX_SITE_REQUEST_USERS_URL+"login_short.php",
					data: queryString ,
					beforeSend: function(){$("#short_login_processing").show("fast");}, //show loading just when link is clicked
					complete: function(){ $("#short_login_processing").hide("fast");}, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
					//alert(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_login = x[i].childNodes[0].nodeValue; break;
								case 'userid' :			userid = x[i].childNodes[0].nodeValue; break;
								case 'expert' :			expertId = x[i].childNodes[0].nodeValue; break;
								case 'pollId' :			pollId = x[i].childNodes[0].nodeValue; break;
								
								case 'mainForm' :		mainForm = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
								//case 'oid' :			oid = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
//								case 'cid' :			cid = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
//								case 'bid' :			bid = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
//								case 'changei' :		changei = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
								
								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_login=='yes'){	
							$("#short_login_processing").show("slow");
							if(self.parent.document.getElementById("headerWelcomeColumn")){
								eleRef = self.parent.document.getElementById("headerWelcomeColumn")
								eleRef.innerHTML = headerInfo;
							};
							
							//alert(redirect_url);
							if(userid==expertId){  // If UserId and ExpertId are Same
							 fillHtml = self.parent.document.getElementById("askQuestion");
							 fillHtml.innerHTMl =" ";
							 alert("You have not Permission.");
							  self.parent.location.href=redirect_url;
							} else {
								//slogin+= '<a href="#" onclick="">' + Sucessfully Login + '</a>';
								//alert("Succesfully Login");
								//self.parent.location.href=redirect_url;
								self.parent.box_remove();
								jsfunc = document.frmShortLogin.pending_jsfunc.value
								frmref = document.frmShortLogin.jsfunc_frmname.value
								//alert("Jsfunc params is --> \n\t"+"(self.parent.document." + frmref+ ") "+"\n")
									if(jsfunc!=''){ //frmRef = self.parent.document.forms[frmref];
										//alert(eval(" self.parent.document."+frmref));return false;
										KK=eval( "self.parent." + jsfunc + "(self.parent.document." + frmref+ ") ");
									}else{ //alert(0);
										self.parent.location.href=redirect_url;
									}
							}
							/*
							processHTML = '<form name="frmLogin" method="post" id="frmLoginAfterRegistration" action="index.php">'+
										'<input type="text" name="action" value="user" />'+
										'<input type="text" name="task" value="login_process" />'+
										'<input type="text" name="login_process_action" value="do_login" />'+
										'<input type="text" class="input" size="30" name="nickname" value="'+document.frmShortRegistration.nickname.value+'" />'+
										'<input type="text" class="input" size="30" name="password" value="'+document.frmShortRegistration.password.value+'" />'+
									'</form>';
							$("#short_registration_result").html("registration done. Processing Login." +processHTML); //show the html inside .content div
							document.getElementById("frmLoginAfterRegistration").submit();
							*/
						}else{
							while(errors.indexOf("~")>=0){		errors = errors.replace(/~/,"<br />");	}
							if(document.frmShortLogin.login_short_ajax_processing){
								// alert(12345);
								errors = errors.replace('class="thickbox"','');
							}
							//alert(errors);
							$("#short_login_result").slideUp();
							$("#short_login_result").html(errors); //show the html inside .content div
							$("#short_login_result").slideDown(); //animation
							tb_init('a.thickbox');
						}
					}
		});
	});
	
});

function new_button_click(event){
			if(event.keyCode==13){
//		event.preventDefault(); 
		queryString = '';
		redirect_url='';
		if(document.frmShortLogin.rem2.checked){
			with(document.frmShortLogin){
				queryString = "&rem2="+rem2.value+"&nickname="+nickname.value+"&password="+password.value+"&login_process_action=do_login";
				redirect_url=action_pending_after_login.value;
			}
		} else {
			with(document.frmShortLogin){
				queryString = "&nickname="+nickname.value+"&password="+password.value+"&login_process_action=do_login";
				//queryString = "&nickname="+nickname.value+"&password="+password.value+"&login_process_action=do_login&expertid="+expertid.value+"&mainForm="+mainForm.value;
				redirect_url=action_pending_after_login.value;
			}
		}
		
		if(redirect_url==''){redirect_url=SITE_URL+'index.php?action=user&task=myaccount'; }
		$.ajax({	method: "get",
					url: AJAX_SITE_REQUEST_USERS_URL+"login_short.php",
					data: queryString ,
					beforeSend: function(){$("#short_login_processing").show("fast");}, //show loading just when link is clicked
					complete: function(){ $("#short_login_processing").hide("fast");}, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
					//alert(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_login = x[i].childNodes[0].nodeValue; break;
								case 'userid' :			userid = x[i].childNodes[0].nodeValue; break;
								case 'expert' :			expertId = x[i].childNodes[0].nodeValue; break;
								case 'pollId' :			pollId = x[i].childNodes[0].nodeValue; break;
								
								case 'mainForm' :		mainForm = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
								//case 'oid' :			oid = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
//								case 'cid' :			cid = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
//								case 'bid' :			bid = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
//								case 'changei' :		changei = x[i].childNodes[0].nodeValue; break;//For Offers Checkbox
								
								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_login=='yes'){	
							$("#short_login_processing").show("slow");
							if(self.parent.document.getElementById("headerWelcomeColumn")){
								eleRef = self.parent.document.getElementById("headerWelcomeColumn")
								eleRef.innerHTML = headerInfo;
							};
							
							//alert(redirect_url);
							if(userid==expertId){  // If UserId and ExpertId are Same
							 fillHtml = self.parent.document.getElementById("askQuestion");
							 fillHtml.innerHTMl =" ";
							 alert("You have not Permission.");
							  self.parent.location.href=redirect_url;
							} else {
							//slogin+= '<a href="#" onclick="">' + Sucessfully Login + '</a>';
							//alert("Succesfully Login");
							//self.parent.location.href=redirect_url;
							self.parent.box_remove();
							jsfunc = document.frmShortLogin.pending_jsfunc.value
							frmref = document.frmShortLogin.jsfunc_frmname.value
							//alert("Jsfunc params is --> \n\t"+"(self.parent.document." + frmref+ ") "+"\n")
								if(jsfunc!=''){ //frmRef = self.parent.document.forms[frmref];
						//alert(eval(" self.parent.document."+frmref));return false;
								KK=eval( "self.parent." + jsfunc + "(self.parent.document." + frmref+ ") ");
							}else{ //alert(0);
								self.parent.location.href=redirect_url;
							}
							
							}
							/*
							processHTML = '<form name="frmLogin" method="post" id="frmLoginAfterRegistration" action="index.php">'+
										'<input type="text" name="action" value="user" />'+
										'<input type="text" name="task" value="login_process" />'+
										'<input type="text" name="login_process_action" value="do_login" />'+
										'<input type="text" class="input" size="30" name="nickname" value="'+document.frmShortRegistration.nickname.value+'" />'+
										'<input type="text" class="input" size="30" name="password" value="'+document.frmShortRegistration.password.value+'" />'+
									'</form>';
							$("#short_registration_result").html("registration done. Processing Login." +processHTML); //show the html inside .content div
							document.getElementById("frmLoginAfterRegistration").submit();
							*/
						}else{
							while(errors.indexOf("~")>=0){		errors = errors.replace(/~/,"<br />");	}
							//alert(errors);
							$("#short_login_result").slideUp();
							$("#short_login_result").html(errors); //show the html inside .content div
							$("#short_login_result").slideDown(); //animation
							tb_init('a.thickbox');
						}
					}
		});
	
		}
}