﻿/* ============================================= *\
|* ############################################# *|
|| #            ATLANTIANS GROUP                 ||
|| #      ~~~~~~~~~~~~ o ~~~~~~~~~~~~            ||
|| #	  AUTHOR:    Nickolas                    ||
|| #	  LANGUAGE:  PHP (4.3.9+)                ||
|| #      DESIGN:    CSS                         ||
|| #      DYNAMICS:  JAVASCRIPT                  ||
|* ############################################# *|
\* ============================================= */
var ua = navigator.userAgent.toLowerCase();
var is_opera = ((ua.indexOf('opera') != -1) || (typeof(window.opera) != 'undefined'));
var is_saf = ((ua.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_ie = ((ua.indexOf('msie') != -1) && (!is_opera) && (!is_saf));
var is_ie7 = ((ua.indexOf('msie 7.') != -1) && (is_ie));
var is_moz = ((!is_saf) && (navigator.product == 'Gecko'));
function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

function fetch_tags(parentobj, tag)
{
	if (parentobj == null)
	{
		return new Array();
	}
	else if (typeof parentobj.getElementsByTagName != 'undefined')
	{
		return parentobj.getElementsByTagName(tag);
	}
	else if (parentobj.all && parentobj.all.tags)
	{
		return parentobj.all.tags(tag);
	}
	else
	{
		return new Array();
	}
}

function stripos(haystack, needle, offset)
{
	if (typeof offset == 'undefined')
	{
		offset = 0;
	}

	index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);

	return (index == -1 ? false : index);
}

function trim(str)
{
	return str.replace(/\s+|(\s+)$/g, '');
}

function urlencode(text)
{
	text = escape(text.toString()).replace(/\+/g, "%2B");
	var matches = text.match(/(%([0-9A-F]{2}))/gi);
	if (matches)
	{
		for (var matchid = 0; matchid < matches.length; matchid++)
		{
			var code = matches[matchid].substring(1,3);
			if (parseInt(code, 16) >= 128)
			{
				text = text.replace(matches[matchid], '%u00' + code);
			}
		}
	}

	text = text.replace('%25', '%u0025');
	return text;
}

function do_an_e(eventobj)
{
	if (!eventobj || is_ie)
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}

function set_cookie(name, value, expires)
{
	document.cookie = name + '=' + escape(value) + '; path=/' + (typeof expires != 'undefined' ? '; expires=' + expires.toGMTString() : '');
}

function delete_cookie(name)
{
	document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT' +  '; path=/';
}

function fetch_cookie(name)
{
	cookie_name = name + '=';
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf(';', value_begin);
			if (value_end == -1)
			{
				value_end = cookie_length;
			}

			var cookie_value = unescape(document.cookie.substring(value_begin, value_end));
			return cookie_value;
		}

		cookie_begin = document.cookie.indexOf(' ', cookie_begin) + 1;
		if (cookie_begin == 0)
		{
			break;
		}
	}

	return null;
}

function Rapidshre_AJAX_TABS()
{
	this.ajaxobj = null;

	this.useajaxobj = fetch_object('useajax');
	this.submitobj = fetch_object('rsbutton');
	this.textobj = fetch_object('rslinks');
	this.processobj = null;

	this.editdoc = null;
	this.editwin = null;
	this.editbox = null;

	this.selectedobj = null;

	var _this = this;

	this.init = function()
	{
		var alinks = fetch_tags(fetch_object('taboptions'), 'a');
		for (var i = 0; i <= alinks.length; i++)
		{
			if (!alinks[i] || typeof alinks[i].rel == 'undefined')
			{
				break;
			}

			if (alinks[i].className == 'selected')
			{
				this.selectedobj = alinks[i];
			}

			alinks[i].onclick = this.linkclick;
		}

		this.useajaxobj.onclick = function()
		{
			var expires = new Date();
			expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 365)); // 1 Yıl

			set_cookie('useajax', (this.checked ? 1 : 0), expires);
		};

		if (fetch_cookie('useajax') == 1 && !this.useajaxobj.checked)
		{
			this.useajaxobj.checked = true;	 // Sadece Önlem.
		}

		this.submitobj.onclick = this.fetch_links;

		this.init_wysiwyg();
	};

	this.fetch_data = function(fragment, obj)
	{
		this.processobj = obj;
		fetch_object('imgprogress').style.display = '';

		this.ajaxobj = new AtLantis_Ajax_Handler(true, true);
		this.ajaxobj.onreadystatechange(this.ajax_request);
		this.ajaxobj.add_data('do', 'tab');
		this.ajaxobj.add_data('tab', fragment);
		this.ajaxobj.add_data('ajax', 1);

		this.ajaxobj.send('index.php?do=getprocess', true);
		return false;
	}

	this.linkclick = function(e)
	{
		// Linkteki Yönlendirme işlemini durduruyoruz.
		// Eğer Tarayıcının JavaScript Desteği Yoksa ya da Kapalıysa Bu işlem hiç başlamayacak
		// ve de Tab Normal İşlemini Görecektir.
		do_an_e(e);

		// Üzerine tıklanan nesne zaten seçili ise ikinci bir defa çalıştırmanın anlamı yok.
		if (_this.selectedobj == this)
		{
			return false;
		}

		_this.fetch_data(this.rel, this);
	};

	this.fetch_links = function(e)
	{
		do_an_e(e); // Butonun işlevini durduruyoruz.

		// AJAX destekli Tarayıcıya Sahip Değilsek ya da Kullanıcı AJAX Kullanmak istemiyorsa?
		if (!_this.useajaxobj.checked || !AJAX_Compatible)
		{
			if (_this.selectedobj.rel == 'shortlinks')
			{
				_this.submitform();
			}

			document.forms[0].submit(); // Form Submit :)
			return false;
		}

		if (_this.selectedobj.rel == 'shortlinks')
		{
			_this.submitform();
		}

		if (!_this.textobj.value) // Link yok :)
		{
			alert('Lütfen Önce Linkleri Girin');
			if (_this.selectedobj.rel != 'shortlinks')
			{
				_this.textobj.focus();
			}
			else
			{
				// _this.editdoc.focus();
			}

			return false;
		}

		var urlprefs = _this.selectedobj.rel;
		switch (urlprefs)
		{
			case 'rapidsafe':
				urlprefs += '.net';
				break;
			case 'rsprotect':
				urlprefs += '.com';
				break;
			case 'lix':
				urlprefs += '.in';
				break;
			case 'stealth':
				urlprefs += '.to';
				break;
		}

		if (_this.selectedobj.rel != 'shortlinks')
		{
			if (window.RegExp) // Linklerin Doğrulayalım
			{
				var re = new RegExp("http://(www\.)?" + urlprefs.replace('.', '\.') + "/(.*)", "gi");
				var textobj = _this.textobj.value.split(/([\n\r\s])/);
				for (var i in textobj)
				{
					if (!textobj[i].match(re))
					{
						alert('Bu Link Bölümüne Yalnızca ' + urlprefs + ' Linklerini Koyabilirsiniz');
						return false;
					}
				}
			}
			else
			{
				var textobj = _this.textobj.value.split(/([\n\r\s])/);
				for (var i in textobj)
				{
					if (stripos(textobj[i], "http://" + urlprefs) !== false || stripos(textobj[i], "http://www." + urlprefs) !== false)
					{
						// hiç birşey:p
					}
					else
					{
						alert('Bu Link Bölümüne Yalnızca ' + (shortrs ? 'Kısaltılmış' : urlprefs) + ' Linklerini Koyabilirsiniz');
						return false;
					}
				}
			}
		}

		fetch_object('imgprogress').style.display = '';

		// ve işte AJAX Başlıyor!..
		_this.ajaxobj = new AtLantis_Ajax_Handler(true, true); // 1. Parametre Async Tipi Bağlantı, 2. Parametre Post tipi Sorgu

		_this.ajaxobj.onreadystatechange(_this.ajax_links);
		_this.ajaxobj.add_data('do', 'getprocess');
		_this.ajaxobj.add_data('process', _this.selectedobj.rel);
		_this.ajaxobj.add_data('rslinks', _this.textobj.value);
		_this.ajaxobj.add_data('ajax', 1);

		_this.ajaxobj.send('index.php?do=getprocess', true); // 2. parametre No Cache

		return false; // Ah Opera ah :) Bir Kere de Problem çıkarmasan :)
	};

	this.ajax_request = function()
	{
		if (_this.ajaxobj.handler.readyState == 4 && _this.ajaxobj.handler.status == 200 && _this.ajaxobj.handler.responseXML)
		{
			var error = _this.ajaxobj.fetch_data(fetch_tags(_this.ajaxobj.handler.responseXML, 'error')[0]);
			if (error)
			{
				alert(error);
				fetch_object('imgprogress').style.display = 'none'; 
				return false;
			}

			var tagvalue = _this.ajaxobj.fetch_data(fetch_tags(_this.ajaxobj.handler.responseXML, 'tagvalue')[0]);
			if (!tagvalue)
			{
				alert('AJAX ile Bilgiler Alınamadı');
				fetch_object('imgprogress').style.display = 'none'; 
				return false;
			}

			if (_this.selectedobj)
			{
				_this.selectedobj.className = '';
			}

			_this.processobj.className = 'selected';
			_this.selectedobj = _this.processobj;

			var expires = new Date();
			expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 365)); // 1 Yıl

			set_cookie('tabselected', _this.selectedobj.rel, expires);

			fetch_object('tabcontent').innerHTML = tagvalue;
			fetch_object('imgprogress').style.display = 'none';

			_this.submitobj = fetch_object('rsbutton');
			_this.submitobj.onclick = _this.fetch_links;
			_this.textobj = fetch_object('rslinks');
			if (is_ie7 && _this.selectedobj.rel != 'shortlinks')
			{
				_this.textobj.focus();
			}

			if (_this.selectedobj.rel == 'shortlinks')
			{
				_this.init_wysiwyg();
			}

			return false;
		}
	};

	this.ajax_links = function()
	{
		if (_this.ajaxobj.handler.readyState == 4 && _this.ajaxobj.handler.status == 200 && _this.ajaxobj.handler.responseXML)
		{
			var error = _this.ajaxobj.fetch_data(fetch_tags(_this.ajaxobj.handler.responseXML, 'error')[0]);
			if (error)
			{
				alert(error);
				fetch_object('imgprogress').style.display = 'none'; 
				return false;
			}

			var divobj = document.createElement('div');
			var divinner = '<div style="margin-top: 10px; border-bottom: 1px dashed purple; padding: 5px">Linkler:</div>';
			var links = fetch_tags(_this.ajaxobj.handler.responseXML, 'result');
			for (var i = 0; i <= links.length; i++)
			{
				if (!links[i]) { break; }
				var link = _this.ajaxobj.fetch_data(links[i]);
				divinner += '<div style="margin-top: 2px; padding: 2px"><a href="' + link + '" target="_blank">' + link + '</a></div>\n';
			}

			var unused = fetch_tags(_this.ajaxobj.handler.responseXML, 'unused');
			if (unused.length > 0)
			{
				divinner += '<div style="margin-top: 10px; border-bottom: 1px dashed purple; padding: 5px">Aşağıdaki Linkler Muhtemelen Başka Bir Gruba Ait:</div>';
				for (var i = 0; i <= unused.length; i++)
				{
					if (!links[i]) { break; }
					divinner += '<div style="margin-top: 2px; padding: 2px">' + _this.ajaxobj.fetch_data(unused[i]) + '</div>\n';
				}
			}

			var shortlink = fetch_tags(_this.ajaxobj.handler.responseXML, 'shortlink');
			if (shortlink.length > 0)
			{
				divinner += '<div style="margin-top: 10px; border-bottom: 1px dashed purple; padding: 5px">Aşağıdaki Linkler Muhtemelen Kırık:</div>';
				for (var i = 0; i <= shortlink.length; i++)
				{
					if (!links[i]) { break; }
					divinner += '<div style="margin-top: 2px; padding: 2px">' + _this.ajaxobj.fetch_data(shortlink[i]) + '</div>\n';
				}
			}

			fetch_object('resultinner').innerHTML = divinner;
			fetch_object('imgprogress').style.display = 'none';

			return false;
		}
	};

	this.write_editor_contents = function(text, doinit)
	{
		if (text == '')
		{
			if (is_ie)
			{
				text = '<p></p>';
			}
			else if (is_moz)
			{
				text = '<br />';
			}
		}
		if (this.editdoc && this.editdoc.initialized)
		{
			this.editdoc.body.innerHTML = text;
		}
		else
		{
			if (doinit && typeof Array.prototype.map == 'undefined') { this.editdoc.designMode = 'on'; }
			this.editdoc = this.editwin.document;
			this.editdoc.open('text/html', 'replace');
			this.editdoc.write(text);
			this.editdoc.close();
			if (doinit)
			{
				this.editdoc.body.contentEditable = true;
				if (typeof Array.prototype.map != 'undefined')
				{
					this.editdoc.designMode = 'on';
				}
			}

			this.editdoc.initialized = true;
		}

	};

	this.init_wysiwyg = function()
	{
		this.editbox = fetch_object('rsiframe');
		if (this.editbox)
		{
			this.editwin = this.editbox.contentWindow;
			this.editdoc = this.editwin.document;

			this.write_editor_contents('', true);

			this.editdoc.createStyleSheet().cssText = 'body { margin: 0px; padding: 0px; font: 11px Verdana; }';
		}
	};

	this.submitform = function()
	{
		this.textobj.value = this.editdoc.body.innerHTML;
		return true;
	};
}

var tabobj = { 'submitform' : function(){ alert('Lütfen Sayfanın Yüklenmesini Bekleyin'); return false; } };