var popUpWidth = 800;
var popUpHeight = 600;

var leftPos = Math.round(screen.width / 2) - Math.round(popUpWidth / 2);
var topPos =  Math.round(screen.height / 2) - Math.round(popUpHeight / 2);
var div = '#inject';

$(document).ajaxStart(function(){
	$("#popupcont").modal();
}).ajaxComplete(function(){
	$.modal.close();
});

function showPage(site){
	$.ajax({
		url:site,
		/*beforeSend: function(){
			$(div).hide('fast');	
		},*/
		success: function(response){
			//$(div).show('fast');
			$(div).html(response);
  		}
	});
}

function setActiveTab()
{
	$('#satu').addClass('active');
	$('#dua').removeClass('active');
	$('#tiga').removeClass('active');
}

function popup(url)
{
	window.open(url,'Win1','toolbar=0,location=0,directories=0,status=0,scrollbars=1,menubar=0,copyhistory=0,width='+popUpWidth+',height='+popUpHeight+',left='+leftPos+',top='+topPos);
}

function newCaptcha(URI,elm)
{
	var element = document.getElementById(elm);
	$.post(URI,{},function(data){
		$(element).html(data);
	});
}

function ajaxLoader(show)
{
	if (show=='show'){
		$('#loader2').modal({
			overlayId:'loader2-overlay',
			containerId:'loader2-container',
			escClose: false
		});
	}
}

function postFunct(URL)
{
	var val = new Array();
	var i=1;
	var index=7;
	val[0] = document.frmApps1.txtMail.value;
	val[1] = document.frmApps1.txtPass1.value;
	val[2] = document.frmApps1.txtName.value;

	if (document.frmApps1.chk1.checked==true) val[3] = document.frmApps1.chk1.value; else val[3]='';
	if (document.frmApps1.chk2.checked==true) val[4] = document.frmApps1.chk2.value; else val[4]='';
	if (document.frmApps1.chk3.checked==true) val[5] = document.frmApps1.chk3.value; else val[5]='';
	if (document.frmApps1.chk4.checked==true) val[6] = document.frmApps1.chk4.value; else val[6]='';

	while (i<=document.frmApps1.counter.value){
		try {
			if ($('#txtOther'+i).val()!="other job" || $('#txtOther'+i).val()!=null)
			{
				val[index] = $('#txtOther'+i).val();
			}			
			i++;
			index++;		
		}
		catch (err) {
			break;
		}
	}
	
	val[index] = document.frmApps1.txtDesc.value;

	$.post(URL,{'fld[]':val},function (data) {
		switch (data)
		{
			case '1':
				$('#errPanel1').html('wrong mail format!!!');
				break;
			case '2':
				$('#errPanel2').html('password didn\'t match!!!');
				break;
		}
	});
}

function modalPopup(elm)
{
	//var box = document.getElementById(elm);
	$(elm).modal({
		//overlayId:'simplemodal-overlay',
		containerId:'simplemodal-container',
		escClose: false
	});
}

function initVideo()
{
	$f("player", "player/flowplayer-3.2.4.swf",{
		clip: {
			autoPlay: false,
			autoBuffering: true
		},

		plugins: {
			controls: "player/flowplayer.controls-3.2.0.swf"
		}	
	});
}

function anchorPopup(url,width,height)
{
	var leftPos = Math.round(screen.width / 2) - Math.round(width / 2);
	var topPos =  Math.round(screen.height / 2) - Math.round(height / 2);
	window.open(url,'Win1','toolbar=0,location=0,directories=0,status=0,scrollbars=1,menubar=0,copyhistory=0,width='+width+',height='+height+',left='+leftPos+',top='+topPos);
}

function fileUpload(URL) {
	$.ajaxFileUpload ({
		url:URL,
		secureuri:false,
		fileElementId:'file1',
		dataType: 'json',
		success: function(data) {
			if (data.error!='')	{
				alert ('maximal width is 300 pixel & maximal file size is 150KB');
				return false;
			}

			/*if (document.getElementById('counter').value==document.getElementById('MAX_UPLOAD').value){
				alert('max upload');
				return false;
			}*/

			if (document.getElementById('counter').value==null || document.getElementById('counter').value==''){
				document.getElementById('counter').value = '1';
				var hiddenName = 'img1';
				var hiddenName2 = 'iimg1';
				var target = 'document.frApps.img1.value';

				var elm = '<td id="tdimg1" style="padding:3px 3px 3px 3px"><table><tr><td><img src="'+data.relativePath+'"/><input type="hidden" name="'+hiddenName+'" value="'+data.theFile+'"/><input type="hidden" name="'+hiddenName2+'" value="'+data.theFile2+'"/></td></tr><tr><td align="center"><input type="button" value="delete" onclick="javascript: if (confirm(\'are you sure\')==true) { ajaxDelete('+target+');removeElement(\'tdimg1\'); }"/></td></tr></table></td>';

				$('#imgcontainer').append(elm);
			} else {
				var oldval = document.getElementById('counter').value;
				var newval = parseInt(oldval)+1;
				document.getElementById('counter').value = newval;
				var hiddenName = 'img'+newval;
				var hiddenName2 = 'iimg'+newval;

				var elmName = 'tdimg'+newval;
				var target = 'document.frApps.img'+newval+'.value';

				var elm = '<td id="'+elmName+'" style="padding:3px 3px 3px 3px"><table><tr><td><img src="'+data.relativePath+'"/><input type="hidden" name="'+hiddenName+'" value="'+data.theFile+'"/><input type="hidden" name="'+hiddenName2+'" value="'+data.theFile2+'"/></td></tr><tr><td align="center"><input type="button" value="delete" onclick="javascript:if (confirm(\'are you sure\')==true) { ajaxDelete('+target+');removeElement(\''+elmName+'\'); }"/></td></tr></table></td>';

				$('#imgcontainer').append(elm);
			}

		},
		error: function (data, status, e) {
			alert (data+'\n'+status+'\n'+e);
		}
	})
	return false;
}
