// linFox Domain roxies GLOBAL Javascript file for all included proxies

// SnoopBlocker
function update_cookies() {
	var str = "";
	if (typeof window.top.self.document.cookie != "undefined") {
		var cookies = window.top.self.document.cookie;
		var pos = cookies.indexOf("proxyweb_config=");
		if (pos != -1) {
			var start = pos + 16;
			var end = cookies.indexOf(";", start);
			if (end == -1)
			
			end = cookies.length;
			str = unescape(cookies.substring(start, end));
		}
		else {
			str = "0:0:0:0:0";
		}
		var values = str.split(":");
		if (values.length == 5) {
			values[0] = document.panel.java.checked ? '1' : '0';
			values[1] = document.panel.jscript.checked ? '1' : '0';
			values[2] = document.panel.activex.checked ? '1' : '0';
			values[3] = document.panel.cookies.checked ? '1' : '0';
			values[4] = document.panel.ua.checked ? '1' : '0';
		}
		window.top.self.document.cookie = "proxyweb_config=" + escape(values.join(':'));
	}
}

// --- ProxyWeb | Anonymouse ---
function GoProxy(form) {
	var URL = "";
	URL += form.proxy.value;
	URL += (form.url.value).replace(/ +/g, "+");
	top.location = URL;
//	form.action=URL;
//	form.submit();
	return false;
}
// end --- ProxyWeb | Anonymouse ---

function wwonsubmit() {
	if (document.fmMain == null || document.fmMain.newwindow == null || document.fmMain.url == null || document.fmMain.forcegzip == null || document.fmMain.strip == null || document.fmMain.target == null)
		return true;
	if (msieversion() < 4 && netscapeversion() < 4)
		return true;
	var url = document.fmMain.url.value;
	var p = url.length;
	while (p > 0 && ' \f\n\r\t\v'.indexOf(url.charAt(p-1)) != -1)
		p--;
	url = url.substring(0,p);
	if (url == '')
		return false;
	p = 0;
	while (p < url.length && ((URL.charAt(p) > 'A' && url.charAt(p) < 'Z') || (url.charAt(p) > 'a' && url.charAt(p) < 'z') || (url.charAt(p) > '0' && url.charAt(p) < '9') || url.charAt(p) == '_'))
		p++;
	if (url.substring(p) == "://")
		return false;	
	document.fmMain.target = "_self";
	if (document.fmMain.newwindow.checked) {
		document.fmMain.target = "_blank";
	}
	return true;
}

// --- MEGAPROXY ---
function go() {
	w = screen.availWidth - 10;
	h = screen.availHeight - 20;
	valz = "width=" + w + ",height=" + h;
	valz += ",left=0,top=0,screenX=0,screenY=0";
	valz += ",menubar,copyhistory=0,location=0,status,scrollbars,resizable,toolbar";
	val = "https://vip.megaproxy.com/go/";
	valf = val + "_mp_framed?" + document.mpurlform.mpurl.value;
	var un_nam = "Megaproxy" + (new Date()).getTime();
	window.open(valf, un_nam, valz);
}

function checkRequired(frmData) { 
	var bFail; 
	bFail = false; // Default to pass 
	for (iElement = 0; iElement < frmData.elements.length; iElement++) {
		if (frmData.elements[iElement].className == 'UrlBox' || frmData.elements[iElement].className == 'EmptyUrlBox') {
			if (frmData.elements[iElement].value == '') {
				bFail = true;
				frmData.elements[iElement].className = 'EmptyUrlBox';
			} else {
				frmData.elements[iElement].className = 'UrlBox';
			}
		}
	}
	return !bFail;
}

function checkForm() { 
	if (!checkRequired(document.forms['mpurlform'])) {
		if(document.all) {
			document.all.spanError.innerText = 'Please enter the URL address: ';
		} else {
			document.getElementById('spanError').innerHTML = 'Please enter the URL address: ';
		}
	} else {
		document.forms['mpurlform'].submit();
	}
}
// end --- MEGAPROXY ---

// --- Poxy v0.4 ---
var proxy_url_form_name = 'poxy_url_form';  
var proxy_settings_form_name = 'poxy_settings_form';
var flags_var_name = 'hl';

/* the variables above should match the $config variables in index.php */

var alpha1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var alpha2 = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
var alnum  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._';

function str_rot13(str) {
	var newStr = '';
	var curLet, curLetLoc;
	for (var i = 0; i < str.length; i++) {
		curLet = str.charAt(i);
		curLetLoc = alpha1.indexOf(curLet);
		if (curLet == '#') {
			window.document.getElementById('proxy_form').action += str.substring(i, str.length)
		}
		newStr += (curLetLoc < 0) ? curLet : alpha2.charAt(curLetLoc);
	}
	return newStr;
}

function base64_encode(str) {
	var out = '';
	var t, x, y ,z;
	for (var i = 0; i < str.length; i += 3) {
		t = Math.min(3, str.length - i);
		if (t == 1) {
			x = str.charCodeAt(i);
			out += alnum.charAt((x >> 2));
			out += alnum.charAt(((x & 0x00000003) << 4));
			out += '--';
		}
		else if (t == 2) {
			x = str.charCodeAt(i);
			y = str.charCodeAt(i+1);
			out += alnum.charAt((x >> 2));
			out += alnum.charAt((((x & 0x00000003) << 4) | (y >> 4)));
			out += alnum.charAt(((y & 0x0000000f) << 2));
			out += '-';
		}
		else {
			x = str.charCodeAt(i);
			y = str.charCodeAt(i+1);
			z = str.charCodeAt(i+2);
			out += alnum.charAt((x >> 2));
			out += alnum.charAt((((x & 0x00000003) << 4) | (y >> 4)));
			out += alnum.charAt((((y & 0x0000000f) << 2) | (z >> 6)));
			out += alnum.charAt((z & 0x0000003f));
		}
	}
	return out;
}

function submit_form() {
	var url = document.forms[proxy_settings_form_name].url.value;
	var flags = '';
	var rotate13 = document.forms[proxy_settings_form_name].elements['ops[]'][5].checked
	var base64 = document.forms[proxy_settings_form_name].elements['ops[]'][6].checked;
	for (i = 0; i < document.forms[proxy_settings_form_name].elements['ops[]'].length; i++) {
		flags += (document.forms[proxy_settings_form_name].elements['ops[]'][i].checked == true) ? '1' : '0';
	}
	document.forms[proxy_url_form_name].elements[flags_var_name].value = flags;
	document.forms[proxy_url_form_name].target = (document.forms[proxy_settings_form_name].new_window.checked == true) ? '_blank' : '_top';
	if (rotate13) {
		  url = str_rot13(url);
	}
	else if (base64) {
		url = base64_encode(url);
	}
	document.forms[proxy_url_form_name].url_input.value = url;
	document.forms[proxy_url_form_name].submit();
	return false;
}
// end --- Poxy v0.4 ---

// Main Proxy Groups Form Action Choice
function proxyselect(group) {
	switch (group) {
		case 1:
			if (document.getElementById('g1select').selectedIndex == 0) {
				alert("Please select a proxy");
			}
			else {
				document.group1.action = document.getElementById('g1select')[document.getElementById('g1select').selectedIndex].value;
				document.group1.submit();
			}
			break;
		case 2:
			if (document.getElementById('g2select').selectedIndex == 0) {
				alert("Please select a proxy");
			}
			else {
				document.poxy_url_form.action = document.getElementById('g2select').options[document.getElementById('g2select').selectedIndex].value;
				document.poxy_settings_form.action = document.getElementById('g2select').options[document.getElementById('g2select').selectedIndex].value;
				submit_form();
			}
			break;
		case 3:
			if (document.getElementById('g3select').selectedIndex == 0) {
				alert("Please select a proxy");
			}
			else {
				document.group3.action = document.getElementById('g3select')[document.getElementById('g3select').selectedIndex].value;
				document.group3.submit();
			}
			break;
		case 4:
			if (document.getElementById('g4select').selectedIndex == 0) {
				alert("Please select a proxy");
			}
			else {
				document.group4.action = document.getElementById('g4select')[document.getElementById('g4select').selectedIndex].value;
				document.group4.submit();
			}
			break;
		case 5:
			if (document.getElementById('g5select').selectedIndex == 0) {
				alert("Please select a proxy");
			}
			else {
				document.group5.action = document.getElementById('g5select')[document.getElementById('g5select').selectedIndex].value;
				document.group5.submit();
			}
			break;
	}
}