// JavaScript Document
function init() {
	document.getElementById('radiovalue1').value = 'true';
	document.getElementById('radiovalue2').value = 'false';
	document.getElementById('radiovalue3').value = 'false';
	document.getElementById('radio1').className = 'radio1';
	document.getElementById('radio2').className = 'radio2';
	document.getElementById('radio3').className = 'radio2';
}

function showagain(id, id1) {
	// init();
	// document.theForm.submit();
	// document.getElementById('radiovalue1').value = 'false';
	document.getElementById(id).style.display = 'block';
	document.getElementById('radiovalue1' + id1).value = 'true';
	document.getElementById('radiovalue2' + id1).value = 'false';
	document.getElementById('radiovalue3' + id1).value = 'false';
	document.getElementById('radio1' + id1).className = 'radio1';
	document.getElementById('radio2' + id1).className = 'radio2';
	document.getElementById('radio3' + id1).className = 'radio2';
}

function radiochange(text1, radiovalues) {
	var id = document.getElementById(text1);
	var radval = document.getElementById(radiovalues);
	if (id.className == 'radio1') {
		id.className = 'radio2';
		radval.value = 'false';
	} else if (id.className == 'radio2') {
		id.className = 'radio1';
		radval.value = 'true';
	}
}

function radiochange_rec_mem(text1, radiovalues) {
	var id = document.getElementById(text1);
	var radval = document.getElementById(radiovalues);
	if (id.className == 'greenbut') {
		id.className = 'redbut';
		radval.value = 'false';
	} else if (id.className == 'redbut') {
		id.className = 'greenbut';
		radval.value = 'true';
	}
}
function formsubmit(id) {
	// document.theForm.submit();
	var radval1 = document.getElementById('radiovalue1' + id).value;
	var radval2 = document.getElementById('radiovalue2' + id).value;
	var radval3 = document.getElementById('radiovalue3' + id).value;
	if ((radval1 == 'true') || (radval2 == 'true') || (radval3 == 'true')) {
		this.changetext(id);
	} else
		document.getElementById('test1' + id).style.display = 'none';
}

function ajaxSave(form, actionAfterSave) {
	if (jQuery == undefined)
		form.submit();
	jQuery.post(form.action + "&ajax=true", jQuery(form).serialize(), function(
			data) {
		showSimpleAlert('Network Categories were saved successfully');
		if(actionAfterSave) actionAfterSave();
	});
}

function formsubmit12(id) {
	// document.theForm.submit();
	var radval1 = document.getElementById('radiovalue1' + id).value;
	var radval2 = document.getElementById('radiovalue2' + id).value;
	var radval3 = document.getElementById('radiovalue3' + id).value;
	if ((radval1 == 'true') || (radval2 == 'true') || (radval3 == 'true')) {
		this.changetext(id);
	} else
		document.getElementById('test1' + id).style.display = 'none';
}
function changetext(id) {
	document.getElementById('title' + id).innerHTML = '<strong>user name</strong> is now in your  Network <a href=\"javascript:startremove12(' + id + ')\">change</a>';
	document.getElementById('content1' + id).style.display = 'none';
}
function startremove(id) {
	document.getElementById('title' + id).className = "addUser";
	document.getElementById('title' + id).innerHTML = document
			.getElementById('content2' + id).innerHTML;
	var radval1 = document.getElementById('radiovalue1' + id).value;
	var radval2 = document.getElementById('radiovalue2' + id).value;
	var radval3 = document.getElementById('radiovalue3' + id).value;
	if (radval1 == 'true')
		document.getElementById('radio4' + id).className = 'radio1';
	else
		document.getElementById('radio4' + id).className = 'radio2';
	if (radval2 == 'true')
		document.getElementById('radio5' + id).className = 'radio1';
	else
		document.getElementById('radio5' + id).className = 'radio2';
	if (radval3 == 'true')
		document.getElementById('radio6' + id).className = 'radio1';
	else
		document.getElementById('radio6' + id).className = 'radio2';
}
function startremove12(id) {
	document.getElementById('title' + id).className = "addUser";
	document.getElementById('title' + id).innerHTML = document
			.getElementById('content2' + id).innerHTML;
	var radval1 = document.getElementById('radiovalue1' + id).value;
	var radval2 = document.getElementById('radiovalue2' + id).value;
	var radval3 = document.getElementById('radiovalue3' + id).value;
	if (radval1 == 'true')
		document.getElementById('radio4' + id).className = 'radio1';
	else
		document.getElementById('radio4' + id).className = 'radio2';
	if (radval2 == 'true')
		document.getElementById('radio5' + id).className = 'radio1';
	else
		document.getElementById('radio5' + id).className = 'radio2';
	if (radval3 == 'true')
		document.getElementById('radio6' + id).className = 'radio1';
	else
		document.getElementById('radio6' + id).className = 'radio2';
}
function submittoremove(id) {
	var radval1 = document.getElementById('radiovalue1' + id).value;
	var radval2 = document.getElementById('radiovalue2' + id).value;
	var radval3 = document.getElementById('radiovalue3' + id).value;
	if ((radval1 == 'true') || (radval2 == 'true') || (radval3 == 'true')) {
		this.changetext();
	} else {
		document.getElementById('title' + id).className = "addUser";
		document.getElementById('title' + id).innerHTML = '<a style=\"cursor:pointer;\" onclick=\"showagain(\'test1'
				+ id
				+ '\','
				+ id
				+ ')\"><font color="#FFFFFF">Add</font> <strong>user name</strong></a> to your  Network';
	}
}
function show(id) {
	if (document.getElementById(id).style.display == 'block')
		return;
	document.getElementById(id).style.display = 'block';
}
function show1(id) {// alert(id)
	document.getElementById(id).style.display = ''
	// document.getElementById('test11').style.display = ''
}
function hide(id) {
	document.getElementById(id).style.display = 'none';
}
function hide12(id) {
	document.getElementById(id).style.display = 'none';
}
function addCommJrnl(id) {// alert(id)
	document.getElementById('addComm' + id).style.display = '';
}
function hideCommJrnl(id) {
	// alert(id)
	document.getElementById('addComm' + id).style.display = 'none';
}
function showCommJrnl(id) {// alert(id)
	document.getElementById('showComm' + id).style.display = '';
}
function hideShowCommJrnl(id) {
	// alert(id)
	document.getElementById('showComm' + id).style.display = 'none'
}
function chkAddJrnlForm(id, jid, user_id, jtype) { // alert(id+'...'+jid+'----'+user_id)
	val = eval("document.frmAddJrnlComm" + id + ".text" + id + ".value");
	if (val == '') {
		alert('Kindly insert your comments.');
	} else {
		if (jtype != '')
			url = "transact-addComm_journal.php?id=" + id + "&jrnlid=" + jid
					+ "&userid=" + user_id + "&jtype=" + jtype;
		else
			url = "transact-addComm_journal.php?id=" + id + "&jrnlid=" + jid
					+ "&userid=" + user_id;
		eval('document.frmAddJrnlComm' + id + '.action="' + url + '"')
		eval('document.frmAddJrnlComm' + id + '.submit()')
	}
}
function chkAddJrnlForm1(id, jid, user_id, cmtid) {
	// alert(id+'...'+jid+'----'+user_id)
	val = eval("document.frmAddJrnlComm" + id + ".text" + id + ".value");
	if (val == '') {
		alert('Kindly insert your comments.');
	} else {
		url = "transact-addComm_journal.php?editcmt=" + cmtid + "&id=" + id
				+ "&jrnlid=" + jid + "&userid=" + user_id;
		// alert(url)
		eval('document.frmAddJrnlComm' + id + '.action="' + url + '"')
		eval('document.frmAddJrnlComm' + id + '.submit()')
	}
}

// CUSTOMIZABLE SETTINGS FOR AVATAR
var maxSize = 75;
var minSize = 45;
var animationSpeed = 8;
// --------------DONT EDIT BELOW--------------

var aniInterval;

var closeInterval;

var opend = false;

// function for menu state change

function changeState(t) {

	opend = t;

	if (t)
		clearInterval(closeInterval);

}

// function for hiding menu after interval, this function actually think sincer

function closeMe(imgDiv, borderDiv, winRef, id) {

	if (opend == false)
		closeInterval = setInterval(function() {
			hideMe(imgDiv, borderDiv, winRef, id)
		}, 200);

	else
		changeState(true);

}

// function for hide menu

function hideMe(imgDiv, borderDiv, winRef, id) {

	document.getElementById(winRef).style.display = 'none';

	// document.getElementById('tab'+id).style.display = 'none';

	clearInterval(closeInterval);

	startAni('small', imgDiv, borderDiv, winRef, id);

}

// start animation, if you call = 'big' then image will be big with animation

function startAni(call, imgDiv, borderDiv, winRef, id) {

	if (document.getElementById(winRef).style.display == "block")
		return;

	// document.getElementById('tab'+id).style.display="";

	if (call == 'big'
			&& document.getElementById(winRef).style.display == "none"
			&& document.getElementById(imgDiv).width <= minSize) {

		aniInterval = aniBig(imgDiv, borderDiv, winRef, id);

	}/*
		 * else if(document.getElementById(winRef).style.display=="none" &&
		 * opend==false && document.getElementById(imgDiv).width>=maxSize){
		 * 
		 * 
		 * 
		 * aniInterval = setInterval(function(){aniSmall(imgDiv,
		 * borderDiv,winRef,id)}, Number(animationSpeed*10));
		 * 
		 * 
		 * 
		 *  }
		 */
	else if (call == 'show'
			&& document.getElementById(winRef).style.display == "none") {

		showDD(winRef, id);

	} else if (document.getElementById(winRef).style.display == "none"
			&& opend == false
			&& document.getElementById(imgDiv).width >= maxSize) {

		aniInterval = aniSmall(imgDiv, borderDiv, winRef, id);

	} else {

		return;

	}

}

// defination of animation

function aniBig(imgDiv, borderDiv, winRef, id) {

	var img = document.getElementById(imgDiv);

	var div = document.getElementById(borderDiv);

	if (img.width >= maxSize) {

		clearInterval(aniInterval);

		return;

	}

	if (img.width < maxSize && img.height < maxSize) {

		img.width = maxSize;

		img.height = maxSize;

		document.getElementById(imgDiv).onclick = function() {
			startAni('show', imgDiv, borderDiv, winRef, id)
		};

		// div.style.offsetWidth = img.width+2.5;

	}

}

// defination of animation

function aniSmall(imgDiv, borderDiv, winRef, id) {

	var img = document.getElementById(imgDiv);

	var div = document.getElementById(borderDiv);

	if (img.width <= minSize) {

		clearInterval(aniInterval);

		return;

	}

	if (img.width > minSize && img.height > minSize) {

		img.width = minSize;
		img.height = minSize;

		document.getElementById(imgDiv).onclick = "";

		// div.style.width = img.width+2.5;
	}

	// img.style.paddingTop = "20px";

}

function showDD(winRef, id) {
	document.getElementById(winRef).style.display = "block";

	document.getElementById('tab' + id).style.display = "block";

	document.getElementById('tab' + id).style.position = "absolute";
}

function showSimpleAlert(message, options) {
	var settings = {
		autoCloseTime: 3000,
		height: 80,
		width: 250
    };

    jQuery.extend(settings, options);

	var simplePopupDialog = jQuery('#simplepopupdialog');
	if(!simplePopupDialog.get(0)) {
		simplePopupDialog = jQuery('<div id="simplepopupdialog" class="popupWindow">');
		var header = jQuery('<div class="header">');
		header.append(jQuery('<div class="title">'));
		var closeplace = jQuery('<div class="closeplace">');
		closeplace.append('<a onclick="return hideSimplePopupDialog();">close</a>');
		header.append(closeplace);
		simplePopupDialog.append(header);
		simplePopupDialog.append('<div class="popupcontent">');
		jQuery('body').append(simplePopupDialog);
	}
	jQuery('.popupcontent', simplePopupDialog).html(message);
	jQuery('.popupcontent', simplePopupDialog).height(settings.height).width(settings.width);
	simplePopupDialog.css('margin-left', -settings.width/2);
	
	simplePopupDialog.fadeIn();
	if(settings.autoCloseTime > 0) {
		setTimeout(function() {
	  		hideSimplePopupDialog();
		}, settings.autoCloseTime);
	}
}

function hideSimplePopupDialog() {
	jQuery('#simplepopupdialog').fadeOut();
	return false;
}