
var ajax_subscription={
loadingmessage: '<div style="text-align:center;width:100%;height:100px;font-family:Tahoma;font-size:8pt;"><p><br></p><img src="../../images/ajax_loading.gif"></div>',
exfilesadded: "",

connect:function(containerid, pageurl, bustcache, jsfiles, cssfiles){
	var page_request = false
	var bustcacheparameter=""
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE6 or below
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
	page_request.onreadystatechange=function(){ajax_subscription.loadpage(page_request, containerid, pageurl, jsfiles, cssfiles)}
	if (bustcache) //if bust caching of external page
		bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	document.getElementById(containerid).innerHTML=ajax_subscription.loadingmessage //Display "fetching page message"
	//document.getElementById('ajax_loading_div').style.display='block';
	page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
	page_request.send(null)
},

loadpage:function(page_request, containerid, pageurl, jsfiles, cssfiles){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(containerid).innerHTML=page_request.responseText
		//document.getElementById('ajax_hidden_load_data').innerHTML=page_request.responseText;
		for (var i=0; i<jsfiles.length; i++)
			this.loadjscssfile(jsfiles[i], "js")
		for (var i=0; i<cssfiles.length; i++)
			this.loadjscssfile(cssfiles[i], "css")
		this.pageloadaction(pageurl) //invoke custom "onpageload" event
	}
},

createjscssfile:function(filename, filetype){
	if (filetype=="js"){ //if filename is a external JavaScript file
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", filename)
	}
	else if (filetype=="css"){ //if filename is an external CSS file
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", filename)
	}
	return fileref
},

loadjscssfile:function(filename, filetype){ //load or replace (if already exists) external .js and .css files
	if (this.exfilesadded.indexOf("["+filename+"]")==-1){ //if desired file to load hasnt already been loaded
		var newelement=this.createjscssfile(filename, filetype)
		document.getElementsByTagName("head")[0].appendChild(newelement)
		this.exfilesadded+="["+filename+"]" //remember this file as being added
	}
	else{ //if file has been loaded already (replace/ refresh it)
 	var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
 	var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
 	var allsuspects=document.getElementsByTagName(targetelement)
 	for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  	if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1){
   	var newelement=this.createjscssfile(filename, filetype)
   	allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
  	}
		}
 }
},


pageloadaction:function(pageurl){
	this.onpageload(pageurl) //call customize onpageload() function when an ajax page is fetched/ loaded
},

onpageload:function(pageurl){
 //do nothing by default

},

load:function(containerid, pageurl, bustcache, jsfiles, cssfiles){
	var jsfiles=(typeof jsfiles=="undefined" || jsfiles=="")? [] : jsfiles
	var cssfiles=(typeof cssfiles=="undefined" || cssfiles=="")? [] : cssfiles
	this.connect(containerid, pageurl, bustcache, jsfiles, cssfiles)
}

} 

var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

function send_message(culture)
{
	var name=document.getElementById('contact-name').value;
	var email=document.getElementById('contact-email').value;
	var body=document.getElementById('contact-messagebody').value;
	name=Base64.encode(name);
	email=Base64.encode(email);
	body=Base64.encode(body);
	ajaxpagefetcher.load('contact_result_div','send_message.php?name='+name+'&email='+email+'&body='+body+'&culture='+culture,true);
	document.getElementById('contact-name').value='';
	document.getElementById('contact-email').value='';
	document.getElementById('contact-messagebody').value='';
	document.getElementById('contact_submit').disabled='disabled';
	document.getElementById('contact_reset').disabled='disabled';
}
function Subscription(rand)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5);
	var name=document.getElementById('name').value;
	var email=document.getElementById('email').value;
	ajax_subscription.load('subscription_form','register.php?culture='+culture+'&rand='+rand+'&name='+encodeURI(name)+'&email='+encodeURI(email),true);
}

function RSS_Panel()
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="rss/panel.php?culture="+culture;
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="rss/panel.php?culture="+culture;
	}
	/*
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	var url="rss/panel.php?culture="+culture;
	*/
	var width = 400;
    var height = 350;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "news_send_window", windowFeatures);

}
function solutions()
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="solutions.php?culture="+culture+"&list";
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="solutions.php?culture="+culture+"&list";
	}
	/*
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	var url="solutions.php?culture="+culture+"&list";
	*/
	var width = 800;
    var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "solutions", windowFeatures);

}
function news_comments(id)
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="news_comments.php?culture="+culture+"&id="+id;	
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="news_comments.php?culture="+culture+"&id="+id;
	}
	
	var width = 500;
    var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "news_send_window", windowFeatures);

}
function photo_comments(id)
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="photo_comments.php?culture="+culture+"&id="+id;
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="photo_comments.php?culture="+culture+"&id="+id;
	}
	/*
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	var url="photo_comments.php?culture="+culture+"&id="+id;
	*/
	var width = 500;
    var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "news_send_window", windowFeatures);

}
function news_print(id)
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="news_print.php?culture="+culture+"&id="+id;
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="news_print.php?culture="+culture+"&id="+id;
	}
	/*
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	var url="news_print.php?culture="+culture+"&id="+id;
	*/
	var width = 800;
    var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",scrollbars,screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "news_send_window", windowFeatures);

}
function news_send(id,token)
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="news_send.php?culture="+culture+"&id="+id+"&token="+token;
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="news_send.php?culture="+culture+"&id="+id+"&token="+token;
	}
	/*
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	var url="news_send.php?culture="+culture+"&id="+id+"&token="+token;
	*/
	var width = 400;
    var height = 150;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "news_send_window", windowFeatures);

}
function explode( delimiter, string, limit ) {
    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/explode
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}
function News(id)
{
	var myString = self.location.href;
	//var culture = myString.substr(myString.length-5, 5); 	
	var queryStr=explode('=',myString);
	//alert(queryStr[1]);
	queryStr=explode('&',queryStr[1]);
	var culture=queryStr[0];
	
	if(id!=0){
		
		document.location.href='index.php?culture='+culture+'&html=newsbody&newsID='+id;
		//ajaxpagefetcher.load('main_div_ajax','news_body.php?culture='+culture+'&newsID='+id,true);
	}else{
		document.location.href='index.php?culture='+culture+'&html=news';
		//ajaxpagefetcher.load('main_div_ajax','news.php?culture='+culture,true);
	}
}
function More_Contacts(page)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	if(page!=0){
		ajaxpagefetcher.load('main_div_ajax','more_contact.php?culture='+culture +'&page='+page,true);
	}else{
		ajaxpagefetcher.load('main_div_ajax','contact.php?culture='+culture,true);
	}
}
function More_Brands(page)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	
	if(page!=0){
		ajaxpagefetcher.load('main_div_ajax','more_brands.php?culture='+culture +'&page='+page,true);
	}else{
		ajaxpagefetcher.load('main_div_ajax','home.php?culture='+culture,true);
	}
}
function More_News(page)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	if(page!=0){
		ajaxpagefetcher.load('main_div_ajax','more_news.php?culture='+culture +'&page='+page,true);
	}else{
		ajaxpagefetcher.load('main_div_ajax','news.php?culture=Fa-IR',true);
	}
}
function More_Albums(page)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	if(page!=0){
		ajaxpagefetcher.load('main_div_ajax','more_gallery.php?culture='+culture +'&page='+page,true);
	}else{
		ajaxpagefetcher.load('main_div_ajax','more_gallery.php?culture='+culture +'&page=1',true);
	}
}

function More_Photos(page,aid)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	if(page!=0){
		ajaxpagefetcher.load('main_div_ajax','photos.php?culture='+culture +'&aid='+aid+'&page='+page,true);
	}else{
		ajaxpagefetcher.load('main_div_ajax','albums.php?culture=Fa-IR',true);
	}
}
function album(id,token)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5);
	ajaxpagefetcher.load('main_div_ajax','photos.php?culture='+culture+'&aid='+id+'&page=1',true);
}
//--------------------------- solutions -----------------------------------
function solutionsList()
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	tabsOff();
	ajaxpagefetcher.load('main_div_ajax','solutions_list.php?culture='+culture,true);
}
function newSolution()
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="solutions_new.php?culture="+culture+"&list=ok";
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="solutions_new.php?culture="+culture+"&list=ok";
	}
	
	var width = 500;
    var height = 500;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "solutions_new", windowFeatures);

}
function More_Solutions(page)
{
	var myString = self.location.href;
	var culture = myString.substr(myString.length-5, 5); 
	if(page!=0){
		ajaxpagefetcher.load('main_div_ajax','solutions_list.php?culture='+culture+'&page='+page,true);
	}else{
		ajaxpagefetcher.load('main_div_ajax','solutions_list.php?culture=Fa-IR',true);
	}
}
function showSolutionContinue(id)
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="showSolutionContinue.php?culture="+culture+"&id="+id;
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="showSolutionContinue.php?culture="+culture+"&id="+id;
	}
	
	var width = 800;
    var height = 600;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "solutions", windowFeatures);

}
function copyLinkToClickBoard(linktext)
{
	window.clipboardData.setData("Text",linktext);
}
function userPhoto()
{
	var myString = self.location.href;
	var sp=myString.split("&");
	if(sp[1]){		
		var culture = sp[0].substr(sp[0].length-5, 5); 
		var url="userPhoto.php?culture="+culture;
	}else{
		var culture = myString.substr(myString.length-5, 5); 
		var url="userPhoto.php?culture="+culture;
	}
	
	var width = 500;
    var height = 500;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "news_send_window", windowFeatures);

}