function signinOrSignup(){
	var dv = '<div id="dv_signinorsignup" style="width:100%;height:50px;border:1px solid #CCC">';
	dv += '<div style="padding: 15px;"><a id="login" onclick="dvLogin();" class="blue" href="#">Sign In</a>&nbsp;';
	dv += 'or&nbsp;<a id="SignUp" onclick=onClickEvents(this.id); class="blue" href="#">Sign Up</a>&nbsp;now!&nbsp;&nbsp;';
	dv += '</div></div>';
	return dv;
}

function loginBox(){
	var dv = '<div id="div_loginbx" style="margin: 0px;" class="loginContent" ><div style="margin: 6px;height: 105px;" class="filebg">';
		dv += '<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td style="height: 14px;" colspan="2"><div align="center" id="lbl_loginerrmsg"';
		dv += ' style="color: rgb(204, 0, 0);"></div></td><td></td></tr><tr><td style="padding-bottom:6px;">اسم العضو&nbsp;:&nbsp;</td>';
		dv += '<td><input type="text" tabindex="1" id="user_name" class="logintxtfld" name="user_name"></td></tr><tr><td>كلمة السر&nbsp;:&nbsp;</td>';
	dv += '<td><input tabindex="2" type="password" id="login_password" class="logintxtfld" name="login_password"></td></tr><tr><td></td><td style="padding-top:3px;">';
		dv += '<input type="hidden" id="login_md5password" name="login_md5password"><input type="hidden" id="login_md5password_utf" name="login_md5password_utf">';
		dv += '<input type="hidden" id="securitytoken" name="securitytoken"><input type="hidden" id="s" name="s"><input type="button" value="قدم"';
	dv += ' id="login" class="btn" tabindex="3" onclick="JAVASCRIPT:loginJS();" name="login">&nbsp;<input type="button" value="Cancel" id="logincancel"';
		dv += ' class="btn" tabindex="4" onclick="onClickEvents(this.id);" name="logincancel">&nbsp;&nbsp;<br/><div style="margin-top:4px;"><a class="blue" tabindex="5" ';
		dv += 'onclick="onClickEvents(this.id)" id="SignUp" style="cursor:pointer;" >Sign Up</a> | <a class="blue" tabindex="6" onclick="onClickEvents(this.id)" id="LostPassword" style="cursor:pointer;" >Lost Password?</a></div></td></tr></tbody></table></div></div>';
		return dv;
}


function dLoginBox(divid,ption){
  if(document.getElementById("userid").value=='0' || document.getElementById("userid").value=='undefined'){
       if(document.getElementById('popiframe')){
           var p = document.getElementById('bdy');p.removeChild(document.getElementById('popiframe'));}
   document.getElementById('PopDiv').innerHTML=loginBox();
   ption = ption.split("_");var ptn = ption[0]+' '+ption[1];
   Popup.show('PopDiv',divid,ptn,{'constrainToScreen':true});
   document.getElementById("user_name").focus();
 }
}


function registUser()
{
	document.getElementById("dv_registering").innerHTML = '<img align="middle" src="images/imgloader.gif">';
	if (document.getElementById("agree_conidition").checked)
	{
		var junk_output;
		md5hash(document.getElementById("register_password"), document.getElementById("register_password_md5"), junk_output, 0);
		md5hash(document.getElementById("register_password_2"), document.getElementById("register_passwordconfirm_md5"), junk_output, 0);
		var FormArray=ConvertFormElementsToArray("frm_reg");


	    mySWF.callSWF("register", ["JS", FormArray]);   
             
  	}
}

function registerDone(text)
{
	YAHOO.util.Dom.get('dv_dialog').style.display = "none";
	YAHOO.util.Dom.get('dv_dialog').innerHTML = "";
	YAHOO.util.Dom.get('dialog_box_mask').style.display = "none";
         dLoginBox("signin_signout","below_right");
         document.getElementById("lbl_loginerrmsg").style.color ="#009900";
	document.getElementById("lbl_loginerrmsg").innerHTML ="Registration Completed! SignIn here";
                   
/*
         document.getElementById("username").value=document.getElementById("register_username").value;
	document.getElementById("login_password").value=document.getElementById("register_password").value;	
	document.getElementById("login_md5password").value=document.getElementById("register_password_md5");

	mySWF.callSWF("login", ["JS", document.getElementById("username").value,document.getElementById("login_password").value,document.getElementById("login_md5password").value,document.getElementById("login_md5password_utf").value, document.getElementById("securitytoken").value, document.getElementById("s").value]);   
*/
}
function logoutJS(securityKey)
{
	document.getElementById("signin_signout").innerHTML ="signing out... ";
    mySWF.callSWF("logout", ["JS",securityKey]); 
	document.getElementById("userid").value ="0";
        loggedUserFun("0");
	if(document.getElementById("div_loginbx"))
         {
         document.getElementById("div_loginbx").style.display='none';
         }
}
	
function loginJS()
{
	if(!document.getElementById("login_password").value || !document.getElementById("user_name").value){
		document.getElementById("lbl_loginerrmsg").innerHTML ="Required values not found!";
	}else{
	document.getElementById("lbl_loginerrmsg").style.color ="#009900";
	document.getElementById("lbl_loginerrmsg").innerHTML ="Signing in... ";
	md5hash(document.getElementById("login_password"), document.getElementById("login_md5password"),document.getElementById("login_md5password_utf"));
	
//alert("username : "+document.getElementById("username").value+" , login_password : "+document.getElementById("login_password").value+" , login_md5password : "+document.getElementById("login_md5password").value+" , login_md5password_utf : "+document.getElementById("login_md5password_utf").value+" , securitytoken : "+ document.getElementById("securitytoken").value+" , ss : "+ document.getElementById("s").value);
	
	mySWF.callSWF("login", ["JS", document.getElementById("user_name").value,document.getElementById("login_password").value,document.getElementById("login_md5password").value,document.getElementById("login_md5password_utf").value, document.getElementById("securitytoken").value, document.getElementById("s").value]);   
	}
}

var manageris='';
function userLoginFailed()
{
    document.getElementById("lbl_loginerrmsg").style.color="#CC0000";
    document.getElementById("lbl_loginerrmsg").innerHTML ="Invalid Username or Password!"; 
}

function userLoggined(user)
{

if (user.userid)
{
    document.getElementById("lbl_loginerrmsg").style.color ="#009900";
    document.getElementById("lbl_loginerrmsg").innerHTML ="Loading data... for " + user.username; 
}
//    loggedUserFun(user);
}


function loggedUserFun(user) {
//alert(1);
	var signin_signout_var;
//alert("USER ID: " + user.userid);
	if (user.userid>0)
	{
manageris=user.manager;
//alert('Manager: '+user.manager);
fillFavoriteList(user.FavoriteaList, "favlist1");
fillFavoriteList(user.FavoriteaList, "favlist2");
//document.getElementById("favlist2").options=document.getElementById("favlist1").options;

var dv_mypage='<a id="mypage" class="yuimenubaritemlabel" href="#!section=user&id='+user.userid+'">رابطي</a>';
document.getElementById("mypageBtn").innerHTML=dv_mypage;

		//alert(user.securityKey+"   user id : "+user.userid);
	signin_signout_var='<a href="#"><b><img src="images/home_icon.gif" width="17" height="17" border="0"> الرئيسية</b></a> | <a id="SignUp" href="http://www.yabdoo.com/board/memeber.php?u='+user.userid+'">'+user.username+'</a>&nbsp;|&nbsp;<a id="log_out" onclick="JAVASCRIPT:logoutJS(' + "'" +user.securityKey +"'"+ ');" class="blue" style="cursor:pointer;">تسجيل خروج</a>';
	if(document.getElementById("div_loginbx"))
		document.getElementById("PopDiv").innerHTML='<div id="div_loginbx" style="width: 180px;background-color:#FFF;border:1px solid #CCC;"><div align="center" style="margin:6px;height:20px;padding:1px 3px;font-size:11px;font-weight:bold;border:1px solid #CCC;background-color:#f1f8ff;color:#006600;"> Login Success </div></div>';timedMsg('PopDiv');
	}else{
	signin_signout_var='<a onClick="navigateToHome()" ><b><img src="images/home_icon.gif" width="17" height="17" border="0"> الرئيسية</b></a> | <a id="log_in" style="cursor:pointer;" class="blue" onclick=dLoginBox("signin_signout","below_right");>دخول</a>&nbsp;|&nbsp;<a id="SignUp"  onClick="onClickEvents(this.id)" class="blue" style="cursor:pointer;" >Sign Up</a>';
		if(document.getElementById("lbl_loginerrmsg")){
		document.getElementById("lbl_loginerrmsg").style.color="#CC0000";
		document.getElementById("lbl_loginerrmsg").innerHTML="Username or password invalid.";}
	}

document.getElementById("signin_signout").innerHTML =signin_signout_var;
	document.getElementById("userid").value=user.userid;
	//getCustomizeCke();	

//getDvBlockSts();

//alert(2);

}
loggedUserFun({userid: '0', username: 'ضيف'})


function CheckUsername(type, username)
{	//alert(username);
		if(username=="")
		{
		document.getElementById(type+"_loading").innerHTML='<span style="color:#F00" >Please enter a +type+</span>';	
		}
		else
		{
                  document.getElementById(type+'_loading').style.display="block";
		document.getElementById(type+'_loading').innerHTML="Checking...";
                  userExistence(type, username);
		}
}

function CheckPasswordMatch(password)
{	//alert(password);
		if(password!="" && document.getElementById("register_password_2").value!="")
		{
			if(document.getElementById("register_password").value != document.getElementById("register_password_2").value)

                           {
                            document.getElementById("pswd_loading").style.display="block";
			document.getElementById("pswd_loading").innerHTML="<span style='color:#F00' >Password doesn't match</span>";
                           }
			else
			document.getElementById("pswd_loading").style.display="none";
		}
}


function ValidateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   		if(reg.test(email) == false)
	   	document.getElementById("email_loading").innerHTML='<span style="color:#F00" >Invalid Email Address!</span>';
	   	else
	   	document.getElementById("email_loading").style.display="none";
}

function userExistenceAnswer(Answer)
{
	var answerType=Answer.userType;
	
		if(Answer.userExistence=="1")
                  {
                    if(answerType=="username")
                    {
		  document.getElementById("username_loading").innerHTML='<span style="color:#F00" >Username already exists!</span>';
                    }
                    else
                    {
                    document.getElementById("email_loading").style.display="block";
                    document.getElementById("email_loading").innerHTML='<span style="color:#F00" >Email already exists!</span>';
                    }
                  }
		else
                  {
                    if(answerType=="username")
                    {
		  document.getElementById("username_loading").innerHTML='<span style="color:#060" >Username is available!</span>';
                    }
                    else
                    {
                    ValidateEmail(document.getElementById("register_email").value);
                    }
                  }
}

//alert('gallery Default Settings: '1,2');

function changeBG(whichColor){
document.bgColor = whichColor;
}

function CheckEmailMatch()
{
		var userVal=document.getElementById('lostpass_username').value;
		var emailVal=document.getElementById('lostpass_email').value;
		
		if((userVal=="")||(emailVal==""))
		{
		document.getElementById('lostpass_email_loading').style.display="block";	
		document.getElementById("lostpass_email_loading").innerHTML='<span style="color:#F00" >Please fill the fields</span>';	
		}
		else
		{
		document.getElementById('lostpass_email_loading').style.display="block";	
		document.getElementById("lostpass_email_loading").innerHTML="Checking...";
           /* function for checking username, email match */	
                   //mySWF.callSWF("UsernameEmailMatchRequest", ["JS",userVal, emailVal]);
		}
}

 /* function for username, email match result */
function UsernameEmailMatchResult()
{
	var matchresult=1; //manually added
	if(matchresult == 0)
	{
		document.getElementById('lostpass_email_loading').style.display="block";	
		document.getElementById("lostpass_email_loading").innerHTML="<span style='color:#F00' >User Name and Email does'nt match!</span>";
	}
	else
	{
		document.getElementById('lostpass_email_loading').style.display="block";	
		document.getElementById("lostpass_email_loading").innerHTML="<span style='color:#006600' >Your new password has been sent to your email!</span>";
	}
}


function lostPasswordContent()
{
var dvContent= '<form id="frm_lostpassword" name="frm_lostpassword" method="post" action=""><table><tr><td colspan="3"></td></tr><tr><td>اسم العضو</td><td>:</td><td><input name="username" id="lostpass_username" width="30" /><div align="left" id="lostpass_username_loading"></div></td></tr><tr><td>البريد</td><td>:</td><td><input name="email" id="lostpass_email" width="30" /><div align="left" id="lostpass_email_loading" style="display:none;"></div></td></tr></table><table><tr><td><input type="button" value="Submit" id="btn_lostpassword" onClick="JAVASCRIPT:CheckEmailMatch();">&nbsp;<input id="btn_cancel" type="button" onClick="onClick=onClickEvents(this.id)" value="Cancel"></td><td></td><td></td></tr></tr></table></form>';

return dvContent;
}
