var ie = navigator.appName.indexOf("Microsoft") >= 0;
var gecko = navigator.userAgent.indexOf("Gecko") >= 0;


function popup(url) {
   window.open(url, "", "width=400,height=400" + ((url.indexOf(".php") > 0 || url.indexOf(".html") > 0) ? ",scrollbars=yes" : ""));

   return false;
}

function popupLink(url, title) {
   return "<a target=_blank href='" + url + "' onclick=\"return popup('" + url + "');\">" + title + "</a>";
}

function end(cabanner) {

	if(cabanner){
		document.write("<div style='padding-right: 40px;'><div id=\"cabanner\">cabanner</div><div style='clear:both'></div></div>");

		var request = false;
		try {
		request = new XMLHttpRequest();
		} catch (trymicrosoft) {
			try {
				request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (othermicrosoft) {
				try {
					request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					request = false;
				}
			}
		}
		if (!request)
		alert("Error initializing XMLHttpRequest!");
		var url = window.location.protocol+"//"+window.location.hostname+"/ca_banner.html";

		request.open("GET", url, false);
		request.send(null);
		if (request.readyState == 4) {
			if (request.status == 200) {
				document.getElementById("cabanner").innerHTML = request.responseText;
			}
		}

	}
}


document.write(""
+ "<style type='text/css'>"
+  "<!--"
//+   "html, body {margin: 0px auto 10px auto; background-color: white; color: black}"
+   "body {margin: 8px 0px 10px 0px; background-color: white; color: black}"
+   "a.index:link {color: #3366cc}"
+   "a.index:visited {color: #609}"
+   "a {color: #3366cc}"
+   "a.ad {color: black; text-decoration: none}"
+   "a.ad:hover {color: #3366cc; text-decoration: underline}"
+   "a.visitedAd {color: #3366cc; text-decoration: none}"
+   "a.visitedAd:hover {color: #3366cc; text-decoration: underline}"
+   "a.comment {color: black; text-decoration: none}"
+   "body, p, table {font: 12px arial, helvetica, sans-serif; line-height: 17px}"
+   ".contents {width: 750px}"
+   ".notice {padding: 7px; background-color: #ffffcc; color: #cc0000}"
+   ".small {font-size: 11px}"
+   ".menu {font: 13px verdana, helvetica, sans-serif}"
+   ".banner {font-style: italic; font-weight: bold; color: gray}"
+   ".warning {font-style: italic; font-weight: bold; background-color: red; color: white}"
+   ".even {background-color: #fff; border-bottom: 1px solid #bbb;}"
+   ".even td.common {border-bottom: 1px solid #bbb;}"
+   ".even th.common {border-bottom: 1px solid #bbb; border-top: 1px solid #bbb;}"
+   ".myeven {border: 0;}"
+   ".odd {background-color: #fff; border-bottom: 1px solid #bbb;}"
+   ".odd td.common {border-bottom: 1px solid #bbb;}"
+   ".myodd {border: 0;}"
+   ".header {font-weight: bold; font-size: 16px; color: black;}"
+   ".popular {background-color: #ffccff; border-bottom: 1px solid #bbb;}"
+   ".popular td.common {background-color: #ffccff; border-bottom: 1px solid #bbb;}"
+   ".mypopular {background-color: #ffccff;}"
+   ".popular-bold {font-weight: bold; background-color: #ffccff; border-bottom: 1px solid #bbb;}"
+   ".popular-bold td.common {font-weight: bold; background-color: #ffccff; border-bottom: 1px solid #bbb;}"
+   ".mypopular-bold {font-weight: bold; background-color: #ffccff;}"
+   ".disabled {background-color: red; color: white; text-decoration: line-through; border-bottom: 1px solid #bbb;}"
+   ".mydisabled {background-color: red; color: white;}"
+ (
     ie || gecko
        ? ""
        : "input {font: 13px courier new, courier}"
  )
+  "-->"
+ "</style>"
+ "<style type='text/css' media='print'>"
+  "<!--"
+   "a {color: black}"
+   ".contents {width: 100%}"
+   ".not-printable {display: none}"
+  "-->"
+ "</style>"
);



function TransPopup(link){
	window.open(link,'mywindow','width=400,height=600');
}

function refresh() {
	window.location.reload(true);
}
function getValue(id) {
	var value = document.getElementById(id).value;
	return value;
}
function setValue(id, new_value) {
	document.getElementById(id).value = new_value;
}
function setValueHTML(id, new_value) {
	if(document.getElementById(id) != null){
		document.getElementById(id).innerHTML = new_value;
	}
}

function setPrice() {
	var credit = getValue('credit');
	var current_level = getValue('current_level');
	var more_days = getValue('more_days');
	var level = getValue('level');
	var days = getValue('days');
	var img_src = '<img src="/images/skelbiu_star.png" alt="star" />';
	var img_html = '';

	for (i=1;i<=level;i++) {
		img_html += img_src;
	}

	var price = ((level-current_level)*level_price*more_days)+(level_price * level * days);
	var missing = (price*100 - credit)/100;
	if (missing - Math.round(missing) == 0) {
		missing = missing+'.00';
	}
	if (price > (credit/100)) {
		setValueHTML('price','<span style="color:red;">'+price+'.00 '+currency+'</span>');
		if(document.getElementById('submit') != null){
			document.getElementById('submit').disabled = 'disabled';
		}
		document.getElementById('add_credit').style.display = 'block';
		if(site!="HYDRA")setValueHTML('missing', '(Jūsų sąskaitoje trūksta '+missing+' '+currency+')');
		else setValueHTML('missing', '(Puudu '+missing+' '+currency+')');
	} else {
		setValueHTML('price',price+'.00 '+currency);
		if(document.getElementById('submit') != null){
			document.getElementById('submit').disabled = '';
		}
		document.getElementById('add_credit').style.display = 'none';
		setValueHTML('missing', '');
	}
	setValueHTML('stars', img_html);
}

function setPrice2() {
    
	var level = getValue('level');
	var days = getValue('days');
	var highlightDays = getValue('highlightDays');

	var img_src = '<img src="/images/skelbiu_star.png" alt="star" />';
	var img_html = '';

	for (i=1;i<=level;i++) {
		img_html += img_src;
	}

	var levelPrice = level_price * level * days;
	var highlightPrice = bold_price * highlightDays;

		setValueHTML('levelPrice',levelPrice+'.00 '+currency);
		setValueHTML('highlightPrice',highlightPrice+'.00 '+currency);
		setValueHTML('additional',levelPrice+highlightPrice+'.00 '+currency);
		setValueHTML('total',levelPrice+highlightPrice+base_price_add_fee+'.00 '+currency);
		setValue('totalPrice',levelPrice+highlightPrice+base_price_add_fee);
	setValueHTML('stars', img_html);
}

function gotoBank () {
    if(site == "SKELBIU"){
        var bankID = document.getElementsByName("bank")[0].value;
        var banks = new Array ("vb2", "hanza", "nord", "snoras", "nordealt", "ukio", "sampo", "sb", "parex");
        var money = document.getElementById("add").value;
        
        if (money == "") {
           alert ("Įveskite sumą kuria norite papilditi savo sąskaitą");
           return;
        }

        if (money < 10) {
           alert ("Jūsų nurodita suma yra per maža. Minimali suma yra 10 Lt");
           return;
        }

        if (bankID == "") {
            alert ("Pasirinkite banką");
            return;
        }
        
        if (typeof(OrderId) != 'undefined') {
            document.getElementsByName("OrderID")[0].value = OrderId;
        }
        
        if (document.getElementsByName('highlighting')[0]) {
            document.getElementsByName("hDays")[0].value = document.getElementsByName('highlighting')[0].value;
        }
        
        document.getElementsByName("Amount")[0].value = money * 100;
        document.getElementsByName("Payment")[0].value = banks[bankID];
        document.getElementById("pay").submit();
    }else{
        var est_bankID = document.getElementsByName("bank")[0].value;
        var est_banks  = new Array ("/test.php", "test.php?seb");
        document.getElementById("action").value = est_banks[est_bankID];
        document.getElementById("pay").submit();
    }
}

function change_forum_cat(){
	document.cat_search.submit();
}

function add_forum_image(topic) {
	window.open("/forum.php?upload&t="+topic, "Upload_image", "top=400,left=300,location=0,menubar=0,resizable=0,width=350,height=150");
}
function quote(id){
	var poster = document.getElementById('p'+id) ? '[quote][by]'+document.getElementById('p'+id).innerHTML+'[/by]' : '[quote][by]'+document.getElementById('p'+id+'t').innerHTML+'[/by]';
	var text = document.getElementById(id) ? document.getElementById(id).innerHTML+'[/quote]<br />' : document.getElementById(id+'t').innerHTML+'[/quote]<br />';
	var oEditor = FCKeditorAPI.GetInstance('reply[content]');
	oEditor.SetHTML(poster+text);
}

function func_one(hash, adID){
	new Ajax.Request('submit.php?act=acclevel&adID=' + adID + '&hash=' + hash , {
		method: 'post',
		onSuccess: function (transport) { change_lev_ac_text (transport.responseXML) }
	});
}
function change_lev_ac_text(text){
	var place = document.getElementById('level_acc');
	place.style.display = '';
}

function OpenWindow(url, dims, align, window_name, windowFeatures) { // {{{
    // constants (almost) {{{

    var margin = 20; // margin from all edges except bottom
    var margin_bottom = 50; // margin from bottom (taskbar)

    // }}}

    // parse and init parameters {{{

    // parse dimensions

    // regexp for parsing dimensions
    var re_dims = new RegExp('^([0-9]+|max)\\*([0-9]+|max)$');
    var tmp_dims = re_dims.exec(dims);
    if (!tmp_dims) {
        throw('OpenWindow: Invalid dimensions value: \''+dims+'\'');
        return undefined;
    }
    // windows specified width and height
    var width = tmp_dims[1];
    var height = tmp_dims[2];

    // parse alignment

    // if empty, make string
    if (!align) align = '';

    var re_align_x = new RegExp('^(left|center|right)$');
    var re_align_y = new RegExp('^(top|middle|bottom)$');

    // find word(s), separated by space
    var re_align = new RegExp('^([a-z]+)?(?:\\s+([a-z]+))?$');
    var tmp_align = re_align.exec(align);
    var align_x = 'center';
    var align_y = 'middle';

    if (re_align_x.exec(tmp_align[1])) { // if first word is align_x
        align_x = tmp_align[1];
    } else if (re_align_y.exec(tmp_align[1])) { // if align_y
        align_y = tmp_align[1];
    } else {
        throw('Invalid align value: \''+tmp_align[1]+'\'');
        return undefined;
    }

    if (re_align_x.exec(tmp_align[2])) { // if second word is align_x
        align_x = tmp_align[2];
    } else if (re_align_y.exec(tmp_align[2])) { // if align_y
        align_y = tmp_align[2];
    } else {
        throw('Invalid align value: \''+tmp_align[2]+'\'');
        return undefined;
    }

    if (!window_name) window_name = '_blank';

    // }}}

    // determine window dimensions and coordinates {{{

    // determine width and height

    var max_width = screen.availWidth - 2*margin;
    var max_height = screen.availHeight - (margin + margin_bottom);

    if (width == 'max') { // width is set to 'max'
        width = max_width;
    } else { // width is set numerically
        width = Math.min(width, max_width);
    }
    if (height == 'max') { // height is set to 'max'
        height = max_height;
    } else { // height is set numerically
        height = Math.min(height, max_height);
    }

    // determine x and y according alignment

    switch (align_x) {
        case 'left':
            var x = margin;
        break;
        case 'center':
            var x = Math.round((max_width - width)/2 + margin, 0);
        break;
        case 'right':
            var x = max_width - width + margin;
        break;
    }

    switch (align_y) {
        case 'top':
            var y = margin;
        break;
        case 'middle':
            var y = Math.round((max_height - height)/2 + margin, 0);
        break;
        case 'bottom':
            var y = max_height - height + margin;
        break;
    }

    // }}}


    // display window {{{

    // window properties
    var props = // main shit
        'width='+width
        +',outerWidth='+width
        +',height='+height
        +',outerHeight='+height
        +',top='+y
        +',screenY='+y
        +',left='+x
        +',screenX='+x;
    var props2 = // other nänn
    	'toolbar=no'
        +'directories=0'
        +',location=no'
        +',menubar=0'
        +',resizable=no'
        +',scrollbars=yes'
        +',status=no';
    var win = window.open(url, window_name, props + ',' + props2);

    win.focus();

    // }}}

    return win;
} // }}}

function addLoadEvent( func ){
    var oldonload = window.onload;
    if( typeof window.onload != 'function' ){
        window.onload = func;
    }else{
        window.onload = function( ){
            if( oldonload){
                oldonload( );
            }
            func();
        }
    }
}

function showEmailForm(){
    var form = document.getElementById("emailform");

    if(form.style.display == "block"){
        form.style.display = "none";
    }else{
        form.style.display = "block";
    }
    
}

function checkEmailForm(){
    var email = document.getElementById("email_field");
    var text = document.getElementById("text_field");
    var captcha = document.getElementById("captcha");
    var captcha2 = document.getElementById("captcha2");
    var error = false;
    
    if(validate("email_Form","email_field") == false){
        email.style.border = "2px solid red";
        error = true;
    }else{
        email.style.border = "1px solid rgb(173,174,173)";
    }
    if(text.value == ""){
        text.style.border = "2px solid red";
        error = true;
    }else{
        text.style.border = "1px solid rgb(173,174,173)";
    }
    if(strtolower(captcha.value) != strtolower(captcha2.value)){
        captcha.style.border = "2px solid red";
        error = true;
    }else{
        captcha.style.border = "1px solid rgb(173,174,173)";
    }
    if(error == false){
        return true;
    }else{
        alert(email_error_msg);
        return false;
    }
}

function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      return false;
   }
   return true;
}

function strtolower( str ) {
    return (str+'').toLowerCase();
}

function filteroptions(value){

	if(value==2 || value==3 || value==0){
		document.getElementById('Interestedchanging').style.display = 'none';
		document.getElementById('IntchangingEl').checked = false;
	}else{
		document.getElementById('Interestedchanging').style.display = 'block';
	}
}
