if (top != self) { top.location = self.location; }

$(document).ready(function(){
	$("#container").corner("7px");
	$("ul.buttons_nav a").corner("5px");
	$("#header,#footer").corner("5px");
	$("#upload_form").corner("5px");
	if($("#download_url").length>0)
		$("#download_url").attr('value',location.href);
});

function moreUploadFields() {
	for(i=2;i<6;i++)
		document.getElementById('file_upload_tr_'+i).style.display='';
}

function ShowProgress(PID) {
	var file = document.getElementById('file_upload');
	if(file.value=="")
		file = document.getElementById('file_upload_ff');
	if (file.value != "") {
		if (navigator.appName=="Microsoft Internet Explorer") {
			var winstyle = "dialogWidth=385px; dialogHeight:140px; center:yes";
			window.showModelessDialog('framebar.asp?to=10&'+PID+'&b=IE',null,winstyle);
		}
		else {
			window.open('framebar.asp?to=10&'+PID+'&b=NN','','width=370,height=115', true);
		}
	}
	return true;
}


function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else if(window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else
		alert('התרחשה שגיאה');
}

var xmlhttp = getXmlHttpRequestObject();

//		קוד אבטחה
var code_xmlhttp;
function checkSecurityCode() {
	if(document.getElementById('file_scode').value=="") {
		alert('חובה להזין קוד אבטחה');
		return false;
	}
	document.getElementById('wrong_code').style.display = 'none';
	document.getElementById('download_button').value = "מבצע אימות קוד אבטחה...";
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			code_xmlhttp = new XMLHttpRequest();
        } catch(e) {
			code_xmlhttp = false;
        }
    } else if(window.ActiveXObject) {
       	try {
        	code_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		code_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		code_xmlhttp = false;
        	}
		}
    }
	if(code_xmlhttp == null)
		return false;
	var file_id = document.getElementById('file_id').value;
	var code = document.getElementById('file_scode').value;
	code_xmlhttp.open('get', "http://www.JustFile.net/check_code.asp?file_id="+file_id+"&code="+code, true);
	code_xmlhttp.onreadystatechange = codeCheck;
	code_xmlhttp.send(null);
}

function codeCheck() {
	document.getElementById('download_button').value = "הורדת קובץ";
	if(code_xmlhttp.readyState == 4 && code_xmlhttp.status == 200) {
		if(code_xmlhttp.responseText=="0")
			document.getElementById('wrong_code').style.display = '';
		else if(code_xmlhttp.responseText=="2")
			location.href = location.href;
		else {
			document.getElementById('wrong_code').style.display = 'none';
			location.href = location.href;
		}
	}
}
//		END קוד אבטחה

function uploadFile(pid,time) {
	$('#uploadFile').submit();
	updateProgress(pid,time);
}

function updateProgress(id,time) {

	$.get("/bar.asp", { pid: id, to: time } ,function(data) {
		$('#uploadFile').css('display','none');
		$('#progressBar').html('<img src="/images/upload_wait.png" style="float:left;margin:0px 0 0 65px;"/>'+data);
	});
}

function copyData(id) {
	$.clipboardReady(function(){
		$.clipboard($('#'+id).val());
		return false;
	});
	return false;
}

function hideCopyIcon(id) {
	if(navigator.userAgent.toLowerCase().indexOf('msie')==-1) {
		$('#'+id).css('display','none');
	}
}

function downloadButton() {
	$('#download_button_data').html("מתחיל בהורדה...");
}

function doLogin() {
	var user_user = $('#user_user').val();
	var user_pass = $('#user_pass').val();
	var user_code = $('#user_code').val();
	var user_rcode = $('#user_rcode').val();
	$('#rlogin').html('מבצע התחברות...');
	$.post('/plogin.asp', {user:user_user, pass:user_pass, code:user_code, rcode:user_rcode}, function(data) {
		$('#rlogin').html(data);
	});	
}

function logout() {
	$.post('/logout.asp', {url:location.href}, function(data) {
		$('#ruser').html(data);
	});	
}