// JavaScript Document
 
// Declaring required variables
// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

 
//form
 

  	function validatecontact() 
		{ 
		
		
		    if(document.contact_us.name.value=="")
			{
				window.alert('Enter Name');
				document.contact_us.name.focus();
				return false;
			}
			  if(document.contact_us.email.value=="")
			{
				window.alert('Enter Email');
				document.contact_us.email.focus();
				return false;
			}
			else
			
			 if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contact_us.email.value ))
			{
		    
			if(document.contact_us.phone.value=="")
			{
				window.alert('Enter Phone Number !');
				document.contact_us.phone.focus();
				return false;
			}
				if(document.contact_us.commnets.value=="")
			{
				window.alert('Enter Comments !');
				document.contact_us.commnets.focus();
				return false;
			}
			 
            	
			return true;
			}
            
			else
			{
 			window.alert("Invalid E-mail Address! Please re-enter.");
			document.contact_us.email.focus();
			return false;
			}
		
		}
		
	function validateeditart()
		{
				if(document.RTEDemo.title.value=="")
			{
				window.alert('Enter Title !');
				document.RTEDemo.title.focus();
				return false;
			}	
				if(document.RTEDemo.elm1.value=="")
			{
				window.alert('Enter Text !');
				document.RTEDemo.elm1.focus();
				return false;
			}	
		}
		
		
		function validateform()
		{
				if(document.contact_form.name.value=="")
			{
 				document.contact_form.name.focus();
				return false;
			}	
		 
		}
		
		
			
	function validateslide()
		{
				if(document.RTEDemo.slide_cat.value=="Select Categories Title" || document.RTEDemo.slide_cat.value=="")
			{
				window.alert('Select Title !');
				document.RTEDemo.slide_cat.focus();
				return false;
			}	
 			 	if(document.RTEDemo.file1.value=="")
			{
				window.alert('Upload Image !');
				document.RTEDemo.slide_cat.focus();
				return false;
			}	
 			 
		}
		
			function validatepassword() 
		{ 
		
		
		    if(document.password.password.value=="")
			{
				window.alert('Enter Current Password !');
				document.password.password.focus();
				return false;
			}
			
			 
		    if(document.password.password_new.value=="")
			{
				window.alert('Enter New Password !');
				document.password.password_new.focus();
				return false;
			}
			
		    if(document.password.password_new1.value=="")
			{
				window.alert('Confirm New Password !');
				document.password.password_new1.focus();
				return false;
			}
			
			    if(document.password.password_new1.value!==document.password.password_new.value)
			{
				window.alert('Passwords do not match. Please Enter Again');
				document.password.password_new1.focus();
				return false;
			}
			  
		}
		
function validateaddnews()
		{
			//alert(document.RTEDemo.newsdesc.value);
			var url = document.RTEDemo.url.value;
				if(document.RTEDemo.newstitle.value=="")
			{
				alert("Please enter news title")
 				document.RTEDemo.newstitle.focus();
				return false;
			}	
					
			if(document.RTEDemo.newsdesc.value=='')
		 {
			alert("Please enter a short description") ;
			document.RTEDemo.newsdesc.focus();
			return false;
		}
		if(document.RTEDemo.url.value=="")
		{
			alert("Please enter a url");
			document.RTEDemo.url.focus();
			return false;
		}
		else {
		var res = check_it(url);
		if(res==0) {
	alert("Please enter a valid URL");
	return false;
		}
		else
		{
			return true;
		}
		}
					 
		}
function check_it(url)
{
     var theurl=url;
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/

     if (tomatch.test(theurl)){
          return "1";
     }
     else
     {
            return "0";
     }
}


function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

function del()
{
  var ok=confirm("Are you sure, Do you want to delete this record?");
  if(ok==true)
		return true;
  else
  		return false; 
}
