var win = null;
var goto_file = 'list-psychic.php';
var partner_='';
function checkBeforCon(psychicid,go){	
      return callcheckBeforCon(psychicid,go,'');
}
function checkBeforCon(psychicid,go,partner){
	  partner = typeof(partner) != "undefined" ?partner:'';
      return callcheckBeforCon(psychicid,go,partner);
}
function callcheckBeforCon(psychicid,go,partner){
	
                LeftPosition = (screen.width) ? (screen.width-770)/2 : 0;
                TopPosition = (screen.height) ? (screen.height-570)/2 : 0;
                win = window.open('', 'userConference','top='+TopPosition+',left='+LeftPosition+'location=no,nenuber=no,toorlbar=no,scrollbars=no, status=no,resizable=no,width=770,height=570');
                goto_file = go;
                partner_= partner;
		var script = document.createElement('script');
		    script.src = "./checkUserBeforeCon.php?psychicid="+psychicid+"&partner="+partner;
			//alert(script.src);
			if(script.addEventListener){
				if(partner=='')script.addEventListener("load", callback, false);
				else script.addEventListener("load", callback_forpartner, false);
			}else if(script.attachEvent){
				if(partner==''){
					script.attachEvent("onreadystatechange", function() { callbackIE(); });			
				}else{
					script.attachEvent("onreadystatechange", function() { callbackIE_forpartner(); });
				}
			}
			document.getElementsByTagName('head')[0].appendChild(script);
			return true;
}

callback = function() {
			var result = typeof(result_check) != "undefined" ? result_check : "เกิดความผิดผลาดขณะระบบประมวลผล กรุณาลองใหม่อีกครั้ง123";				
			if(result == 'NOTLOGIN'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			      window.location='/login-form.php?goto='+goto_file;
			}
                        else if(result == 'NOQUOTA'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			      window.location='/package-promotion.php';
			}
                        else if(result == 'QUOTANOTENOUGH'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'QUOTANOTENOUGH2'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			      //window.location='/package-promotion.php';
			}
                        else if(result == 'NOHAVEPSYCHIC'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'PSYCHICOFF'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'PSYCHICON'){
                              win.location.replace('/userConference.php?partner='+partner_);
                        }
                        else if(result == 'PSYCHICBUSY'){
                              win.location.replace('/confirm-conference.php?partner='+partner_);
			}
                        else{
                              win.location.replace('/alert-message.php');
			}                        
};

callbackIE = function() {
			var target = window.event.srcElement;
			if(target.readyState == "loaded")
			callback.call(target);
};


callback_forpartner = function() {	
			
			var result = typeof(result_check) != "undefined" ? result_check : "เกิดความผิดผลาดขณะระบบประมวลผล กรุณาลองใหม่อีกครั้ง456";			
			if(result == 'NOTLOGIN'){
			      win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'NOQUOTA'){
			      win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'QUOTANOTENOUGH'){
                              win.location.replace('/alert-message.php?msg_code='+result);
                        }
                        else if(result == 'QUOTANOTENOUGH2'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'NOHAVEPSYCHIC'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'PSYCHICOFF'){
                              win.location.replace('/alert-message.php?msg_code='+result);
			}
                        else if(result == 'PSYCHICON'){
                              win.location.replace('/userConference.php?partner='+partner_);
                        }
                        else if(result == 'PSYCHICBUSY'){
                              win.location.replace('/confirm-conference.php?partner='+partner_);
			}
                        else{							
                              win.location.replace('/alert-message.php');
			}                        
};

callbackIE_forpartner = function() {
			var target = window.event.srcElement;
			if(target.readyState == "loaded")
			callback.call(target);
};
