﻿//***************************************************************************************************
										/* Menu show panel script */
//***************************************************************************************************
function change_menu(obj,img)
{
	document.getElementById(obj).style.background = "url('template/dana/images/smenu_item.png') no-repeat center";
	show_menu(obj,img);
}
function reset_menu(obj)
{
	document.getElementById(obj).style.background = "url('template/dana/images/menu_item.png') no-repeat center";
	hide_menu(obj);        		
}
function show_menu(obj,img)
{
	menu_item = document.getElementById(obj);
	menu_div = document.getElementById("sub_" + obj);
	
	menu_div.style.background = "url('template/dana/images/smenu/" + img + ".png') no-repeat center";	
	menu_div.style.display = "block";
	menu_div.style.top = 135;
	menu_div.style.right = (screen.width /2) - 493;
}
function hide_menu(obj)
{
	document.getElementById("sub_" + obj).style.display = "none";
}
//***************************************************************************************************
function show_erore(object1,object2)
{  
	obj1 = document.getElementById(object1);
	obj2 = document.getElementById(object2);
	if  (obj1.value == "")
	     obj2.style.display = "block";
	else
	     obj2.style.display = "none";      
}
//***************************************************************************************************
 function close_layout(object)
  {  
    obj = document.getElementById(object);
    if  (obj.style.display == "none")
         obj.style.display = "block";
    else
         obj.style.display = "none";      
  }
// show menu *******************************************************************************************
function close_layout_menu(object)
{
	close_menu();
    obj = document.getElementById(object);
         obj.style.display = "block";
}
// Show news Function *********************************************************************************
function show(imgID) 
{
    currentVote=parseInt(document.getElementById("vote").value);
    if (imgID==-1) 
        imgID=currentVote;
    if (imgID<currentVote)
      return;
    for (i=1;i<=imgID;i++)
        document.getElementById("r"+i).className="transOFF";
    for (i=imgID+1;i<=5;i++)
        document.getElementById("r"+i).className="transON";
}

function validateForm()
{
	flag = check("name");
	if (flag && !checkEmail(trim(document.getElementById("email").value)))
	{
	    document.getElementById("email").style.backgroundColor="#FFE7F3";
	    return false;                       
	}
	else
	    document.getElementById("email").style.backgroundColor = "";
	flag = flag && check("description");
	return flag;
}
function check(item)
{    
    if (trim(document.getElementById(item).value)=="")
    {
        document.getElementById(item).style.backgroundColor="#FFE7F3";
        return false;
    }
    else
        document.getElementById(item).style.backgroundColor="";
    return true;
}

function checkEmail(email) 
{
    if (trim(email)!="" && email.search(/^[^@]+@[^@]+.[a-z]{2,}$/i)==-1)
        return false;
    return true;
}
function changeVote(i)
{
    document.getElementById("vote").value=i;
    show(i);
} 
function LTrim( value ) {
    
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
    
}

// Removes ending whitespaces
function RTrim( value ) {
    
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
    
}

// Removes leading and ending whitespaces
function trim( value ) {
    
    return LTrim(RTrim(value));
    
}function LTrim( value ) {
    
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
    
}

// Removes ending whitespaces
function RTrim( value ) {
    
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
    
}

// Removes leading and ending whitespaces
function trim( value ) {
    
    return LTrim(RTrim(value));
    
}

function changeDays()
{
    year=(document.getElementById('year').value);
    if (year<1380 || year>1410)
    {
        document.getElementById('year').style.backgroundColor='#FFE7F3';
        return;
    }
    else
    document.getElementById('year').style.backgroundColor='';    
    month	= document.getElementById('month').value;
    daylist	= document.getElementById('day').value;
    jYear	= document.getElementById('jYear').value;
    jMonth	= document.getElementById('jMonth').value;
    jDay	= document.getElementById('jDay').value;
    daylist	= document.getElementById('day');
    if (month<='06')
        lastDay=31;
    else if (month<='11')
        lastDay=30;
    else
    {
        if (year%4==3)
            lastDay=30;
        else
            lastDay=29;
    }
    daylist.options.length=0;
    var d = new Date();
    var flag=false;
    if (year==jYear && month==jMonth)
        flag=true;
    for (i=1;i<=lastDay;i++)
        daylist.options[daylist.options.length] = new Option(i,(i<10?"0"+i:i), false, (flag && jDay==i));
}

//************************************************** AJAX Function *******************************************
var xmlHttp;
var div;
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
     {
         // Firefox, Opera 8.0+, Safari
         xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     // Internet Explorer
     try
      {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
     if (xmlHttp==null)
        alert ("Your browser dos not support this plugin . Use new version of your browser, Please");
     return xmlHttp;
}
function stateChanged() 
{
    if(xmlHttp.readyState==1)
    {
    }
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
        document.getElementById(div).innerHTML=xmlHttp.responseText;
     }    
}
function add_news(type,cat,location)
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      {
      alert ("Your browser dos not support this plugin . Use new version of your browser, Please");
      return false;
      } 
     limit = Number(document.getElementById("news_hide" + cat).value);

        if (type=="add")
        {
                limit += 1;
        }
        else
        {
                limit -= 1;
        }
      if( limit >= 2 && limit <= 9)
      {
        var url="module/mod_news/news_ajax.php";
        url = url + "?catid=" + cat + "&limit=" + limit;
        div = location ;
        xmlHttp.onreadystatechange = stateChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
}

//*******************************************News Search ****************************************
function search_validate(obj,msg)
{
    if(trim(document.getElementById(obj).value) == "")
    {
        alert(msg);
        return false;
    }
    return true;
}
function post_search(mod)
{
    if (!search_validate("txt_pattern","الگوی جستجو را وارد کنید"))
        return false;

    url 	= "?mod=search&action=" + mod;
    lid 	= "lid=" + document.getElementById('chk_lid').checked;    
    abs 	= "abs=" + document.getElementById('chk_abs').checked;
    body 	= "body=" + document.getElementById('chk_body').checked;    
    whole 	= "whole=" + document.getElementById('chk_whole').checked;    
    pic 	= "pic=" + document.getElementById('chk_pic').checked;
    syear 	= "syear=" + document.getElementById("syear_slc").options[document.getElementById("syear_slc").selectedIndex].value;
    smonth 	= "smonth=" + document.getElementById("smonth_slc").options[document.getElementById("smonth_slc").selectedIndex].value;
    sday 	= "sday=" + document.getElementById("sday_slc").options[document.getElementById("sday_slc").selectedIndex].value;
    eyear 	= "eyear=" + document.getElementById("eyear_slc").options[document.getElementById("eyear_slc").selectedIndex].value;
    emonth 	= "emonth=" + document.getElementById("emonth_slc").options[document.getElementById("emonth_slc").selectedIndex].value;
    eday 	= "eday=" + document.getElementById("eday_slc").options[document.getElementById("eday_slc").selectedIndex].value;
    sort 	= "sort=" + document.getElementById("slc_sort").options[document.getElementById("slc_sort").selectedIndex].value;
    number 	= "number=" + document.getElementById("slc_number").options[document.getElementById("slc_number").selectedIndex].value;
    lim 	= "lim=" + document.getElementById("slc_number").options[document.getElementById("slc_number").selectedIndex].value;
    catid 	= "catid=" + document.getElementById("slc_newscat").options[document.getElementById("slc_newscat").selectedIndex].value;
    url    += "&" + catid + "&" + lid + "&" + abs + "&" + abs + "&" + body + "&" + whole + "&" + pic + "&" + syear + "&" + smonth + "&" + 
    sday   +  "&" + eyear + "&" + emonth + "&" + eday + "&" + sort + "&" + number + "&" + lim;

    frm = document.forms[0];
    frm.action = url;
    frm.submit();
}
function post_archive(mod)
{
    syear = "syear=" + document.getElementById("syear_slc").options[document.getElementById("syear_slc").selectedIndex].value;
    smonth = "smonth=" + document.getElementById("smonth_slc").options[document.getElementById("smonth_slc").selectedIndex].value;
    sday = "sday=" + document.getElementById("sday_slc").options[document.getElementById("sday_slc").selectedIndex].value;
    eyear = "eyear=" + document.getElementById("eyear_slc").options[document.getElementById("eyear_slc").selectedIndex].value;
    emonth = "emonth=" + document.getElementById("emonth_slc").options[document.getElementById("emonth_slc").selectedIndex].value;
    eday = "eday=" + document.getElementById("eday_slc").options[document.getElementById("eday_slc").selectedIndex].value;
    sort = "sort=" + document.getElementById("slc_sort").options[document.getElementById("slc_sort").selectedIndex].value;
    number = "number=" + document.getElementById("slc_number").options[document.getElementById("slc_number").selectedIndex].value;
    lim = "lim=" + document.getElementById("slc_number").options[document.getElementById("slc_number").selectedIndex].value;
    catid = "catid=" + document.getElementById("slc_newscat").options[document.getElementById("slc_newscat").selectedIndex].value;
    url += "&" + catid + "&" + syear + "&" + smonth + "&" + sday +     "&" + eyear + "&" + emonth + "&" + eday + "&" + sort + "&" + number + "&" + lim;

    frm = document.forms[0];
    frm.action = url;
    frm.submit();
}
function high_color(obj)
{
    obj.style.backgroundColor = "#eef9f3";
}
function low_color(obj)
{
    obj.style.backgroundColor = "";
}
function cat_update(id)
{
    if (search_validate("txt_category","نام دسته خبری را وارد کنید"))
            document.forms["frm_cat"].submit()
        else
        return false;
}
function cat_del(id,mod)
{
    var answer = confirm("آیا شما مایل به حذف این دسته خبری هستید ؟");    
    if(answer)
    {
        location.href = "?mod=category&action=" + mod + "&act=delete&catid=" + id ;
    }
}
function add_cat()
{
    if (search_validate("txt_category","نام دسته خبری را وارد کنید"))
            document.forms["frm_cat"].submit()
        else
        return false;
}
function ValidRegister()
{
	id=0;
	name1 	= document.getElementById("txtName");
	family 	= document.getElementById("txtFamily");
	user 	= document.getElementById("txtUser");
	email 	= document.getElementById("txtEmail");
	email2 	= document.getElementById("txtEmail2");
	action	= document.getElementById("action");
	if(name1.value == "")
		id++;
	if(family.value == "")
		id++;
	if(user.value == "")
		id++;
	if(email.value == "")
		id++;
	if(email2.value == "")
		id++;
	if(checkEmail(email.value))
		document.getElementById("er_email_check").style.display = "none";
	else
	{
		id++;
		document.getElementById("er_email_check").style.display = "block";
	}
	if(email.value == email2.value)
		document.getElementById("er_email").style.display = "none";
	else
	{
		id++;
		document.getElementById("er_email").style.display = "block";
	}
	if(id == 0)
	{
		var url = "ajax.php?mod=login&action=" + action.value + "&txtName=" + name1.value + "&txtFamily=" + family.value + "&txtUser=" + user.value + "&txtEmail=" + email.value;
		show_ajax(url,'window');
	}
}
function user_login()
{
	user = document.getElementById("txt_user");
	pass = document.getElementById("txt_pass");
	dest = document.getElementById("dest");
	var url = "ajax.php?mod=login&action=redirect&tul="+user.value+"&tpl="+pass.value;
	url = trim(url);
	show_ajax(url,'window');
}
function forgetpass()
{
	id = 0
	email = document.getElementById("txtEmail");
	if(email.value == "")
		id++;
	if(checkEmail(email.value))
		document.getElementById("er_email_check").style.display = "none";
	else
	{
		id++;
		document.getElementById("er_email_check").style.display = "block";
	}
	if(id == 0)
		show_ajax("ajax.php?mod=login&action=sendpass&txtEmail=" + email.value, 'window');
}
function redirect_ajax(url)
{
	window.location = url;
}
function close_window()
{
	document.getElementById("hidden").style.display = "none";
}
function hide_window()
{
	document.getElementById("hidden").style.display = "block";
}
function show_ajax(url,location)
{
	div = location;
	document.getElementById(div).innerHTML = "";
	if(location == "window")
		hide_window();
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("مرورگر شما از برنامه سایت پشتیبانی نمی کند . از مرورگر جدیدتر استفاده کنید");
	  return flase;
	  }
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
