// JavaScript Document

function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}

function toggle_listing(id) {
	var divid = 'div' + id;
	var plusminusid = 'plusminus' + id;
	
	var n = document.getElementById(divid);
	var p = document.getElementById(plusminusid);
		
	if(n.style['height'] == 'auto'){
		setStyleById(divid, 'height', '32px');
		p.innerHTML = "<a href=\"javascript:toggle_listing('" + id + "');\" style=\"text-decoration:none;font-size:10px;color:#666666;\">[+]</a>";
	} else {
		setStyleById(divid, 'height', 'auto');
		p.innerHTML = "<a href=\"javascript:toggle_listing('" + id + "');\" style=\"text-decoration:none;font-size:10px;color:#666666;\">[-]</a>";
	}
}

function toggle_link_rejection_field() {
	var field = document.getElementById('rejection_email');
	
	var val = document.getElementById('approve_action').value;
	
	if (val == "discard+email") {
		try {
			field.style.display = 'block';
		} catch (e) {
		
		}
	} else {
		try {
			field.style.display = 'none';
		} catch (e) {
			field.style.display = '';
		}
	}
}

function popupWin(u,n,o) { // v3
	var ftr = o.split(","); 
	nmv=new Array(); 
	for (i in ftr) {
		x=ftr[i]; 
		t=x.split("=")[0]; 
		v=x.split("=")[1]; 
		nmv[t]=v;
	}
	if (nmv['width']=='100%'){
		nmv['width']=screen.width-10;
		if(nmv['width'] > 912){
			nmv['width'] = 912;
		}
	}
	if (nmv['height']=='100%'){
		nmv['height']=screen.height-65;
		if(nmv['height'] > 768){
			nmv['height'] = 768;
		}
	}
	if (nmv['centered']=='yes' || nmv['centered']==1) {
		nmv['left']=(screen.width-nmv['width'])/2 ; 
		nmv['top']=(screen.height-nmv['height']-72)/2 ; 
		nmv['left'] = (nmv['left']<0)?'0':nmv['left'] ; 
		nmv['top']=(nmv['top']<0)?'0':nmv['top']; 
		delete nmv['centered'];
	} else {
		nmv['left']= 0; 
		nmv['top']= 0; 
		nmv['left'] = 0; 
		nmv['top']= 0; 
	}
	o=""; 
	var j=0; 
	for (i in nmv) {
		o+=i+"="+nmv[i]+"\,";
	} 
	o=o.slice(0,o.length-1);
	window.open(u,n,o);
}

function popupWinForm(form){
    var winName = form.name + "_win";
    window.open("", winName, 'width=600,height=550,scrollbars=yes,toolbar=no,status=no,resize=yes,centered=yes');    
    form.target = winName;
    form.submit();
}

function fieldIsEmpty(fieldobj) {
	if (fieldobj.value == "")
		return true;
	else
		return false;
}