function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//More images can be added following the same format.
//The script will automatically adapt for more images.
function RandElement(IList)
{
    return(IList[Math.round(Math.random()*(IList.length-1))]);
}

//Used for opening the Pop-up window
function MM_openBrWindow(theURL,winName,features)
{
  window.open(theURL,winName,features);
}


/*
+----------------------------------------------------------------------+
| function useful for all pages starts                                 |
+----------------------------------------------------------------------+
*/
function submitAction(myval)
{
	var url;
	url = "act.php?customerid="+document.form2.customerid.value+ "&event="+document.form2.eventid.value+ "&timeid="+document.form2.timeid.value+ "&action="+myval;
	//alert(url);
	open(url, target="_self");
}

/*
+----------------------------------------------------------------------+
| function useful for all pages ends                                   |
+----------------------------------------------------------------------+
*/

/*
+----------------------------------------------------------------------+
| Search related functions Start                                       |
+----------------------------------------------------------------------+
*/

//Function for populating the calender in search section
function fun1()
{
    //alert ("today"+document.form1.sysdate.value);
    var curDate=new Date(document.form1.sysdate.value+"");
    tempstvr=false;
	tempflag=false;
    //show_calendar3('document.form1.date',"",curDate);
    show_calendar3('document.form1.date',"",'','',curDate,tempstvr,"",0,tempflag);
    document.form1.date.value=document.form1.date.value.substring(0,10);
}


//Function for validating the event field in search section
function checkfield()
{
  if(checkevent()==false)
   return false;
  return true;
}
//Function for validating the event field in search section
function checkevent()
{
  var eventval=document.form1.event.value;
  if(eventval.toString()=="")
  {
    alert("Event Needs to be Selected");
    document.form1.event.focus();
    return false;
  }
  else
   return true;
}
//Function for validating the city field in search section(presently not used)
function checkcity()
{
  var cityval=document.form1.city.value;
  if(cityval.toString()=="")
  {
    alert("City is a required field");
    document.form1.city.focus();
    return false;
  }
  else
   return true;
}

//Function for validating the date field in search section
function checkdate()
{
  if(document.form1.date.value=="")
  {
    alert("Date is a Required Field");
    document.form1.date.focus();
    return false;
  }

  else
   return true;
}

//Occurs when customer checks the "Display only if Tickets are available" Check button.
function goforevent()
{
  //alert("go for event");
   if(checkfield()==true)
   {
         city = "";
         eventname = "";
        if (document.form1.city.value != ""){
            city=document.form1.city.value;
        }
        event1=document.form1.event.value;
        if (document.form1.available.checked == true)
        {
          //document.form1.available.value = 1;
            available = 1;
        }
        else
        {
          //document.form1.available.value = 0;
            available = 0;
        }
        if(document.form1.eventname.value != ""){
            eventname = document.form1.eventname.value;
        }
        var url = "../search/searchresult.php?event="+event1+"&city="+city+"&eventname="+eventname+"&available="+available+"&pgno=1";
        open(url, target="_self");
	}
}

function goforevent_tele()
{
  //alert("go for event");
   if(checkfield()==true)
   {
         city = "";
         eventname = "";
        if (document.form1.city.value != ""){
            city=document.form1.city.value;
        }
        event1=document.form1.event.value;
        if (document.form1.available.checked == true)
        {
          //document.form1.available.value = 1;
            available = 1;
        }
        else
        {
          //document.form1.available.value = 0;
            available = 0;
        }
        if(document.form1.eventname.value != ""){
            eventname = document.form1.eventname.value;
        }
        var url = "searchresult_admin.php?event="+event1+"&city="+city+"&eventname="+eventname+"&available="+available+"&pgno=1";
        open(url, target="_self");
	}
}

//Occurs when customer clicks the "go" button related to Date Search
function godate()
{
   if(checkdate()==true)
   {
    date = document.form1.date.value;
    if (document.form1.availabledate.checked == true)
     {
        document.form1.availabledate.value = 1;
        availabledate = 1;
     }
     else
     {
        document.form1.availabledate.value = 0;
        availabledate = 0;
     }
    var url = "../search/searchresult.php?date="+date+"&availabledate="+availabledate+"&pgno=1";
    open(url, target="_self");
	}
}
function godate_tele()
{
   if(checkdate()==true)
   {
    date = document.form1.date.value;
    if (document.form1.availabledate.checked == true)
     {
        document.form1.availabledate.value = 1;
        availabledate = 1;
     }
     else
     {
        document.form1.availabledate.value = 0;
        availabledate = 0;
     }
    var url = "searchresult_admin.php?date="+date+"&availabledate="+availabledate+"&pgno=1";
    open(url, target="_self");
	}
}

//Used to check the date field in the date search section
function checkdate()
{
  if(document.form1.date.value == "")
  {
    alert("Date is a Required Field");
    document.form1.date.focus();
    return false;
  }
  else
   return true;
}

//Paging NEXT
function next()
{
   //alert("hi");
   city=document.form1.city.value;
   //alert(city);
   event1=document.form1.event.value;
   eventname = document.form1.eventname.value;
   available = document.form1.available.value;
   date = document.form1.date.value;
   //alert(event1);
   pgno=document.form1.pgno.value;
   //alert(pgno);
   if(pgno=="")
   pgno=0;

   maxpgno=document.form1.maxpgno.value;
   //alert(maxpgno);
   pgno=Math.abs(pgno)+1;
   if(pgno > maxpgno)
   {
       pgno=pgno-1;
   }
   //alert(pgno);
 if (maxpgno != 1){
      if ((document.form1.event.value != "") && (document.form1.city.value != ""))
          var url = "../search/searchresult.php?event="+event1+"&city="+city+"&eventname="+eventname+"&available="+available+"&pgno="+pgno;
      else if (document.form1.date.value != ""){
          availabledate = document.form1.availabledate.value;
          var url = "../search/searchresult.php?date="+date+"&pgno="+pgno+"&availabledate="+availabledate;
      }
       else if(document.form1.loc.value!="no")
           var url = "../search/searchbyloc.php?loc="+document.form1.loc.value+"&pgno="+pgno;
       else
          var url = "../search/searchresult.php?result=all&pgno="+pgno+"&available="+available;

           //alert(url);
          open(url, target="_self");
  }
}


//next for telebooking
function next_tele()
{
   //alert("hi");
   city=document.form1.city.value;
   //alert(city);
   event1=document.form1.event.value;
   eventname = document.form1.eventname.value;
   available = document.form1.available.value;
   date = document.form1.date.value;
   //alert(event1);
   pgno=document.form1.pgno.value;
   //alert(pgno);
   if(pgno=="")
   pgno=0;

   maxpgno=document.form1.maxpgno.value;
   //alert(maxpgno);
   pgno=Math.abs(pgno)+1;
   if(pgno > maxpgno)
   {
       pgno=pgno-1;
   }
   //alert(pgno);
 if (maxpgno != 1){
      if (((document.form1.event.value != "") || (document.form1.city.value != ""))&&(document.form1.loc.value=="no")){
       
          var url = "searchresult_admin.php?event="+event1+"&city="+city+"&eventname="+eventname+"&available="+available+"&pgno="+pgno;
      }
      else if (document.form1.date.value != ""){
          availabledate = document.form1.availabledate.value;
          var url = "searchresult_admin.php?date="+date+"&pgno="+pgno+"&availabledate="+availabledate;
      }
       else if(document.form1.loc.value>=1){
           var url = "searchbyloc_admin.php?loc="+document.form1.loc.value+"&pgno="+pgno;
           }
       else{
           var url = "searchresult_admin.php?result=all&pgno="+pgno+"&available="+available;
           }

          // alert(document.form1.date.value);
          open(url, target="_self");
  }
}

//Paging PREVIOUS
function previous()
{
   city=document.form1.city.value;
   event1=document.form1.event.value;
   eventname = document.form1.eventname.value;
   date = document.form1.date.value;
   available = document.form1.available.value;
   availabledate = document.form1.availabledate.value;
   pgno=document.form1.pgno.value;
   maxpgno=document.form1.maxpgno.value;
   pgno=Math.abs(pgno)-1;
   if(pgno<1)
   {
     pgno=1;
   }
   if (maxpgno != 1){
       if ((document.form1.event.value != "") && (document.form1.city.value != ""))
          var url = "../search/searchresult.php?event="+event1+"&city="+city+"&eventname="+eventname+"&available="+available+"&pgno="+pgno;
      else if (document.form1.date.value != "")
          var url = "../search/searchresult.php?date="+date+"&pgno="+pgno+"&availabledate="+availabledate;
       else if(document.form1.loc.value!="no")
           var url = "../search/searchbyloc.php?loc="+document.form1.loc.value+"&pgno="+pgno;
        else
          var url = "../search/searchresult.php?result=all&pgno="+pgno+"&available="+available;
       //alert(url);
       open(url, target="_self");
   }
}

//Paging PREVIOUS telebooking
function previous_tele()
{
   city=document.form1.city.value;
   event1=document.form1.event.value;
   eventname = document.form1.eventname.value;
   date = document.form1.date.value;
   available = document.form1.available.value;
   availabledate = document.form1.availabledate.value;
   pgno=document.form1.pgno.value;
   maxpgno=document.form1.maxpgno.value;
   pgno=Math.abs(pgno)-1;
   if(pgno<1)
   {
     pgno=1;
   }
   if (maxpgno != 1){
       if (((document.form1.event.value != "") || (document.form1.city.value != ""))&&(document.form1.loc.value=="no"))
          var url = "searchresult_admin.php?event="+event1+"&city="+city+"&eventname="+eventname+"&available="+available+"&pgno="+pgno;
      else if (document.form1.date.value != "")
          var url = "searchresult_admin.php?date="+date+"&pgno="+pgno+"&availabledate="+availabledate;
       else if(document.form1.loc.value>=1)
           var url = "searchbyloc_admin.php?loc="+document.form1.loc.value+"&pgno="+pgno;
        else
          var url = "searchresult_admin.php?result=all&pgno="+pgno+"&available="+available;
       //alert(url);
       open(url, target="_self");
   }
}




/*
+----------------------------------------------------------------------+
| Search related functions end                                         |
+----------------------------------------------------------------------+
*/

//For getting the event id
function radioVal()
{
	var val=0;
	var i=0;
	for(i=0;i<document.myevents.elements.length;i++)
	{
		if (document.myevents.elements[i].type=="radio")
		{
			var checked=document.myevents.elements[i].checked;

			if(checked)
			{


				val=document.myevents.elements[i].value;
				return(val);
			}
		}
	}
	return(true);
}


//Function for checking the Quantity of Cancelled Tickets.
function checkQtyOfCancelledTickets()
{
	var catId=new String("");
	var checkCount=0;
	for(i=0;i<document.form2.elements.length;i++)
	{
		if (document.form2.elements[i].type=="checkbox")
		{
			var checked=document.form2.elements[i].checked;
			if(checked)
			{
				checkCount=checkCount+1;
			}
		}
	}
	if(checkCount==0)
	{
		alert("Please Select at Least one Ticket Number.");
		return(false);
	}
    return true
}


/*
+----------------------------------------------------------------------+
| Buy Ticktes  related functions start                                  |
+----------------------------------------------------------------------+
*/


//Fnction for checking the Booking ticktes Quantity
function checkBookingTickets()
{
    options = document.form2.seatingoptions.value;
    optionsarray = options.split(',');

    categories = document.form2.categories.value;
    categoriesarray = categories.split(',');
    totaltickets = 0;
     for (var i=0; i < optionsarray.length; i++) {

        option = replaceString(" ", "", optionsarray[i]);
        available = 0;
         for (j=0; j < document.form2.elements.length; j++)
         {

            if ((document.form2.elements[j].type == 'hidden') && (document.form2.elements[j].name == option ))
            {
                available = document.form2.elements[j].value;
                booked = 0;

                for (k=0; k < categoriesarray.length; k++)
                {
                    catname = "";
                    category = replaceString(" ", "", categoriesarray[k]);
                    catname = option+"_"+category;
                    for (l=0; l<document.form2.elements.length; l++)
                    {
                         if ((document.form2.elements[l].type == 'text')&& (document.form2.elements[l].name == catname ))
                         {
                                if (document.form2.elements[l].value == "")
                                {

                                     document.form2.elements[l].value = 0;
                                    document.form2.elements[l].focus();
                                }
                                if (IsNumeric(document.form2.elements[l].value)==false)
                        		{
                        			alert("Only Integer Values should be allowed for Quantity.");
                        			document.form2.elements[l].select();
                        			return false;
                        		}
                      		booked = parseInt(booked) + parseInt(document.form2.elements[l].value);
                            totaltickets = parseInt(totaltickets) + parseInt(booked);
                          }
                    }
                    if (parseInt(booked) > parseInt(available))
                    {
                     alert ("You should enter less than or equal to available tickets");
                     return false;
                    }
                }
            }
        }
   }
 if (parseInt(totaltickets) <= 0)
 {
     alert("Atleast one ticket should be booked");
     return false;
 }
return true;
}


//Function used inthe function CheckBookingTicktes
function replaceString(oldS, newS, fullS) {
// Replaces oldS with newS in the string fullS
   for (var i = 0; i < fullS.length; i++) {
      if (fullS.substring(i, i + oldS.length) == oldS) {
         fullS = fullS.substring(0, i) + newS + fullS.substring(i + oldS.length, fullS.length);
      }
   }
   return fullS;
}


/*
+----------------------------------------------------------------------+
| Buy Ticktes  related functions end                                   |
+----------------------------------------------------------------------+
*/


/*
+----------------------------------------------------------------------+
| Credit card checking related functions Start                         |
+----------------------------------------------------------------------+
*/

//Function for calling the subfunctions related to all fields
function checkCreditCardFields()
  {
    if(CheckCardNumber()==false)
        return false;
    if(CheckCardType()==false)
        return false;
    if(CheckCardName()==false)
        return false;
    if(CheckExpiryDate()==false)
        return false;
    return true;
  }

//Function for checking the Credit card number
function CheckCardNumber()
{
    if(Trim(document.form2.intCreditCardNumber.value) == "")
		{
			alert("Enter Transaction ID Number");
			document.form2.intCreditCardNumber.focus();
			return false;
		}

    /*if(IsNumeric(document.form2.intCreditCardNumber.value)==false)
		{
			alert("Only integer value is allowed in Transaction ID.");
			document.form2.intCreditCardNumber.select();
			return false;
		}*/

	/*if((document.form2.intCreditCardNumber.value.length) < 15)
		{
	   	    alert("Enter Valid Transaction ID");
	   	    document.form2.intCreditCardNumber.select();
		    return false;
		}*/
	return true;
}


//Function for checking the Credit card Type
function CheckCardType()
{
    if (document.form2.strCreditCardType.selectedIndex == 0)
		{
			alert("Please Select your Credit Card Type");
			document.form2.strCreditCardType.focus();
			return false;
		}
	return true;
}

//Function for checking the Credit card name
function CheckCardName()
{
    if(Trim(document.form2.strNameOnCard.value) == "")
		{
			alert("Enter valid name on Credit card");
			document.form2.strNameOnCard.focus();
			return false;
		}

   	if(checkchar(document.form2.strNameOnCard)==false)
		{

		    document.form2.strNameOnCard.select();
             return false;
       }
    return true;
}

//Function for checking the Credit card Expiry date
function CheckExpiryDate()
{
    cm=document.form2.cmonth.selectedIndex;
    cmv=parseInt(document.form2.cmonth[cm].value);
    cy=document.form2.cyear.selectedIndex;
    cyv=document.form2.cyear[cy].value;
   if ((cmv<parseInt(document.form2.month.value)) && (cyv<=parseInt(document.form2.year.value)))
   {
     alert ("Credit card expiry date should be more than the current date");
     return false;
    }
   return true;
}


/*
+----------------------------------------------------------------------+
| Credit card checking related functions end                           |
+----------------------------------------------------------------------+
*/


/*
+----------------------------------------------------------------------+
| Customer profile related functions start                             |
+----------------------------------------------------------------------+
*/

//Function for Validating all the Fields in the Create customer and edit profile of the Customer
function checkprofilefields()
{
        if(checkname()==false)
          return false;
        if(checklast()==false)
          return false;
        if(checkemail()==false)
          return false;
	   if(checkadd1()==false)
         return false;
        if(checkcity()==false)
          return false;
        if(checkstate()==false)
          return false;
        //if(checkzip()==false)
        // return false;
        if(checkphone()==false)
         return false;
         if(checkfax()==false)
            return false;
        if(checkpsw()==false)
          return false;
        if(checkrepsw()==false)
          return false;
		if(matchpsw()==false)
	 	{
	 		return false;
	 	}
 return true;
}


function matchpsw()
{
 var pass1=new String("");
 var pass2=new String("");
 pass1=document.form1.psw.value;
 pass2=document.form1.psw2.value;
 if(pass1==pass2)
  return true;
 else
 {
  alert("Password Mismatch");
  document.form1.psw.value="";
  document.form1.psw2.value="";
  document.form1.psw.focus();
  return false;
 }
}


function checkname()
{
 //check for first name field
 var name="First Name";
if(checkempty(document.form1.firstname,name)==true&&checkchar(document.form1.firstname,name)==true&&checklength(document.form1.firstname,name)==true)
     return(true);
 else
  {
   document.form1.firstname.value="";
   document.form1.firstname.focus();
   return false;
  }
}



function checklast()
{
 //check for first name field
 var name="Last Name";
if(checkempty(document.form1.lastname,name)==true&&checkchar(document.form1.lastname,name)==true&&checklength(document.form1.lastname,name)==true)
     return(true);
 else
  {
   document.form1.lastname.value="";
   document.form1.lastname.focus();
   return false;
  }
}
function checkemail()
{
 var name="User ID";
 if(checkempty(document.form1.email,name)==true&&emailcheck(document.form1.email)==true)
  return true
 else
 {
  document.form1.email.value="";
  document.form1.email.focus();
 return false;
 }
}

function checkadd1()
{
  var name="Address1";
if(checkempty(document.form1.add1,name)==true)
   return true;
 else
 {
  document.form1.add1.value="";
  document.form1.add1.focus();
  return false;
 }
}

function checkcity()
{
   var value1=document.form1.city.value;
  if(value1.toString()=="")
   {
   alert("City Needs to be Selected");
   document.form1.city.focus();
      return(false);
  }
  else
    return(true);
}
function checkstate()
{
   var value1=document.form1.state.value;
   
  if(value1.toString()=="None")
   {
   alert("State Needs to be Selected");
   
      return(false);
  }
  else
    return(true);
}
function checkzip()
{
  var name="Zip";
  if(checkempty(document.form1.zip.value,name)==true)
   return true;
  else
  {

    document.form1.zip.focus();
    return false;
  }
}
function checkphone()
{
 var name="Phone";
 if(checkempty(document.form1.phno,name)==true&&IsNumeric1(document.form1.phno.value,name)==true)
 return true;
 else
  {
       document.form1.phno.focus();
    document.form1.phno.value="";
       return(false);
  }
}
function checkfax()
{
 var name="Fax";
if(IsNumeric1(document.form1.fax.value,name)==true)
{
  if(document.form1.fax.value.length<=10)
    return true;
  else
  {
    alert("Fax Should be Smaller Than or Equal to 10 Characters");
    document.form1.fax.value="";
    document.form1.fax.focus();
    return false;
  }
}
else
  {
     document.form1.fax.focus();
    document.form1.fax.value="";
       return(false);
  }
}

function checkpsw()
{
  var name="Password";
 if(checkempty(document.form1.psw,name)==true&&checklength(document.form1.psw,name)==true)
  return true;
 else
 {
  document.form1.psw.value="";
  document.form1.psw.focus();
  return false;
 }
}
function checkrepsw()
{
  	var name="Retype Password";
  	if(checkempty(document.form1.psw2,name)==true&&checklength(document.form1.psw2,name)==true)
   		return true;
	 else
	 {
	  document.form1.psw2.value="";
	  document.form1.psw2.focus();
	  return false;
	 }
}


/*
+----------------------------------------------------------------------+
| Customer profile related functions end                               |
+----------------------------------------------------------------------+
*/



/*
+----------------------------------------------------------------------+
| General functions start                                              |
+----------------------------------------------------------------------+
*/

function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

//Function that checks the given value is numeric or not
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var Char;

   for (i = 0; i < sText.length; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
            return false;
         }
      }
   return true;
}

//Checking whether the field is empty or not
function checkempty(fieldname,name)
{
 var fieldvalue=Trim(fieldname.value);
   
 if(fieldvalue.toString()=="")
  {
    alert(name+" is a Required Field");
    return false;
  }
 else
  return true;
}

//Function for checking whether the given field contains charecters or not
function checkchar(fieldname)
{
    var fieldvalue=new String("");
    fieldvalue=fieldname.value;
	var snum;
	snum=fieldvalue.charAt(0);
	if(!((snum>='0')&&(snum<='9') || snum==" "))
	{
        for(i=0;i<fieldvalue.length;i++)
	    {
		  var single;
		  single=fieldvalue.charAt(i);
		  if(!((single>='A')&&(single<='Z')||(single>='a')&&(single<='z')||(single==" ")))
		  {
			 //	alert("Only letters,spaces and/or numbers may be used.");
				if (fieldname=="document.form2.strCreditCardType")
			        {
			           alert("Enter valid Credit card type.");
			        }
			    else if(fieldname==document.form1.City)
                    alert ("Enter valid City name");
			    else
			        alert ("Enter valid  Name");
                    return(false);
			            	break;
		 }

	             }
	     }
	else
	{
	   alert("First character cannot be a Number or space");
	    fieldname.value="";
	     return false;
    }
     return true;
}

//checking the numeric value including Decimal value
function IsNumeric1(sText,name)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
	  alert("Please Enter a Valid "+name);
         IsNumber = false;
         }
      }
   return IsNumber;

}

//Function for checking fields length
function checklength(fieldname,name)
{
    var fieldvalue=fieldname.value;
    var fieldlength=fieldvalue.length;
    //alert(fieldname.name);
    var minval=3;
    var maxval=20;

    if(fieldname.name=='psw')
    {
        minval=6;
        maxval=200;
    }

    if(fieldname.name=='add1')
    {
        minval=1;
        maxval=100;
    }

    if(fieldname.name=='psw2')
    {
        minval=6;
        maxval=200;
    }


    if(fieldname.name=='fax')
    {
        maxval=10;
        minval=5;
    }
    if(fieldname.name=='firstname')
    {
        minval=1;
        maxval=20;
    }
    if(fieldname.name=='lastname')
    {
        minval=1;
        maxval=20;
    }

    if(fieldlength<minval)
    {

        alert(name+" Should be Greater Than "+minval+" Characters");
        return(false);
    }

    if(fieldlength>maxval)
    {
        alert(name+" Should be Less Than "+maxval+" Characters");
        return(false);
    }
    return true;
}

//THIS FUNCTION TELLS IS THE ENTERED MAIL ID IS VALID ONE OR NOT? ****
function emailcheck (strFieldName)
{
        var emailStr=strFieldName.value
        var count=0;
        /*for(var i=0;i<emailStr.length-1;i++)
         {
          if(emailStr.charAt(i)=='@')
            break;
          count++;

         if(count>15)
         {
             alert("EmailId should be less than 15 characters");
              return false;
         }
 }*/


/* The following pattern is used to check if the entered e-mail address fits the user@domain  format. It also is used to separate the username from the domain. */
        var emailPat=/^(.+)@(.+)$/

/* The following string represents the pattern for matching all special characters.  We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */
        var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

/* The following string represents the range of characters allowed in a username or domainname.  It really states which chars aren't allowed. */
        var validChars="\[^\\s" + specialChars + "\]"

 /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney. com is a legal e-mail address. */
        var quotedUser="(\"[^\"]*\")"

 /* The following pattern applies for domains that are IP addresses, rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal   e-mail address. NOTE: The square brackets are required. */
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

 /* The following string represents an atom (basically a series of non-special characters.) */   	var atom=validChars + '+'
 /* The following string represents one word in the typical username.For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */
        var word="(" + atom + "|" + quotedUser + ")"

 // The following pattern describes the structure of the user
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

 /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into  different pieces that are easy to analyze. */

        var matchArray=emailStr.match(emailPat)
        var len=emailStr.length;
        if(len==0)
                return true
        if (matchArray==null)
	{
         /* Too many/few @'s or something; basically, this address doesn't
                even fit the general mould of a valid e-mail address. */

                alert("Incorrect Email address (check @ and .'s)")
                strFieldName.select()
                strFieldName.focus()
                return false
        }
        var user=matchArray[1]
        var domain=matchArray[2]

        // See if "user" is valid
        if (user.match(userPat)==null)
	{
                // user is not valid
                alert("Invalid UserName.")
                strFieldName.select()
                strFieldName.focus()
                return false
        }

        /* if the e-mail address is at an IP address (as opposed to a symbolic
                host name) make sure the IP address is valid. */
        var IPArray=domain.match(ipDomainPat)
        if (IPArray!=null)
	 {
                // this is an IP address                                                                        for (var i=1;i<=4;i++)
		{
                        if (IPArray[i]>255)
                        {
                            alert("Destination IP address is invalid!")
                            strFieldName.select()
                                strFieldName.focus()
                                return false
                        }
                }
                return true
        }

        // Domain is symbolic name
        var domainArray=domain.match(domainPat)
        if (domainArray==null)
	{
                alert("Invalid Domain Name")
                strFieldName.select()
                strFieldName.focus()
                return false
        }

        /* domain name seems valid, but now make sure that it ends in a three-letter word (like          com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a 		hostname preceding the domain or country. */

        /* Now we need to break up the domain to get a count of how many atoms
                it consists of. */
        var atomPat=new RegExp(atom,"g")
        var domArr=domain.match(atomPat)
        var len=domArr.length
        if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
        {
                // the address must end in a two letter or three letter word.
            alert("The address must end in a three-letter domain, or two letter country.")
                strFieldName.select()
                strFieldName.focus()
                return false
        }

        // Make sure there's a host name preceding the domain.
        if (len<2)
        {
                        var errStr="This address is missing a hostname!"
                alert(errStr)
                strFieldName.select()
                strFieldName.focus()
                return false
        }

        // If we've gotten this far, everything's valid!
        return true;
}
/*
+----------------------------------------------------------------------+
| General functions end                                                |
+----------------------------------------------------------------------+
*/

/*
+----------------------------------------------------------------------+
| Functions for Login Checkings starts                                 |
+----------------------------------------------------------------------+
*/


function ValidateEmailId()
{
 //returns true or false after validation of emailid and password

  if(check1()==true && check2()==true)
    return(true);
   else
  return(false);
}

function check1()
{
    var email=document.loginform.email;
    var name="User ID";
     if(checkempty(document.loginform.email,name)==true&&emailcheck(document.loginform.email)==true)
      return true
     else
     {
      document.loginform.email.value="";
      document.loginform.email.focus();
     return false;
     }
}

//check2 for validation of password
function check2()
{
    var psw=document.loginform.psw.value;
    if(psw.toString()=="")
    {
     alert("Please Enter a Password");
     document.loginform.psw.focus();
    }
   else
   {
    if(checkpassword()==false)
      return(false);
    else
       return(true);
   }

}


function checkpassword()
{
 var psw=document.loginform.psw.value;
 //checks for length of password
     if(psw.length<6)
      {
        alert("Password Needs To be More Than 6  Characters ");
        document.loginform.psw.focus();
        document.loginform.psw.value="";
        return(false);
      }
      else
	  {
	    var val1=new String("");
	    val1=document.loginform.psw.value;
	    for(i=0;i<val1.length;i++)
	    {
	      if(val1.charAt(i)==" ")
	      {
	        alert("Password Cannot Contains Spaces");
	        document.loginform.psw.value="";
	        document.loginform.psw.focus();
	        return false;
	        break;
	      }
	    }
	    return true;
	  }
       return true;
}


/*
+----------------------------------------------------------------------+
| Functions for Login Checkings ends                                   |
+----------------------------------------------------------------------+
*/

/*
+----------------------------------------------------------------------+
| Functions for forgotpassword fields starts                           |
+----------------------------------------------------------------------+
*/

function checkforgetpasswordemail()
{

    var email=document.form1.email;
    var name="Email Id";
     if(checkempty(document.form1.email,name)==true&&emailcheck(document.form1.email)==true)
      return true
     else
     {
      document.form1.email.value="";
      document.form1.email.focus();
     return false;
   }
}

function checkforgetpasswordfields()
{
 if(checkforgetpasswordemail()==false)
  return false;
 return true;
}

/*
+----------------------------------------------------------------------+
| Functions for forgotpassword fields ends                             |
+----------------------------------------------------------------------+
*/


