function toggle(div_id, popup_width, popup_height) {
	var el = document.getElementById(div_id);
	
	if ( el.style.display != 'block' ) {	
		el.style.display = 'block';
		if ((div_id != 'popUpBlanket') && (popup_width != '') && (popup_height != '')) {
			// reposition the popup if the window resizes
			 window.onresize = function() {	window_pos(div_id, popup_width, popup_height); };
		}
	}
	else { 
		el.style.display = 'none';
		window.onresize = function() {};
	}
}
function blanket_size(popUpDivVar, popup_height) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	//alert(viewportheight);
	var blanket = document.getElementById('popUpBlanket');
	blanket.style.height = blanket_height + 'px';
	/*var popUpDiv = document.getElementById(popUpDivVar);
	//popUpDiv_top=blanket_height/2-(popup_height/2);
	popUpDiv_top=viewportheight/2-(popup_height/2);
	popUpDiv.style.height = popup_height + 'px';
	popUpDiv.style.top = popUpDiv_top + 'px';*/
}
function window_pos(popUpDivVar, popup_width, popup_height) {
	
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	//alert('viewportwidth = ' + viewportwidth + "\n" + 'viewportheight = ' + viewportheight + "\n" + 'window_width = ' + window_width);
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_left=window_width/2-(popup_width / 2);
	popUpDiv_top=viewportheight/2-(popup_height/2);
	popUpDiv.style.width = popup_width + 'px';
	popUpDiv.style.left = popUpDiv_left + 'px';
	popUpDiv.style.top = popUpDiv_top + 'px';
}

/*function centertable_size(windowname, popup_width, popup_height) {
	var my_tds = document.getElementById(windowname).getElementsByTagName('td');
	//var my_table = my_tables[0];
	//var my_tds = my_tables[0].getElementsByTagName('td');
	var my_td = my_tds[0];
	//my_table[0].style.width = popup_width + 'px';
	//my_table[0].style.height = popup_height + 'px';
	my_tds[0].style.width = (popup_width - 28) + 'px';
	my_tds[0].style.height = (popup_height - 28) + 'px';
	my_tds[0].style.verticalAlign = "middle";
}*/
function popup(windowname, popup_width, popup_height) {
	blanket_size(windowname, popup_height);
	window_pos(windowname, popup_width, popup_height);
	toggle('popUpBlanket');
	toggle(windowname, popup_width, popup_height);	
	//centertable_size(windowname, popup_width, popup_height);
}

function validateSharePopUp(thisform) {
	with (thisform) {
		if (from_name.value == '') {
			alert("Please enter your name");
			from_name.focus();
			return false;
		}
		if (validate_email(from_email,"Not a valid e-mail address!")==false) {
			from_email.focus();
			return false;
		}
		if (friend_name.value == '') {
			alert("Please enter a valid name");
			friend_name.focus();
			return false;
		}
		if (validate_email(friend_email,"Not a valid e-mail address!")==false) {
			friend_email.focus();
			return false;
		}
		
	}
	return true;
}

