function C(obj)
{document.getElementById('c1').src='./Images/Inner/t0.jpg';document.getElementById('c2').src='./Images/Inner/g0.jpg';document.getElementById('c3').src='./Images/Inner/pr0.jpg';document.getElementById('c4').src='./Images/Inner/ph0.jpg';document.getElementById('c5').src='./Images/Inner/w0.jpg';obj.src=obj.src.replace('0','1');}
function Check()
{if(trim(document.getElementById('txtSearch').value)=='')document.getElementById('txtSearch').value='ادخل كلمه البحث';
}

function Reset()
{
	document.forms[0].reset();
}

function showWap()
{
	l = (screen.width-273)/2;
	t = (screen.height-480)/2;
	window.open("http://www.adpolice.gov.ae/adpwap/default.aspx","wap1","height=370,width=273,top="+t+",left=" + l +",status=no,toolbar=no,menubar=no,location=no;");
}

function Print()
{
	LeftPosition = (screen.width) ? (screen.width-600)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0;
	var win = window.open("./Controls/Print.htm","Print","height=500,width=600,top=" + TopPosition + ",left=" + LeftPosition + "status=yes,toolbar=no,menubar=yes,location=no");
	win.focus();
}


function GP(id)
{
	LeftPosition = (screen.width) ? (screen.width-600)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0;
	var win = window.open("./GPop.aspx?ID=" + id,"GPop","height=500,width=600,top=" + TopPosition + ",left=" + LeftPosition + "status=yes,toolbar=no,menubar=yes,location=no");
	win.focus();
}

function TP(id)
{
	LeftPosition = (screen.width) ? (screen.width-600)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0;
	var win = window.open("./TPop.aspx?ID=" + id,"TPop","height=500,width=600,top=" + TopPosition + ",left=" + LeftPosition + "status=yes,toolbar=no,menubar=yes,location=no");
	win.focus();
}


function PP(id)
{
	LeftPosition = (screen.width) ? (screen.width-600)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-600)/2 : 0;
	var win = window.open("./PHPop.aspx?ID=" + id,"TPop","height=500,width=600,top=" + TopPosition + ",left=" + LeftPosition + "status=yes,toolbar=no,menubar=yes,location=no");
	win.focus();
}

function Mail(bdy)
{
	navigate('mailto:?subject= Abu Dhabi Police News : ' + document.getElementById('_ctl2_lblTitle').innerText + '&body=' + bdy );
}

function Weather()
{
	var strData = tac_post('on_weather','').split('|');

	if(strData.length > 1)
	{
		document.getElementById('tblWeather').className		= "Vis";
		document.getElementById('wMes').className			= "Inv";
		document.getElementById('lblName').innerText		= strData[0];
		document.getElementById('lblTime').innerText		= strData[1];
		document.getElementById('lblTemp').innerText		= strData[2];
		document.getElementById('lblFeels').innerText		= strData[3];
		document.getElementById('lblStatus').innerText		= strData[4];
		document.getElementById('Image1').src				= strData[5];
		document.getElementById('lblWind').innerText		= strData[6];
		document.getElementById('lblHumidity').innerText	= strData[7];
		document.getElementById('lblVisibility').innerText	= strData[8];
		document.getElementById('lblUV').innerText			= strData[9];
	}
	else
	{
		document.getElementById('tblWeather').className = "Inv";
		document.getElementById('wMes').innerText = "عفوا، لاتوجد معلومات عن حالة الطقس في الوقت الحالي";
		document.getElementById('wMes').className = "Vis";
	}
}

function Gallery(id)
{
	window.open("./Controls/Image.aspx?ID=" + id,"Gallery","status=no,toolbar=no,menubar=no,location=no");
}

function NImage()
{
	window.open("./Controls/NImage.htm","News","status=no,toolbar=no,menubar=no,location=no");
}

function NImg(obj)
{
	document.getElementById('hidNImage').value = obj.src;
	window.open("show.htm","News","status=no,toolbar=no,menubar=no,location=no");
}

function Login()
{
	if(trim(document.getElementById('txtUser').value) == '')
	{
		alert('رجاءً، أدخل اسم المستخدم');
		document.getElementById('txtUser').focus();
		document.getElementById('txtUser').select();
		return;
	}

	if(trim(document.getElementById('txtPass').value) == '')
	{
		alert('رجاءً، أدخل كلمة السر');
		document.getElementById('txtPass').focus();
		document.getElementById('txtPass').select();
		return;
	}

	var log = tac_post('on_login', document.getElementById('txtUser').value + ':' + document.getElementById('txtPass').value);
	if(log == "0")
	{
		alert('عفواً، يرجى التحقق من اسم المستخدم أو رمز المرور وإعادة المحاولة مرة أخرى');
		document.getElementById('txtUser').focus();
		document.getElementById('txtUser').select();
		document.getElementById('txtPass').value = '';
		return false;
	}
	else
	{
		document.getElementById('_ctl2_imgLogin').className = 'Inv';
		document.getElementById('_ctl2_imgSignout').className = 'ImgButton Vis';
		document.getElementById('_ctl2_tdLogin').innerHTML = log;
		alert('مرحباً، لقد تمت عملية الدخول بنجاح ');
		location.reload();
		return;
	}
}

function Logoff()
{
	var logoff = tac_post('on_logoff','');
	document.getElementById('_ctl2_imgLogin').className = 'ImgButton Vis';
	document.getElementById('_ctl2_imgSignout').className = 'Inv';
	document.getElementById('_ctl2_tdLogin').innerHTML = logoff;
	location.reload();
}

function KL()
{
	if(event.keyCode == 13) Login();
	else Page_BlockSubmit = true;
}

function NL()
{
	if(event.keyCode == 13) NewsLetter();
	else Page_BlockSubmit = true;
}

function AEnter()
{
	if(event.keyCode == 13 && trim(document.getElementById('txtASearch').value) != '')
	{
		document.getElementById('btnASearch').click();
	}
	else Page_BlockSubmit = true;
}

function ASearch()
{
	var sTerm = trim(document.getElementById('txtASearch').value);
	if(sTerm != '')
	{
		if(sTerm.length > 2)
		{
			if(tac_post('on_article_search', document.getElementById('txtASearch').value + ':' + document.getElementById('_ctl2_ASearch_ddlCategory').options[document.getElementById('_ctl2_ASearch_ddlCategory').selectedIndex].value) == "0")
			{
				alert("عفواً، لاتوجد نتائج لكلمة البحث.");
				document.getElementById('txtASearch').focus();
				document.getElementById('txtASearch').select();
				return false;
			}
			else
			{
				navigate('./?T=12&M=' + document.getElementById('_ctl2_ASearch_ddlCategory').options[document.getElementById('_ctl2_ASearch_ddlCategory').selectedIndex].value + '&S=' + document.getElementById('txtASearch').value);
			}
		}
		else alert('يرجى إدخال 3 حروف على الاقل.');
	}
	else
	{
		alert('يرجى إدخال كلمة البحث.');
		document.getElementById('txtASearch').focus();
		return false;
	}
}

function Enter()
{
	if(event.keyCode == 13 && trim(document.getElementById('txtSearch').value) != '')
	{
		document.getElementById('btnSearch').click();
	}
	else Page_BlockSubmit = true;
}

function AD(adId)
{
	var rtn = tac_post('on_ads',adId);
	document.getElementById('_ctl2_lblContent').innerHTML = rtn;
}

function Search()
{
	var sTerm = trim(document.getElementById('txtSearch').value);
	if(sTerm != '' && sTerm != 'ادخل كلمه البحث')
	{
		if(sTerm.length > 2)
		{
			if(tac_post('on_search', document.getElementById('txtSearch').value + ':' + document.getElementById('ddlSearch').options[document.getElementById('ddlSearch').selectedIndex].value) == "0")
			{
				alert("عفواً، لاتوجد نتائج لكلمة البحث.");
				document.getElementById('txtSearch').focus();
				document.getElementById('txtSearch').select();
				return false;
			}
			else
			{
				navigate('./?T=10&M=' + document.getElementById('ddlSearch').options[document.getElementById('ddlSearch').selectedIndex].value + '&S=' + document.getElementById('txtSearch').value);
			}
		}
		else alert('يرجى إدخال 3 حروف على الاقل.');
	}
	else
	{
		alert('يرجى إدخال كلمة البحث.');
		return false;
	}
}

function Over(num)
{
	document.getElementById('TD' + num).className = 'Over';
}

function Out(num)
{
	document.getElementById('TD' + num).className = '';
}

function ON(obj)
{
	obj.className = 'LIImage ImgButton';
}

function OFF(obj)
{
	obj.className = 'LNImage ImgButton';
}

function Poll()
{
	var qid  = document.getElementById('qid').innerText;
	var rbl  = document.getElementById('nav_rblAnswers');
	var rbls = rbl.getElementsByTagName('input');
	var res = 0;
	for(i = 0; i < rbls.length;i++)
	{
		if(rbls[i].checked)
		{
			res = rbls[i].value;
			break;
		}
	}

	var rtn = tac_post('on_poll',res);
	if(rtn == "0")
	{
		alert("عفواً، خطأ في عملية إرسال المعلومات، يرجى المحاولة مرة اخرى");
		return;
	}
	else
	{
		document.getElementById('nav_imgPSubmit').className = 'Inv';
		document.getElementById('nav_tdPContent').innerHTML = rtn;
		alert('شكراً، عملية الإقتراع تمت بنجاح');
		return;
	}
}

function Results()
{
	var rtn = tac_post('on_pollresults','');
	if(document.getElementById('nav_imgPSubmit') != null)document.getElementById('nav_imgPSubmit').className = 'Inv';
	document.getElementById('nav_tdPContent').innerHTML = rtn;
}

function NewsLetter()
{
	var email = trim(document.getElementById('txtNLetter').value);
	if(email == '')
	{
		alert('يرجى إدخال البريد الإلكتروني');
		document.getElementById('txtNLetter').focus();
		document.getElementById('txtNLetter').select();
		return;
	}

	if(CheckMail(email))
	{
		var rtn = tac_post('on_nletteren',document.getElementById('txtNLetter').value);
		if(rtn == "0")
		{
			alert("عفواً، البريد الإلكتروني المرسل مسجل لدينا.");
			document.getElementById('txtNLetter').select();
			document.getElementById('txtNLetter').focus();
			return;
		}
		else
		{
			document.getElementById('txtNLetter').value = '';
			alert('شكراً، عملية إرسال المعلومات تمت بنجاح.\n\nرقم اشتراكك هو : ' + rtn);
			return;
		}
	}
	else
	{
		alert('البريد الإلكتروني المرسل غير صحيح، يرجى المحاولة مرة أخرى');
		document.getElementById('txtNLetter').focus();
		document.getElementById('txtNLetter').select();
		return;
	}
}

function trim(s)
{
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function SNews()
{

	if(trim(document.getElementById('txtFrom').value) == '')
	{
		alert('من فضلك أدخل بريدك الإلكترونى.');
		document.getElementById('txtFrom').focus();
		document.getElementById('txtFrom').select();
		return;
	}

	if(!CheckMail(document.getElementById('txtFrom').value))
	{
		alert('البريد الإلكترونى الذى أدخلته ليس صحيحا.');
		document.getElementById('txtFrom').focus();
		document.getElementById('txtFrom').select();
		return;
	}

	if(trim(document.getElementById('txtTo').value) == '')
	{
		alert("من فضلك أخل البريد الإلكترونى للمرسل إليه.");
		document.getElementById('txtTo').focus();
		document.getElementById('txtTo').select();
		return;
	}

	if(!CheckMail(document.getElementById('txtTo').value))
	{
		alert("البريد الإلكترونى الذى أدخلته ليس صحيحا.");
		document.getElementById('txtTo').focus();
		document.getElementById('txtTo').select();
		return;
	}


	var url = AddParamToURL(location.href);

	var rtn = tac_post('on_sendnews',document.getElementById('txtFrom').value + ';' + document.getElementById('txtTo').value + ';' + url);
	if(rtn == "1")
	{
		alert("خطأ.");
		return;
	}
	else
	{
		document.getElementById('txtTo').value = '';
		document.getElementById('txtTo').focus();
		alert('تم إرسال الخبر لعنوان البريد الإلكترونى الذى حددته.');
		return;
	}
}

function AddParamToURL(strLoc)
{
	strLoc = strLoc.replace('?','-');
	strLoc = strLoc.replace('&','--');
	return strLoc;
}

function CheckMail(mail)
{
	 var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return(regex.test(mail));
}