﻿Image1= new Image(84,22)
Image1.src = "images/about1.gif";

Image2= new Image(84,22)
Image2.src = "images/contact1.gif";

Image3= new Image(84,22)
Image3.src = "images/index1.gif";

Image4= new Image(84,22)
Image4.src = "images/help1.gif";

Image5= new Image(84,22)
Image5.src = "images/advers1.gif";

Image6= new Image(72,20)
Image6.src = "images/buy1.gif";

Image7= new Image(72,20)
Image7.src = "images/more1.gif";

Image8= new Image(90,13)
Image8.src = "images/ajax-loader.gif";

Image9= new Image(90,13)
Image9.src = "admin/images/ajax-loader.gif";


var headID1 = document.getElementsByTagName("head")[0];         
var oScript1 = document.createElement("script");
oScript1.type = "text/javascript";
oScript1.src ="script/color_functions.js";
headID1.appendChild(oScript1);

var headID1 = document.getElementsByTagName("head")[0];         
var oScript1 = document.createElement("script");
oScript1.type = "text/javascript";
oScript1.src ="script/js_color_picker_v2.js";
headID1.appendChild(oScript1);


var headID = document.getElementsByTagName("head")[0];         
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href ="script/js_color_picker_v2.css";
cssNode.media = 'screen';
headID.appendChild(cssNode);


var xmlHttp,xmlHttp1,xmlHttp2;
var obj,obj1,obj2,divI;
var inimg="<img src='images/ajax-loader.gif' />";
var source1,divID1,mypost1,source2,divID2,mypost2;
var loopCheck= true;
mypost1 = '&test=test';
mypost2 = '&test=test';
mypost3 = '&test=test';

function loading(divI){
	$('#'+divI).hide().empty();
	$('#mywait').fadeIn();
}

function load(divI){
	$('#mywait').hide();
	$('#'+divI).fadeIn();
}

function Post(a , b , source,divID){
  var pos , chars , operand , mypost;
  if (source.length > 0){
	for(i=0 ; i<a.length ; i++){
		if(a[i]=='###')
			continue;
		if(b[i].indexOf('#@' , 0)!=-1){
			mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value;
			continue;
		}
		pos = a[i].indexOf('#' , 0);
		if(pos==-1){
			if(!checkEmp(a[i] , b[i]))
				return false;
			mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value;
		}else{
			operand = a[i].slice(pos+1);
			a[i] = a[i].slice(0 , pos);
			if(!checkEmp(a[i] , b[i]))
				return false;
			chars = operand.slice(3);
			operand = operand.slice(0 , 3);
			switch (operand) {
				case 'mai' :
					if(!email(a[i]))
						return false;
					mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value; break;
				case 'pas' : 
					if(!checkEmp(a[i+1] , b[i+1]))
						return false;
					if(!checkEqual(a[i] , a[i+1] , b[i]+' و '+b[i+1]))
						return false;
						mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value;
						mypost = mypost + '&'+a[i+1]+'='+document.getElementById(a[i+1]).value;
						a[i+1] ='###'; break;
				case 'min' :
					if(!checkMin(a[i] , chars , b[i]))
						return false;
					mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value; break;
				case 'max' :
					if(!checkMax(a[i] , chars , b[i]))
						return false;
					mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value; break;
				default : break;
			}
			
		}
	}
    obj = document.getElementById(divID);
	divI=divID;
	if(document.getElementById("mywait")){
		loading(divID);
	}
	
	//This is the url that links to the php page with POST Elemenets
	var url= source;
    xmlHttp=GetXmlHttpObject3(checkReadyState3)
    xmlHttp.open("POST", url , true)
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlHttp.setRequestHeader('Content-length', mypost.length);
    xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.send(mypost);
 } //  end of the souce.length
  else{ 
	obj.innerHTML=""
  }
}// ENd of the Get data function


function Get(source,divID){
	obj = document.getElementById(divID);
	if (source.length > 0){
	  divI=divID;
	  if(document.getElementById("mywait")){
		loading(divID);
	  }
	  //This is the url that links to the php page with GET Elemenets
	  var url= source;
      xmlHttp=GetXmlHttpObject3(checkReadyState3)
      xmlHttp.open("GET", url , true)
	  xmlHttp.send(null)
	}else
	  obj.innerHTML="";
}

function Get2(source,divID){
  if (source.length > 0){
    obj2 = document.getElementById(divID);
  	divI=divID;
	if(document.getElementById("mywait")){
		loading(divID);
	}
	//This is the url that links to the php page with POST Elemenets
	var url= source;
    xmlHttp2=GetXmlHttpObject3(checkReadyState4)
      xmlHttp2.open("GET", url , true)
	  xmlHttp2.send(null)
	}else
	  obj2.innerHTML="";
}

function checkForm(a,b){
	if((a==0) || (b==0))
		return true;
	var pos , chars , operand , mypost;
	for(i=0 ; i<a.length ; i++){
		if(a[i]=='###')
			continue;
		if(b[i].indexOf('#@' , 0)!=-1){
			mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value;
			continue;
		}
		pos = a[i].indexOf('#' , 0);
		if(pos==-1){
			if(!checkEmp(a[i] , b[i]))
				return false;
			mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value;
		}else{
			operand = a[i].slice(pos+1);
			a[i] = a[i].slice(0 , pos);
			if(!checkEmp(a[i] , b[i]))
				return false;
			chars = operand.slice(3);
			operand = operand.slice(0 , 3);
			switch (operand) {
				case 'mai' :
					if(!email(a[i]))
						return false;
					mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value; break;
				case 'pas' : 
					if(!checkEmp(a[i+1] , b[i+1]))
						return false;
					if(!checkEqual(a[i] , a[i+1] , b[i]+' و '+b[i+1]))
						return false;
						mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value;
						mypost = mypost + '&'+a[i+1]+'='+document.getElementById(a[i+1]).value;
						a[i+1] ='###'; break;
				case 'min' :
					if(!checkMin(a[i] , chars , b[i]))
						return false;
					mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value; break;
				case 'max' :
					if(!checkMax(a[i] , chars , b[i]))
						return false;
					mypost = mypost + '&'+a[i]+'='+document.getElementById(a[i]).value; break;
				default : break;
			}
			
		}
	}
	mypost3 = mypost;
	return true;
}




function Waiting(a, b, source,divID){
	if(!loopCheck)
		return false;
	mypost3 += '&w2=true';
	if(!checkForm(a,b))
		return false;
	source1= source;
	divID1=divID;
  if (source.length > 0){
    obj2 = document.getElementById(divID);
	//This is the url that links to the php page with POST Elemenets
	var url= source;
    xmlHttp2=GetXmlHttpObject4(checkReadyStateWait)
    xmlHttp2.open("POST", url , true)
    xmlHttp2.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlHttp2.setRequestHeader('Content-length', mypost3.length);
    xmlHttp2.setRequestHeader('Connection', 'close');
	xmlHttp2.send(mypost3);
 } //  end of the souce.length
  else{ 
	obj2.innerHTML=""
  }
}// ENd of the Get data function

function WaitingList(source5,divID5){
	if(!loopCheck)
		return false;
	mypost2 = '&checking='+document.getElementById('checking').value;
	source2= source5;
	divID2=divID5;
  if (source5.length > 0){
    obj1 = document.getElementById(divID5);
	//This is the url that links to the php page with POST Elemenets
	var url1= source5;
    xmlHttp1=GetXmlHttpObjectWait(checkReadyStateWaitList)
    xmlHttp1.open("POST", url1 , true)
    xmlHttp1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlHttp1.setRequestHeader('Content-length', mypost2.length);
    xmlHttp1.setRequestHeader('Connection', 'close');
	xmlHttp1.send(mypost2);
 } //  end of the souce.length
  else{ 
	obj1.innerHTML=""
  }
}// ENd of the Get data function


function GetXmlHttpObject3(handler){
  var objXmlHttp=null
  if (navigator.userAgent.indexOf("Opera")>=0)
  {
    alert("This example doesn't work in Opera") 
	  return 
  }
  if (navigator.userAgent.indexOf("MSIE")>=0){ 
    var strName="Msxml2.XMLHTTP"
    if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
      strName="Microsoft.XMLHTTP"
    } 
    try{ 
      objXmlHttp=new ActiveXObject(strName)
      objXmlHttp.onreadystatechange=handler 
      return objXmlHttp
    } 
    catch(e){ 
      alert("Error. Scripting for ActiveX might be disabled") 
      return 
    } 
  } 
  if (navigator.userAgent.indexOf("Mozilla")>=0){
    objXmlHttp=new XMLHttpRequest()
	objXmlHttp.onload=handler
	objXmlHttp.onerror=handler 
	return objXmlHttp
  }
} 

function GetXmlHttpObject4(handler){
  var objXmlHttp2=null
  if (navigator.userAgent.indexOf("Opera")>=0)
  {
    alert("This example doesn't work in Opera") 
	  return 
  }
  if (navigator.userAgent.indexOf("MSIE")>=0){ 
    var strName="Msxml2.XMLHTTP"
    if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
      strName="Microsoft.XMLHTTP"
    } 
    try{ 
      objXmlHttp2=new ActiveXObject(strName)
      objXmlHttp2.onreadystatechange=handler 
      return objXmlHttp2
    } 
    catch(e){ 
      alert("Error. Scripting for ActiveX might be disabled") 
      return 
    } 
  } 
  if (navigator.userAgent.indexOf("Mozilla")>=0){
    objXmlHttp2=new XMLHttpRequest()
	objXmlHttp2.onload=handler
	objXmlHttp2.onerror=handler 
	return objXmlHttp2
  }
} 

function GetXmlHttpObjectWait(handler){
  var objXmlHttp1=null
  if (navigator.userAgent.indexOf("Opera")>=0)
  {
    alert("This example doesn't work in Opera") 
	  return 
  }
  if (navigator.userAgent.indexOf("MSIE")>=0){ 
    var strName="Msxml2.XMLHTTP"
    if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
      strName="Microsoft.XMLHTTP"
    } 
    try{ 
      objXmlHttp1=new ActiveXObject(strName)
      objXmlHttp1.onreadystatechange=handler 
      return objXmlHttp1
    } 
    catch(e){ 
      alert("Error. Scripting for ActiveX might be disabled") 
      return 
    } 
  } 
  if (navigator.userAgent.indexOf("Mozilla")>=0){
    objXmlHttp1=new XMLHttpRequest()
	objXmlHttp1.onload=handler
	objXmlHttp1.onerror=handler 
	return objXmlHttp1
  }
} 


function checkReadyState3(){
	if(xmlHttp.readyState < 4) {
		// not load
	}
	else
	{
		if(xmlHttp.status == 200)
		{
			load(divI);
			obj.innerHTML=xmlHttp.responseText;
		}
		else if(xmlHttp.status == 404)
		{
			load(divI);
		}
		else
		{
			load(divI);
		}
	}
}

function checkReadyState4(){
	if(xmlHttp2.readyState < 4) { document.getElementById("mywait").innerHTML =inimg; }
	else
	{
		if(xmlHttp2.status == 200)
		{
			obj2.innerHTML=xmlHttp2.responseText;
			document.getElementById("mywait").style.display="none";
		    document.getElementById("mywait").innerHTML = "";
		}
		else if(xmlHttp2.status == 404)
		{
			// Add a custom message or redirect the user to another page
			document.getElementById("mywait").style.display="block";
			document.getElementById("mywait").innerHTML = "";
		}
		else
		{
			document.getElementById("mywait").style.display="block";
			document.getElementById("mywait").innerHTML = "";
		}
	}
}

function checkReadyStateWait(){
	if(xmlHttp2.readyState < 4) { document.getElementById("mywait").innerHTML =inimg; }
	else
	{
		if(xmlHttp2.status == 200)
		{
			if(xmlHttp2.responseText==''){
				document.getElementById("mywait").innerHTML =inimg;
				if(loopCheck)
					setTimeout('Waiting(0,0,source1,divID1);',3000);
			}else{
				obj2.innerHTML=xmlHttp2.responseText;
				document.getElementById("mywait").style.display="none";
				document.getElementById("mywait").innerHTML = "";
				if(loopCheck)
					setTimeout('Waiting(0,0,source1,divID1);',3000);
			}
		}
		else if(xmlHttp2.status == 404)
		{
			// Add a custom message or redirect the user to another page
			document.getElementById("mywait").style.display="block";
			document.getElementById("mywait").innerHTML = "";
		}
		else
		{
			document.getElementById("mywait").style.display="block";
			document.getElementById("mywait").innerHTML = "";
		}
	}
}

function checkReadyStateWaitList(){
	if(xmlHttp1.readyState < 4) { }
	else
	{
		obj1.innerHTML=xmlHttp1.responseText;
		document.getElementById("mywait").style.display="none";
		document.getElementById("mywait").innerHTML = "";
		if(loopCheck)
			setTimeout('WaitingList(source2,divID2);',3000);
	}
}


function email(elem) {
    var val=".لطفا پست الکترونيکي معتبر وارد نماييد";
	var str = document.getElementById(elem).value;
	var at="@";
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert(val)
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert(val)
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert(val)
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		alert(val)
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert(val)
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		alert(val)
		return false
	}
		
	if (str.indexOf(" ")!=-1){
		alert(val)
		return false
	}
 	return true;
}
	
function checkEmp(elem , msg) {
	if (document.getElementById(elem).value == "") {
		alert (".لطفا "+msg+" را وارد كنيد")
		return false;
	}
	return true;
}

	
function checkEqual(elem1 , elem2 , msg ) {
	if (document.getElementById(elem1).value != document.getElementById(elem2).value) {
		alert ("."+msg+" ، با هم يكسان نيستند")
		return false;
	}
	return true;
}


function checkMin(elem , minLength , msg) {
	if (document.getElementById(elem).value.length < minLength) {
		alert (".حداقل كاراكتر مجاز براي "+msg+" ، "+minLength+ " مي باشد")
		return false;
	}
	return true;
}
function checkMax(elem , maxLength , msg) {
	if (document.getElementById(elem).value.length > maxLength) {
		alert (".حداكثر كاراكتر مجاز براي "+msg+" ، "+maxLength+ " کاراکتر مي باشد \n عبارتي كه شما وارد كرديد ، "
		+document.getElementById(elem).value.length+" كاراكتر است" )
		return false;
	}
	return true;
}

function checkOnline(){
	Waiting(0, 0, 'inc/func.php','ondiv');
}

function logIn() {
	a= new Array('login_name','login_pass');
	b= new Array('نام کاربري' , 'رمز عبور');
	Post(a , b , 'index.php' ,'bodyajax');
	setTimeout("Get2('menu.php' ,'adminMenu');" , 1000);
}

function logOut() {
	if(confirm('آيا مي خواهيد خارج شويد ؟')){
		Get('login.php?logout=true' ,'bodyajax');
		Get2('menu.php' ,'adminMenu');
	}
}

