﻿
//*******************************ajax***********************************

<!--
var xmlHttp;
function createRequest(){ 
if(window.ActiveXObject){ 
	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
} else if(window.XMLHttpRequest){  
	xmlHttp = new XMLHttpRequest(); 
} 
} 
/////////////////////////////////////////////////////
//                   ajax news                    ///
////////////////////////////////////////////////////
function ajax(url){ 
createRequest();
xmlHttp.open("GET", url, true); 
xmlHttp.onreadystatechange = updatepage; 
xmlHttp.send(null); 
}

function updatepage(){
	document.getElementById('load_ajax').innerHTML = "<div id='load_ajax' align='center'><img src='image/loading.gif'><br>Please wait... <br></div>"
	if(xmlHttp.readyState == 4){
		document.getElementById('load_ajax').innerHTML = xmlHttp.responseText
	}
}

/////////////////////////////////////////////////////
//                   Login                        ///
////////////////////////////////////////////////////

function login(){
$(document).ready(function()
{	
$("#login_form").submit(function()
	{
				
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('در حال اعتبار سنجی....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("checklogin.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
		  if(data==1) //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('شما وارد سایت شدید').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 $("#login_form").html('');
				 document.location='index.php';
				 
			  });
			  
			});
		  }
		  if(data==0) //if incorrect login detail 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('نام کاربری یا رمز عبور اشتباه است').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#password").blur(function()
	{
		$("#login_form").trigger('submit');
	});
	
});
}


/////////////////////////////////////////////////////
//                   show news box                ///
////////////////////////////////////////////////////
function showbox()
{
$(document).ready(function(){
				//Examples of how to assign the ColorBox event to elements
				
				$(".show1").colorbox({width:"70%", height:"70%"});
				$(".show2").colorbox({width:"70%", height:"70%", inline:true, href:"#load_ajax"});
				$(".show3").colorbox({width:"80%", height:"80%", iframe:true});
				
				
				//Example of preserving a JavaScript event for inline calls.
				$("#click").click(function(){ 
					$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
					return false;
				});
			});
   
}




/////////////////////////////////////////////////////
//                   check empty                  ///
////////////////////////////////////////////////////


function v2()
{
	errors=''
			
			
	if ( document.getElementById('username').value =="" ){
		errors+='           نام کاربری را وارد کنید'+ ' -' + '\n';
	}
			
	if ( document.getElementById("password").value =="" ){
		errors+='   رمز عبور را وارد کنید'+ ' -' + '\n';
		}
						 
	if (errors!=""){												
		alert('                  :خطاهاي ذيل را تصحيح کنيد\n'+errors);
		return false;
				
	}
	else {
				
		return true;
				
		}
			
}

/////////////////////////////////////////////////////
//                   tooltips                    ///
////////////////////////////////////////////////////
function tooltips()
{
$(document).ready(function(){
	tooltip();
});
}
//-->

