var div = '#inject';
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);

/* show popup window */
function popUp(abc)
{
	window.open(abc,'Win1','toolbar=0,location=0,directories=0,status=0,scrollbars=1,menubar=0,copyhistory=0,width='+popUpWidth+',height='+popUpHeight+',left='+leftPos+',top='+topPos);
}
/* show popup window */

// timeout is in miliseconds
$.ajaxSetup({
	type:'POST',
	timeout:60000,
	dataType:'html',
	error: function(xhr) {
			$(div).html("Error:"+xhr.status+' '+xhr.statusText);
	}
});

function showPage(URL){
	$.ajax({
		url:URL,
		/*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');
}

$("#loader").ajaxStart(function(){
	$(this).modal({
		overlayId:'loader-overlay',
		containerId:'loader-container',
		escClose: false		
	});
	}).ajaxComplete(function(){
		$.modal.close();
});

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 fileUpload(URL) {
	$.ajaxFileUpload ({
		url:URL,
		secureuri:false,
		fileElementId:'file1',
		dataType: 'json',
		success: function(data) {
			document.getElementById('thumbs').src="../../system/var/usr/img/thumbs/"+data.filename;
			document.frmApps1.thumbsName.value=data.filename;
			document.frmApps2.file1.value='';
		},
		error: function (data, status, e) {
			alert (data+'\n'+status+'\n'+e);
		}
	})
	return false;
}

function portoUpload(URL,profilId) {
	$.ajaxFileUpload ({
		url:URL,
		secureuri:false,
		fileElementId:'file1',
		dataType: 'json',
		success: function(data) {
			var src = "../../system/var/usr/img/portofolio/thumbs/"+data.filename;
			$.post('savePortofolio',{field1:profilId,field2:data.filename,field3:data.uploadDate},function(hasil){
				document.frmApps1.counter.value=parseInt(document.frmApps1.counter.value)+1;
				var index = document.frmApps1.counter.value;

				//<li><table><tr><td><input type="checkbox" name="chk<?=$i?>" id="chk<?=$i?>" class="chk" value="<?=$row->id?>" onclick="activate()" /><img name="thumbs" src="<?=base_url()."system/var/usr/img/portofolio/thumbs/".$row->thumbnail?>" onmouseover="TagToTip('info<?=$i?>')" onmouseout="UnTip()" /></td></tr></table><span id="info<?=$i?>" style="visibility:hidden;display:none"><table><tr><td>Upload Date:&nbsp;</td><td><?=date('j F Y',strtotime($row->upload_date))?></td></tr><tr><td>Upload Time:&nbsp;</td><td><?=date('H:i:s',strtotime($row->upload_date))?></td></tr></table></span></li>
				
				$('#gallery').append('<tr><td><input type="checkbox" name="chk'+index+'" id="chk'+index+'" class="chk" value="'+hasil.id+'" onclick="activate()" /></td><td><span onclick="popUp(\'viewImage/'+hasil.id+'\');"><img name="thumbs" src="'+src+'" onmouseover="TagToTip(\'info'+index+'\')" onmouseout="UnTip()" style="cursor:pointer" /></span></td><td><span id="info'+index+'" style="visibility:hidden;display:none"><table><tr><td>Upload Date:&nbsp;</td><td>'+hasil.dateUpload+'</td></tr><tr><td>Upload Time:&nbsp;</td><td>'+hasil.timeUpload+'</td></tr></table></td></tr>');
			},'json');
			document.frmApps1.file1.value='';
			document.frmApps2.btSelect.disabled=false;
		},
		error: function (data, status, e) {
			$("#error").html('<b><i>'+e+'</i></b>');
			$("#error").fadeOut(3000);
		}
	})
	return false;
}

/* don't do it!!! */
shortcut.add("Ctrl+1",function() {
	$('#showme').modal({
		overlayId:'showme-overlay',
		containerId:'showme-container',
		escClose: false
	});
});
/* don't do it!!! */