/******************************************************
	Date Created: 19th Jan, 2007
	Created By: Jerome Peeris
	Purpose of this (page/form/module): This page is used for the javascript funtion.
	Last Modified: 
	Modified By: Jerome Peeris
******************************************************/

/* Read Only Function*/
function make_readonly()
{
	alert("Please Use Browse Button");
	return false;
}//End of Function

/* Checks for blank text boxes*/
function checkBlank(ctl,msgName)
{
	if(Trim(ctl.value)=="")	
    {
		alert(''+msgName+'' + "cannot be blank");
		ctl.focus();
		return (false);
    }
}//End of Function

 function confirmEmail(ctl1,ctl2)
	{
		
		if(ctl1.value != ctl2.value)
		{
			alert ("Email and Confirm Email do not match\n");
			ctl1.focus();
			return (false);
	   }
	   else
	   {
		   return (true);
	   }
	
	}//End of Function
/* Checks for unselected select boxes*/
function checkSelect(ctl,msgName)
{
	if(ctl.selectedIndex==0)	
    {
		alert('Please select '+msgName);
		ctl.focus();
		return (false);
    }
	else
    {
    	return (true);
    }
}//End of Function


/* Checks for the entered email id is in a proper format*/
function ValidateEmail(ctl)
{
	var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) ) 
	{
		error = 1;
		alert("Email enter proper Email Address.");
		ctl.focus();
		return (false);
	}
}//End of Function



/* Function to validate the radio button*/
function radio_validate(formObj) 
{
    var isOK = false;
    for (i=0;i<formObj.elements.length;i++) 
	{
		currElem = formObj.elements[i]
        if (currElem.type == "radio"  &&  currElem.checked) 
		{
            isOK=true;
			break;
        }
    }
    
	if (!isOK) 
		alert("You need to select a option !");
    return isOK;
}//End of Function


/* Function to remove the leading and trailing spaces*/
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}//End of Function

/*Function for To Check if it is Numeric*/

function IsNumeric(cti,msgName)

{
   var ValidChars = "0123456789";
   
   var Char;

 
   for (i = 0; i < cti.value.length; i++) 
      { 
      Char = cti.value.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         alert(msgName+' should be Numeric');
		 cti.focus();
		 return (false);
         }
      }
	 
   }






/* Funtion for Numbers Only and Disables all other key*/


function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	
	if (unicode!=8)
	{ //if the key isn't the backspace key (which we should allow)
		if (unicode<48||unicode>57) //if not a number
		return false //disable key press
	}
}//End of Function


/* Function moves the cursor from one text box to another after 3 characters*/
function valuedata(data,movedata)
{ 
	if(data.length == 3)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function

 
/* Function moves the cursor from one text box to another after 2 characters*/
function valuedata1(data,movedata)
{
	if(data.length == 2)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function


/* Funtion for Characters Only and Disables all other key*/

function alphaCharacters(event)
{
	
	/********
	FOR IE
	*********/
	if(document.all)
	{
		if(event.keyCode>=65 && event.keyCode<=90)
		{
			return true;
		}
		else if(event.keyCode>=97 && event.keyCode<=122)
		{
			return true;
		}
		else if(event.keyCode==32)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/************************************
	OTHER BROWSER LIKE FIREFOX,NETSCAPE
	*************************************/
	if ((!document.all )&& (document.getElementById)) 
	{
		if(event.which>=65 && event.which<=90)
		{
			return true;
		}
		else if(event.which>=97 && event.which<=122)
		{
			return true;
		}
		else if(event.which==32)
		{
			return true;
		}
		else if(event.which==0 || event.which==8)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}//End of Function


function cancelMC()
{
	window.location = "?q=add_menu_cat";
}
function cancelMod()
{
	window.location = "?q=module";
}
function cancelSubs()
{
	window.location = "?q=subscriber";
}
function cancelP(cid)
{
	
	window.location = "?q=photo_gallery&cid="+cid;
}
function cancelAr()
{
	window.location = "?q=article";
}
function cancelACr()
{
	window.location = "?q=artcat";
}

function cancelE()
{
	window.location = "?q=member";
}

function cancelA()
{
	window.location = "?q=member";
}
function cancelcol()
{
	window.location = "?q=configuration&cid="+1+"";
}

function cancelPC()
{
	window.location = "?q=photo_category";
}
function cancelM(menuid)
{
	window.location = "?q=add_menu&menucid="+menuid+"";
}
function cancelGA(menuid)
{
	window.location = "?q=analytic&cid="+1+"";
}
function cancelNL()
{
	window.location = "?q=subscriber";
}
function cancelSER()
{
	window.location = "?q=servicescategory";
}
function cancelIT()
{
	window.location = "?q=serviceitem";
}

/* Funtion for Characters Only and Disables all other key*/

function lenghthcheck(event)
{
	var length=event;	

	if (length >4 && length < 10)
		return true;
	else
		alert("The Postcode should be 4-10 characters long.");
}


