// Script form validator
function formValidator(){
	// Make quick references to our fields
	var title = document.getElementById('title');
	var content = document.getElementById('elm1');
	
	if(notEmpty(title, "Please enter the title!")){
		return true;
	}
	return false;
}

function pollingValidator(){
	// Make quick references to our fields
	var question = document.getElementById('question');
	var opt1 = document.getElementById('opt1');
	var opt2 = document.getElementById('opt2');
	
	if(notEmpty(question, "Please enter the question!")){
		if(notEmpty(opt1, "Please enter at least 2 options in option 1 and option 2!")){
			if(notEmpty(opt2, "Please enter at least 2 options in option 1 and option 2!")){
				return true;
			}
		}
	}
	return false;
}

function messageValidator(){
	// Make quick references to our fields
	var from = document.getElementById('from');
	var email = document.getElementById('email');
	
	if(notEmpty(from, "Please enter your name!")){
		if(emailValidator(email, "Please enter a valid email address!")){
			return true;
		}
	}
	return false;
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
// Script form validator


// Script add field upload news
function addfield (id){
	document.getElementById('a').innerHTML = "Choose a picture to upload: <input type=\"file\" name=\"file2\" \/>";
	document.getElementById('adduploadfield').style.visibility = "hidden";
}
// Script add field upload news


// Script check password
function checkpass (){
	var temp1;
	var temp2;
	temp1 = document.getElementById('password1').value;
	temp2 = document.getElementById('password2').value;
	if(temp1 != temp2)
	{
		document.getElementById('b').innerHTML = "<b><font color=\"FF0000\">Password doesn't match!</font></b>";
	}
	else
	{
		document.getElementById('b').innerHTML = "<b><font color=\"#348017\">Password match!</font></b>";
	}
}
// Script check password


// Script popup everyday's delight
/*function popup(){
	var page = "popup.php";
	var winl = (screen.width-300)/2;
	var wint = (screen.height-250)/2;
	var windowproperties = "width=300,height=250,top="+wint+",left="+winl+",location=no,menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no";
	window.open(page,'PopupName',windowproperties);
}*/
/*function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
*/
function toggle(div_id) {
	var el = document.getElementById(div_id);
	//if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	el.style.display = 'block';
}

function toggle1(div_id) {
	var el = document.getElementById(div_id);
	el.style.display = 'none';
	//else {el.style.display = 'none';}
}

function blanket_size(popUpDivVar) {
	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;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = (screen.height-500)/2 + 'px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = 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;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}

function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}

function popup1(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle1('blanket');
	toggle1(windowname);		
}

function timingex( ){
	popup('popUpDiv');
	setTimeout("popup1('popUpDiv');",5000);
}
// Script popup everyday's delight


// Script WYSIWYG - TinyMCE
tinyMCE.init({
	// General options
	mode : "textareas",
	theme : "advanced",
	plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,help",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,advhr",
	theme_advanced_buttons4 : "insertdate,inserttime,preview,|,forecolor,backcolor,|,ltr,rtl,|,fullscreen",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,

	// Example content CSS (should be your site CSS)
	content_css : "css/content.css",

	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "lists/template_list.js",
	external_link_list_url : "lists/link_list.js",
	external_image_list_url : "lists/image_list.js",
	media_external_list_url : "lists/media_list.js",

	// Style formats
	style_formats : [
		{title : 'Bold text', inline : 'b'},
		{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
		{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
		{title : 'Example 1', inline : 'span', classes : 'example1'},
		{title : 'Example 2', inline : 'span', classes : 'example2'},
		{title : 'Table styles'},
		{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
	],

	// Replace values for the template plugin
	template_replace_values : {
		username : "Some User",
		staffid : "991234"
	}
});
// Script WYSIWYG - TinyMCE
