function load(code) {
	var ajp = new AjaxPages();

	resu=ajp.load('index3.php?'+code);

	if (resu!="" && resu!="undefined") {
		return resu; } //else alert("ط¨ط±ظˆط² ط®ط·ط§");
//		window.scrollTo("50%",0);
}


function loader(url,funname){
//alert(url);
divinde=document.getElementById(funname);
divinde.innerHTML='<table width=100%><tr><td align=center><img src=images/load.gif><br> . . . ط¯ط± ط­ط§ظ„ ط¨ط§ط±ع¯ط²ط§ط±ظٹ</td></tr></table>';
setTimeout(funname+"('"+url+"')",400);
}



function sendloader(url){
funname='send';
nam=document.getElementById('name');
if (nam.value =='') {
			alert('لطفا نام و يا ايميل خود را وارد نماييد');
			nam.focus();
	return false;
	}
	messe=document.getElementById('mess');
	if (messe.value =='' ) {
			alert('لطفا متن پيام خود را وارد نماييد');
	messe.focus();
	return false;
	}
	divinde=document.getElementById(funname);
	divinde.innerHTML='<table width=100%><tr><td align=center><img src=images/load.gif><br> . . . در حال ارسال</td></tr></table>';
	setTimeout(funname+"('"+url+"')",400);
}


function loaderidea(url,checkid){
//alert(url);
funname1='nazar';
divinde=document.getElementById(funname1);
divinde.innerHTML='<table width=100%><tr><td align=center><img src=images/load.gif><br> . . . ط¯ط± ط­ط§ظ„ ط¨ط§ط±ع¯ط²ط§ط±ظٹ</td></tr></table>';

setTimeout("sendidea('"+url+"',"+checkid+")",400);
}
function sendidea(url,idd){
resss=load(url+'&itemid='+idd);
divinde.innerHTML=resss;
}


function send(url){

queee=messe;
//document.getElementById('mess');
namm=nam;
//document.getElementById('name');
//emaii=document.getElementById('email');

rque=encodeURIComponent(queee.value);
rnam=encodeURIComponent(namm.value);
//remai=encodeURIComponent(emaii.value);

divinde=document.getElementById('send');
resss1=load(url+'&body='+rque+'&name='+rnam);

divinde.innerHTML=resss1;
//alert(resss1);
}



function faqview(code){
divinde=document.getElementById('gallery');
resss=load('YToxOntzOjM6InVzciI7czoxMjoiZmFxL3Nob3cucGhwIjt9&fcid='+code);
divinde.innerHTML=resss;
}


function find(valu){
divinde=document.getElementById('gallery');
resss=load('YToxOntzOjM6InVzciI7czoxMjoiZmluZC9yZXMucGhwIjt9&fin='+encodeURIComponent(valu));
divinde.innerHTML=resss;
}


function sendloadermember(url,funname){
nam=document.getElementById('name1');
if (nam.value =='') {
		alert('ظ„ط·ظ&#65533;ط§ ظ†ط§ظ… ط±ط§ ظˆط§ط±ط¯ ظ†ظ…ط§غŒغŒط¯');
		nam.focus();
return false;
}
quee=document.getElementById('username1');
if (quee.value =='' || quee.value =='') {
	alert('ظ…طھظ† ظ†ط§ظ… ظƒط§ط±ط¨ط±ظٹ ط±ط§ ط®ط§ظ„غŒ ظ†ع¯ط°ط§ط±غŒط¯.');
quee.focus();
return false;
}
divinde=document.getElementById(funname);
//divinde.innerHTML='<table width=100%><tr><td align=center><img src=images/load.gif><br> . . . ط¯ط± ط­ط§ظ„ ط¨ط§ط±ع¯ط²ط§ط±ظٹ</td></tr></table>';

degreee=document.getElementById('degree1');
agg=document.getElementById('age1');
emaii=document.getElementById('email1');
username=document.getElementById('username1');
pass=document.getElementById('pass1');
city=document.getElementById('city1');

rnam=encodeURIComponent(nam.value);
rdegre=encodeURIComponent(degreee.value);
rag=encodeURIComponent(agg.value);
remai=encodeURIComponent(emaii.value);
rusername=encodeURIComponent(username.value);
rpass=encodeURIComponent(pass.value);
rcity=encodeURIComponent(city.value);

divinde=document.getElementById('gallery');

resss=load(url+'&nam='+rnam+'&degre='+rdegre+'&ag='+rag+'&emai='+remai+'&usernam='+rusername+'&pass='+rpass+'&cit='+rcity);
divinde.innerHTML=resss;

}


/*
function bookview(url,imgg){
bookvie=document.getElementById('bookview');
resss=load(url);
bookvie.innerHTML=resss;



imgvie=document.getElementById('imgdiv');
resimg=load(imgg);
imgvie.innerHTML=resimg;
document.getElementById('asdfasdfsdf').background="images/right_08.gif";
}
*/

/*
function leftload(url,titr){
leftconres=document.getElementById('leftcon');
titlee=document.getElementById('titlearticle');
ress=load(url);
ress1=load(titr);
backk=leftconres.innerHTML;
leftconres.innerHTML=ress;
titlee.innerHTML=ress1;
return backk;
}
*/

var AjaxPages = function() {};
/**
 * Loads an Ajax Pages template from a file
 * @param url The file to be loaded
 * @returns The template loaded
 */
AjaxPages.prototype.load = function ( url ) {
        var req;
        // branch for native XMLHttpRequest object


        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.open("GET", url, false);
//			req.onreadystatechange = callback(req);
//alert('asdfasdfasdf');
            req.send(null);
        // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {

            req="";
			req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
		   rand=Math.random();
		   req.open("GET", url+'&'+rand, false);

		   req.send(null);
			}
        }
        this.template = req.responseText;
        return req.responseText;
}

/**
 * Parses the template
 * @param value (Optional) The template code
 * @returns The javascript code generated from the parsing
 */
AjaxPages.prototype.parse = function( value ) {
    if ( value == undefined ) {
        value = this.template;
    }
    var out = "";
    var lineNumber = 1;
    try {

        var betweenPerc = false;

        out = "function(context) { \n";

        out += "var __ajp = new AjaxPages();\n";
        out += "var __include;\n";

        out += "try {\n"

        out += "   if ( context == undefined ) { \n";
        out += "       context = '';\n";
        out += "   }\n";

        out += "var out= unescape('";

        var line = "";

        for (i = 0; i < value.length; i++ )
        {
            var nextTwo = "";
            if ( i <= value.length - 2 ) {
                nextTwo = value.charAt(i) + value.charAt( i + 1 );
            }

            var nextThree = "";
            if ( i <= value.length - 3 ) {
                nextThree = value.charAt(i) + value.charAt( i + 1 ) + value.charAt( i + 2 );
            }

            if ( nextTwo == "<%" && nextThree != "<%=" && nextThree != "<%@") {

                out += "');\n";
                betweenPerc = true;
                i += 1;

            } else if ( nextTwo == "<%" && nextThree == "<%=" && nextThree != "<%@") {

                out += escape(line) + "');\n";
                line = "";
                out += "    out+= ";

                betweenPerc = true;
                i += 2;
            } else if ( nextTwo == "<%" && nextThree != "<%=" && nextThree == "<%@" ) {

                i += 3;
                var directive = "";

                while ( nextTwo != "%>" ) {
                    directive += value.charAt(i);
                    i++;
                        if ( i <= value.length - 2 ) {
                            nextTwo = value.charAt(i) + value.charAt( i + 1 );
                        }

                }

                out += escape(line) + "');\n";
                line = "";


                out += this._processDirective( directive );
                out += "    out+= unescape('";
                i++;
            } else if ( nextTwo == "%>" ) {
                out += ";\n" + "    out+= unescape('";
                // TODO Throw error if it is off, wrong sintax
                betweenPerc = false;
                i += 1;
            } else if ( value.charAt(i) == String.fromCharCode(10) )  {
                if ( !betweenPerc ) {
                    out += escape(line) + "\\n');\n" + "    out+= unescape('";
                    line = "";
                    lineNumber ++;
                }

            } else if ( value.charAt(i) == String.fromCharCode(13) )  {
            } else {
                if ( betweenPerc ) {
                    out += value.charAt(i) ;
                } else {
                    line += value.charAt(i);
                }
            }
        }

        out += escape(line) + "');\n";

        out += "} catch (e) {"
        out += "return '"+"An exception occurred while excuting template. Error type: ' + e.name"
               + "+ '. Error message: ' + e.message;";
        out += "}"
        out += "    return out;\n";
        out += "}\n";
   } catch (e) {

        out = "function(context) { \n";
        out += "return '"+"An exception occurred while parsing on line "+ lineNumber +". Error type: " + e.name
               + ". Error message: " + e.message+"';";
        out += "}"
   }

    return out;
}





/**
 * Private method. Should not be used externally.
 * @private
 */
AjaxPages.prototype._processDirective = function(directive) {
    var i = 0;

    var tolkenIndex = 0;
    var tolken = new Array();

    //Skip first spaces;
    while ( directive.charAt(i) == ' ' ) {
        i++;
    }

    tolken[tolkenIndex] = "";
    while ( directive.charAt(i) != ' ' && i <= directive.length ) {
        tolken[tolkenIndex] += directive.charAt(i);
        i++;
    }

    tolkenIndex++;

    //Skip first spaces;
    while ( directive.charAt(i) == ' ' ) {
        i++;
    }

    tolken[tolkenIndex] = "";
    while ( directive.charAt(i) != ' ' && directive.charAt(i) != '=' && i <= directive.length ) {
        tolken[tolkenIndex] += directive.charAt(i);
        i++;
    }

    tolkenIndex++;

    //Skip first spaces;
    while ( directive.charAt(i) == ' ' ) {
        i++;
    }

    if( directive.charAt(i) != '=' )
        throw new AjaxPagesException("Sintax error", "Tolken = expected attribute");
    i++

    //Skip first spaces;
    while ( directive.charAt(i) == ' ' ) {
        i++;
    }

    tolken[tolkenIndex] = "";
    while ( directive.charAt(i) != ' ' && i <= directive.length ) {
        tolken[tolkenIndex] += directive.charAt(i);
        i++;
    }
    tolkenIndex++;

    //Skip first spaces;
    while ( directive.charAt(i) == ' ' &&  i <= directive.length ) {
        i++;
    }

    tolken[tolkenIndex] = "";
    while ( directive.charAt(i) != ' ' && directive.charAt(i) != '=' && i <= directive.length && i <= directive.length ) {
        tolken[tolkenIndex] += directive.charAt(i);
        i++;
    }

    tolkenIndex++;

    if( directive.charAt(i) != '='  && i <= directive.length  )
        throw  new AjaxPagesException("Sintax error", "Tolken = expected after attribute" );
    i++

    tolken[tolkenIndex] = "";
    while ( directive.charAt(i) != ' ' && i <= directive.length  && i <= directive.length ) {
        tolken[tolkenIndex] += directive.charAt(i);
        i++;
    }

    var file = "";
    var context = "";

    if ( tolken[0] != "include" )
        throw new AjaxPagesException("Sintax error","Directive " + tolken[0] + " unknown.") ;

    if ( tolken[1] != "file" )
        throw new AjaxPagesException("Sintax error", "Attribute file expected after include." );
    else file = tolken[2];


    if ( tolken[3] != "context" && tolken[3] != "" )
        throw new AjaxPagesException( "Sintax error", "Attribute context expected after file.");
    else if ( tolken[3] == "context" )
        context = tolken[4]
    else
        context = "context";

    var out  = "    __ajp.load("+ file +");\n";
        out += "    __include = __ajp.getProcessor();\n";
        out += "    out+= __include(" + context + ");\n";

    return out;

}

/**
 * Processes the template
 * @param value (Optional) The template code.
 * @returns The output from processing the template
 */
AjaxPages.prototype.process = function( value ) {
    eval ( "var processor =" + this.parse( value ) );
    return processor();
}

/**
 * Get the function that processes the template
 * @param value (Optional) The template code
 * @returns The function that process the template
 */
AjaxPages.prototype.getProcessor = function( value ) {
    eval ( "var processor =" + this.parse( value ) );
    return processor;
}

/**
 * Exception throwed by AjaxPages
 */
AjaxPagesException = function( name, message ) {
    this.name = name;
    this.message = message;
}


function callback(req) {
if (req.readyState == 4) {
document.getElementById('left').innerHTML="ط¯ط± ط­ط§ظ„ ط¨ط§ط±ع¯ط²ط§ط±ظٹ <img src='images/indicator_green.gif' />";
//do something interesting here
	}
}
