var dtCh= "/";
var minYear=1960;
var maxYear=2100;

function Trim( str ) {
   for( i=0; i < str.length; i++ ) {
      if(str.charAt(i) != " ") break;
   }
   for( j=str.length - 1; j >= 0; j-- ) {
      if(str.charAt(j) != " ") break;
   }
   if( i == str.length ) {
      str="";
   }
   else {
      str=str.substring(i,j+1);
   }
   return str;
}

function validno( numvar ) {
   var len=numvar.length;
   if( ( numvar.substring( 0, 1 ) == " " ) || ( numvar.substring( len-1, len ) == " " ) )
      return false;
   for( var i=0; i<len; i++ ) {
      if( !( numvar.substring( i, i+1 ) >= '0' && numvar.substring( i, i+1 ) <= '9' ) )
         return false;
   }
   return true;
}

function validnostring( charvar ) {
   var len=charvar.length;
   if( ( charvar.substring( 0, 1 ) == " " ) || ( charvar.substring( len-1, len ) == " " ) )
      return false;
   for( var i=0; i<len; i++ ) {
      if( ( !( charvar.substring( i, i+1 ) >= '0' && charvar.substring( i, i+1 ) <= '9' ) ) &&
          ( !( charvar.substring( i, i+1 ) == ',' || charvar.substring( i, i+1 ) == '/' ) ) )
          return false;
   }
   return true;
}

function validchar( charvar ) {
   var len=charvar.length;
   if( ( charvar.substring( 0, 1 ) == " " ) || ( charvar.substring( len-1, len ) == " " ) )
      return false;
   for( var i=0; i<len; i++ ) {
      if( ( !( charvar.substring( i, i+1 ) >= '0' && charvar.substring( i, i+1 ) <= '9' ) ) &&
          ( !( charvar.substring( i, i+1 ) >= 'a' && charvar.substring( i, i+1 ) <= 'z' ) ) &&
          ( !( charvar.substring( i, i+1 ) >= 'A' && charvar.substring( i, i+1 ) <= 'Z' ) ) )
          return false;
   }
   return true;
}

function check_textbox( form_name, element_name, element_msg ) {
   value_var = "document."+form_name+"."+element_name+".value";
   res_value_var = eval( value_var );
   if( !Trim( res_value_var ) ) {
      alert("Please enter the " + element_msg );
      focus_var = "document."+form_name+"."+element_name+".focus()";
      eval(focus_var);
      return false;
   }
   return true;
}

function check_select( form_name, element_name, element_msg ) {
  value_var = "document."+form_name+"."+element_name+".options[document."+form_name+"."+element_name+".selectedIndex].value";
   res_value_var = eval( value_var );
   if( !Trim ( res_value_var ) ) {
      alert("Please select the " + element_msg );
      focus_var = "document."+form_name+"."+element_name+".focus()";
      eval(focus_var);
      return false;
   }
   return true;
}

function ispastdate( value1, value2 ) {
//used to check whether the date1 ie value1 is less than date2 ie value2
var date1, date2;
var month1, month2;
var year1, year2;
date1 = value1.substring (0, value1.indexOf ("/"));
date1 = eval(date1);
month1 = value1.substring (value1.indexOf ("/")+1, value1.lastIndexOf("/"));
month1 = eval(month1);
year1 = value1.substring (value1.lastIndexOf ("/")+1, value1.length);
year1 = eval(year1);
date2 = value2.substring (0, value2.indexOf ("/"));
date2 = eval(date2);
month2 = value2.substring (value2.indexOf ("/")+1, value2.lastIndexOf("/"));
month2 = eval(month2);
year2 = value2.substring (value2.lastIndexOf ("/")+1, value2.length);
year2 = eval(year2);
if (year1 > year2) return 1;
else if (year1 < year2) return -1;
else if (month1 > month2) return 1;
else if (month1 < month2) return -1;
else if (date1 > date2) return 1;
else if (date1 < date2) return -1;
else return 0;
}

function isInteger( s ) {
   var i;
   for( i = 0; i < s.length; i++ ) {
      // check that current character is number.
      var c = s.charAt(i);
      if( ( ( c < "0" ) || ( c > "9" ) ) ) return false;
   }
   return true;
}

function isDate( dtStr ) {
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1) {
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]) {
                alert("Please enter a valid day")
                return false
        }
	if (strMonth.length<1 || month<1 || month>12) {
		alert("Please enter a valid month")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear) {
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false) {
		alert("Please enter a valid date")
		return false
	}
	return true
}

function Validatedate( datetocheck ) {
   if( isDate(datetocheck)==false ) {
      return false
   }
   return true
}

function stripCharsInBag( s, bag ) {
   var i;
   var returnString = "";
   // Search through string's characters one by one. If character is not in bag, append to returnString.
   for(i = 0; i < s.length; i++ ) {
      var c = s.charAt(i);
      if( bag.indexOf(c) == -1 ) returnString += c;
   }
   return returnString;
}

function daysInFebruary( year ) {
// February has 29 days in any year evenly divisible by four, EXCEPT for centurial years which are not also divisible by 400.
    return ( ( ( year % 4 == 0 ) && ( ( ! ( year % 100 == 0 ) ) || ( year % 400 == 0 ) ) ) ? 29 : 28 );
}

function DaysArray( n ) {
   for (var i = 1; i <= n; i++) {
      this[i] = 31
      if( i==4 || i==6 || i==9 || i==11 ) { this[i] = 30 }
       if( i==2 ) { this[i] = 29 }
   }
   return this
}

function onlyNumbers(e) {
        var key;
        var keychar;
        var reg;
        if(window.event) {
                // for IE, e.keyCode or window.event.keyCode can be used
                key = e.keyCode;
        }
        else if(e.which) {
                // netscape
                key = e.which;
        }
        else {
                // no event, so pass through
                return true;
        }
        keychar = String.fromCharCode(key);
        reg = /\d/;
        return reg.test(keychar);
}

function checkemailid( emailid ) {
   var check = "pass"
   emailarraylist = emailid.split(","); 
   for (var i=0; i<emailarraylist.length; i++)
   {
       emailarray = Trim(emailarraylist[i]).split("@");
       if( emailarray.length != 2 ) {
           check="fail";
       }
       else {
           if( emailarray[0].search("^[A-Za-z0-9]" ) == -1 ) check="fail";//End of name needs alphanumeric
           if( emailarray[0].search("[A-Za-z0-9]$" ) == -1 ) check="fail";//dot, dash and underscore are ok, but only in middle of name
           if( emailarray[0].search("[\.\_\-]+") > 0 ) {
               if( emailarray[0].search("[A-Za-z0-9][\.\_\-][A-Za-z0-9]+$") == -1 ) check="fail";}
           if( emailarray[1].search("^[A-Za-z0-9][A-Za-z0-9\-]+[\.]+[A-Za-z0-9]{2,}") == -1 ) check="fail";
           if( emailid.indexOf("..") >= 0 ) check = "fail";// Two dots together not allowed
       }
       if( check == "fail" ) {
          alert( "Please enter a valid email address" );
          return false;
       }
   }
   return true;
}

function checktextarea( form ) {
   if( !Trim( form.comment.value ) ) {
      alert( "Please enter the comment" );
      form.comment.focus();
      return false;
   }
   return true;
}

function pricecalculation() {
   if( !check_textbox( "buysupportform", "nooftickets", "number of tickets" ) ) {
      return false;
   }
   if( document.buysupportform.nooftickets.value < 200 ) {
      alert("No of tickets should be greater than 200");
      document.buysupportform.nooftickets.focus();
      return false;
   }
   if( !validno( document.buysupportform.nooftickets.value) ) {
      alert("Please enter a numeric value");
      document.buysupportform.nooftickets.focus();
      return false;
   }
   var nooftickets = document.buysupportform.nooftickets.value;
   var service_tax = document.buysupportform.service_tax.value;
   var oneticketprice = document.buysupportform.oneticketprice.value;
   var amount = nooftickets * oneticketprice;
   var amount_withtax = amount + ( service_tax * amount ) / 100;
   amount_withtax = Math.round( amount_withtax );
   document.buysupportform.amount.value = amount;
   document.buysupportform.amount_withtax.value = amount_withtax;
   return true;
}

function whatstheprice() {
   document.buysupportform.amount_withtax.value = "";
   pricecalculation();
}

function checkbuysupport() {
   if( document.buysupportform.loginid ) {
      if( !check_select( "buysupportform", "loginid", "company name") ) {
         return false;
      }
   }
   if( ! pricecalculation() ) return false;
   if( ( document.buysupportform.paymode[0].checked == false ) && ( document.buysupportform.paymode[1].checked == false ) && ( document.buysupportform.paymode[2].checked == false ) ) {
      alert("Please select the payment mode");
      return false;
   }
   if( document.buysupportform.paymode[0].checked == true ) {
      if( confirm("Payment by Cash" ) ) {
         return true;
      }
      else return false;
   }
   if( document.buysupportform.paymode[1].checked == true ) {
      if( document.buysupportform.dd_no ) {
         if( !check_textbox( "buysupportform", "dd_no", "DD/Cheque number" ) ) {
            return false;
         }
      }
      if( document.buysupportform.dd_date ) {
         if( !check_textbox( "buysupportform", "dd_date", "DD/Cheque date" ) ) {
            return false;
         }
      }
      if( document.buysupportform.dd_amount ) {
         if( !check_textbox( "buysupportform", "dd_amount", "DD/Cheque amount" ) ) {
            return false;
         }
      }
      if( document.buysupportform.bank_name ) {
         if( !check_textbox( "buysupportform", "bank_name", "bank name" ) ) {
            return false;
         }
      }
      if( confirm("Payment by DD/Cheque" ) ) {
         return true;
      }
      else return false;
   }
   if( document.buysupportform.paymode[2].checked == true ) {
      if( confirm("Payment by Credit Card" ) ) {
         return true;
      }
      else return false;
   }
   return true;
}

function checkpaysupport() {
   if( !check_textbox( "paysupportform", "dd_no", "DD/Cheque number" ) ) {
      return false;
   }
   if( !check_textbox( "paysupportform", "dd_date", "DD/Cheque date" ) || !Validatedate( document.paysupportform.dd_date.value ) ) {
      return false;
   }
   if( !check_textbox( "paysupportform", "bank_name", "bank name" ) ) {
      return false;
   }
   return true;
}

function cash_paymode() {
   if( document.buysupportform.dd_no ) {
      document.buysupportform.dd_no.value= "";
      document.buysupportform.dd_no.disabled=true;
   }
   if( document.buysupportform.dd_date ) {
      document.buysupportform.dd_date.value= "";
      document.buysupportform.dd_date.disabled=true;
   }
   if( document.buysupportform.dd_amount ) {
      document.buysupportform.dd_amount.value= "";
      document.buysupportform.dd_amount.disabled=true;
   }
   if( document.buysupportform.bank_name ) {
      document.buysupportform.bank_name.value= "";
      document.buysupportform.bank_name.disabled=true;
   }
}

function cheque_paymode() {
   if( document.buysupportform.dd_no ) {
      document.buysupportform.dd_no.disabled=false;
   }
   if( document.buysupportform.dd_date ) {
      document.buysupportform.dd_date.disabled=false;
   }
   if( document.buysupportform.dd_amount ) {
      document.buysupportform.dd_amount.disabled=false;
   }
   if( document.buysupportform.bank_name ) {
      document.buysupportform.bank_name.disabled=false;
   }
}

function approvetrans( transid, loginid ) {
   if( confirm( "You are proceeding to approve the transaction" ) ) {
      location = "index.php?task=approvetrans&transid="+transid+"&loginid="+loginid;
   }
}

function deletetrans( transid ) {
   if( confirm( "Are you sure you want to delete the transaction?" ) ) {
      location = "index.php?task=deletetransaction&transid="+transid;
   }
}

function delete_timeouttrans( transid ) {
   if( confirm( "Are you sure you want to delete the transaction?" ) ) {
      location = "index.php?task=delete_timeouttransaction&transid="+transid;
   }
}

function checkpendingdays() {
   if( !check_textbox( "form", "days", "number of days" ) ) {
      return false;
   }
   if( !validno( document.form.days.value) ) {
      alert("Please enter a numeric value");
      document.form.days.focus();
      return false;
   }
   return true;
}

function checksearch() {
   if( document.searchform.soptiondate.checked == true ) {
      if( !Trim( document.searchform.datefrom.value ) || !Validatedate( document.searchform.datefrom.value ) ) {
         alert("Please enter the start date");
         document.searchform.datefrom.focus();
         return false;
      }
      if( !Trim( document.searchform.dateto.value ) || !Validatedate( document.searchform.dateto.value ) ) {
         alert("Please enter the end date");
         document.searchform.dateto.focus();
         return false;
      }
      var date1 = document.searchform.datefrom.value;
      var date2 = document.searchform.dateto.value;
      if( ispastdate( date1, date2 ) == 1 ) {
         alert("Please check the 'from' and 'to' dates");
         return false;
      }
   }
   if( document.searchform.soptionname ) {
      if( document.searchform.soptionname.checked == true ) {
         if( !check_textbox( "searchform", "name", "name to be searched" ) ) {
            return false;
         }
      }
   }
   return true;
}

function checksearchticket() {
   if( !check_textbox( "form", "searchkey", "search word" ) ) {
      return false;
   }
   return true;
}

function checkentity() {
   if( !check_textbox( "form", "loginname", "login name" ) ) {
      return false;
   }
   if( document.form.loginname.value.length < 5 ) {
      alert("Login name should be 5 characters");
      document.form.loginname.focus();
      return false;
   }
   if( !check_textbox( "form", "location", "location" ) ) {
      return false;
   }
   if( !check_textbox( "form", "salutation", "salutation" ) ) {
      return false;
   }
   if( !check_textbox( "form", "contactname", "contact name" ) ) {
      return false;
   }
   if( !check_textbox( "form", "title", "designation" ) ) {
      return false;
   }
   if( !check_textbox( "form", "email", "email" ) ) {
      return false;
   }
   if( !checkemailid(document.form.email.value) ) {
      document.form.email.focus();
      return false;
   }
   if( document.form.cellno.value == "" || !validnostring( document.form.cellno.value ) || ( document.form.cellno.value.length < 7 ) ) {
      alert("Please enter phone number");
      document.form.cellno.focus();
      return false;
   }
   if( document.form.level ) {
      if( !check_select( "form", "level", "level") ) {
         return false;
      }
   }
   return true;
}

function selectinstallation() {
   if( !check_select( "techform", "customerid", "installation") ) {
      return false;
   }
   return true;
}

function checknewregistration() {
   if( !check_select( "newregform", "reason", "reason for registration") ) {
      return false;
   }
   if( !check_select( "newregform", "salutation", "salutation") ) {
      return false;
   }
   if( !check_textbox( "newregform", "name", "name" ) ) {
      return false;
   }
   if( !check_textbox( "newregform", "title", "designation" ) ) {
      return false;
   }
   if( !check_textbox( "newregform", "companyname", "company name" ) ) {
      return false;
   }
   if( !check_textbox( "newregform", "add1", "address" ) ) {
      return false;
   }
   if( !check_textbox( "newregform", "location", "city" ) ) {
      return false;
   }
   if( !check_textbox( "newregform", "pincode", "pincode" ) ) {
      return false;
   }
   if( !check_textbox( "newregform", "country", "country" ) ) {
      return false;
   }
   if( document.newregform.cellno.value == "" || !validnostring( document.newregform.cellno.value ) || ( document.newregform.cellno.value.length < 7 ) ) {
      alert( "Please enter phone number" );
      document.newregform.cellno.focus();
      return false;
   }
   if( !check_textbox( "newregform", "email", "email" ) ) {
      return false;
   }
   if( !checkemailid(document.newregform.email.value) ) {
      document.newregform.email.focus();
      return false;
   }
   if( !check_textbox( "newregform", "loginname", "loginname" ) ) {
      return false;
   }
   if( !validchar(document.newregform.loginname.value) ) {
      alert("Loginname should not contain special characters");
      document.newregform.loginname.focus();
      return false;
   }
   if( document.newregform.loginname.value.length < 5 ) {
      alert("Login name should be 5 characters");
      document.newregform.loginname.focus();
      return false;
   }
   return true;
}

function generatelicense() {
   if( document.details.global_domainname ) {
      if( !check_textbox( "details", "global_domainname", "Global Domain Name for generating License key" ) ) {
         return false;
      }
      if( ( document.details.global_domainname.value == "" ) || ( document.details.global_domainname.value.indexOf("") == -1 ) || ( document.details.global_domainname.value.indexOf(".") ==-1 ) ) {
         alert("Check Global Domain Name ");
         document.details.global_domainname.focus();
         return false;
      }
   }
   if( document.details.noofusers ) {
      if( !Trim( document.details.noofusers.value ) || ! validno( document.details.noofusers.value ) ) {
         alert("Enter the Number of Users for generating License key");
         document.details.noofusers.focus();
         return false;
      }
   }
   if( document.details.product_version.value <= 4 ) {
      myWin=window.open("http://license.carizen.co.in/licenseeditold.php?&usr="+document.details.noofusers.value+ "&glo="+document.details.global_domainname.value+ "&ema="+document.details.email_domainname.value);
      // closeIt();
   }
   else {
      var h = '';
      if( document.details.mods[11].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[10].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[9].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[6].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[4].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[5].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[3].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[2].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[7].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[8].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[12].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[1].checked == true ) h = h +'1' ;
      else h = h +'0' ;
      if( document.details.mods[0].checked == true ) h = h +'1' ;
      else h = h +'0' ; 
      
      document.details.license_module.value = h;
      
      myWin=window.open("http://license.carizen.co.in/licenseedit.php?mod="+document.details.license_module.value+"&usr="+document.details.noofusers.value+ "&glo="+document.details.global_domainname.value+ "&ema="+document.details.email_domainname.value);
      //closeIt();
   }
}

function closeIt() {
   if( !myWin.closed )
   setTimeout( "myWin.self.close()", 3000 )//adjust timing
}

function checkcustediting() {
   if( document.details.loginname ) {
      if( !check_textbox( "details", "loginname", "login name" ) ) {
         return false;
      }
      if( document.details.loginname.value.length < 5 ) {
         alert("Login name should be 5 characters");
         document.details.loginname.focus();
         return false;
      }
   }
   if( document.details.cname ) {
      if( !check_textbox( "details", "cname", "company name" ) ) {
         return false;
      }
   }
   if( document.details.salutation ) {
      if( !check_textbox( "details", "salutation", "salutation" ) ) {
         return false;
      }
   }
   if( document.details.contactname ) {
      if( !check_textbox( "details", "contactname", "contact name" ) ) {
         return false;
      }
   }
   if( document.details.title ) {
      if( !check_textbox( "details", "title", "designation" ) ) {
         return false;
      }
   }
   if( document.details.add1 ) {
      if( !check_textbox( "details", "add1", "address" ) ) {
         return false;
      }
   }
   if( document.details.location ) {
      if( !check_textbox( "details", "location ", "city" ) ) {
         return false;
      }
   }
   if( document.details.pincode ) {
      if( !check_textbox( "details", "pincode", "pincode" ) ) {
         return false;
      }
   }
   if( document.details.country ) {
      if( !check_textbox( "details", "country", "country" ) ) {
         return false;
      }
   }
   if( document.details.email ) {
      if( !check_textbox( "details", "email", "email" ) ) {
         return false;
      }
      if( !checkemailid(document.details.email.value) ) {
         document.details.email.focus();
         return false;
      }
   }
   if( document.details.cellno ) {
      if( document.details.cellno.value == "" || !validnostring( document.details.cellno.value ) || ( document.details.cellno.value.length < 7 ) ) {
         alert("Please enter phone number");
         document.details.cellno.focus();
         return false;
      }
   }
   if( document.details.id_branch ) {
      if( !check_select( "details", "id_branch", "carizen branch name" ) ) {
         return false;
      }
   }
   if( document.details.location_nickname ) {
      if( !check_textbox( "details", "location_nickname", "installation location" ) ) {
         return false;
      }
   }
   if( document.details.loginacc ) {
      if( !check_textbox( "details", "loginacc", "login account" ) ) {
         return false;
      }
   }
   if( document.details.cloginpwd ) {
      if( !check_textbox( "details", "cloginpwd", "login password" ) ) {
         return false;
      }
   }
   if( document.details.rootpwd ) {
      if( !check_textbox( "details", "rootpwd", "root password" ) ) {
         return false;
      }
   }
   if( document.details.processor ) {
      if( !check_textbox( "details", "processor", "Processor" ) ) {
         return false;
      }
   }
   if( document.details.ram ) {
      if( !check_textbox( "details", "ram", "RAM" ) ) {
         return false;
      }
   }
   if( document.details.hdd ) {
      if( !check_textbox( "details", "hdd", "HDD" ) ) {
         return false;
      }
   }
   if( document.details.conntype ) {
      if( !check_select( "details", "conntype", "connectivity type" ) ) {
         return false;
      }
      if( document.details.conntype.value=='2' ) {
         if( !check_textbox( "details", "staticip", "static Ip" ) ) {
            return false;
         }
      }
   }
   if( document.details.monitor ) {
      if( !check_textbox( "details", "monitor", "Monitor" ) ) {
         return false;
      }
   }
   if( document.details.nic ) {
      if( !check_textbox( "details", "nic", "NIC" ) ) {
         return false;
      }
   }
   if( document.details.product ) {
      if( !check_textbox( "details", "product", "Product " ) ) {
         return false;
      }
   }
   if( document.details.product.value != '7' ) {
      if( document.details.product_version ) {
         if( !check_textbox( "details", "product_version", "Product version" ) ) {
            return false;
         }
         if( !check_textbox( "details", "product_release", "product Release" ) ) {
            return false;
         }
         if( ! ( ( document.details.product_version.value == '6' ) || ( document.details.product_version.value == '7' ) || (document.details.product_version.value == '8') || ( document.details.product_version.value == '9' ) ) ) {
            if( document.details.product_release.value != -1 ) {
               alert( "Please Select Valid Release" );
               document.details.product_release.focus();
               return false;
            }
         }
         else if( document.details.product_version.value=='7' ) {
            if( ( document.details.product_release.value != '24' ) && ( document.details.product_release.value != '25' ) && (document.details.product_release.value != '26') && ( document.details.product_release.value != '27') ) {
               alert( "For Version 1.9 Select release 1000019 or 1000020 or 1000021 or 1000022" );
               document.details.product_release.focus();
               return false;
             }
         }
         else if( document.details.product_version.value=='8' ) {
            if( ( document.details.product_release.value != '28' )  ) {
               alert( "For Version 2.0 Select release 1000024" );
               document.details.product_release.focus();
               return false;
             }
         }
         else if( document.details.product_version.value=='9' ) {
            if( ( document.details.product_release.value != '29' )  ) {
               alert( "For Version 2.1 Select release 1000026" );
               document.details.product_release.focus();
               return false;
             }
         }
         else {
            if( ( document.details.product_release.value == '24') || (document.details.product_release.value == '25') || (document.details.product_release.value == '26') || (document.details.product_release.value == '27') || (document.details.product_release.value == '28') || (document.details.product_release.value == '29') || ( document.details.product_release.value == '-1') ) {
               alert( "For Version 1.8 Select releases from 1000000 to 1000017" );
               document.details.product_release.focus();
               return false;
            }
         }
      }
   }
   else {
      if( document.details.product_version.value != '' ) {
         alert( "No need to enter the version" );
         document.details.product_version.focus();
         return false;
      }
      if( document.details.product_release.value != '' ) {
         alert(" No need to enter the release");
         document.details.product_release.focus();
         return false;
      }
   }
   if( document.details.musername ) {
      if( !check_textbox( "details", "musername", "mail server user name" ) ) {
         return false;
      }
   }
   if( document.details.mpassword ) {
      if( !check_textbox( "details", "mpassword", "mail server password" ) ) {
         return false;
      }
   }
   if ( document.details.edit_type.value == "" ) {
      if( document.details.global_domainname ) {
         if( !check_textbox( "details", "global_domainname", "Global Domain Name" ) ) {
            return false;
         }
         if( ( document.details.global_domainname.value == "" ) || ( document.details.global_domainname.value.indexOf( "" ) == -1 ) || ( document.details.global_domainname.value.indexOf(".") == -1 ) ) {
            alert("Check Global Domain Name ");
            document.details.global_domainname.focus();
            return false;
         }
      }
      if( document.details.noofusers ) {
         if( !Trim( document.details.noofusers.value ) || ! validno( document.details.noofusers.value ) ) {
            alert("Enter the Number of Users");
            document.details.noofusers.focus();
            return false;
         }
      }
   }
   if( document.details.support_date ) {
      var t;
      if( document.details.support[0].checked ) t=1;
      else t=0;
      if( t== 1 ) {
         if( !Validatedate( document.details.support_date.value ) ) {
            return false;
         }
         if( ispastdate( document.details.today.value, document.details.support_date.value ) == 1 ) {
            alert("Support date should not be less than the current date");
            document.details.support_date.focus();
            return false;
         }
      }
      else {
         if( document.details.support_date.value != '00/00/0000' ) {
             if( !Validatedate( document.details.support_date.value ) ) {
                return false;
             }
             if( ispastdate( document.details.support_date.value, document.details.today.value ) == 1 ) {
               alert("Support date Must be less than the current date");
               document.details.support_date.focus();
               return false;
            }
         }
      }
      if( t != document.details.actualsupport.value ) {
         if( document.details.support_date.value == document.details.actualsupportdate.value ) {
            alert( "Please enter new support date" );
            document.details.support_date.focus();
            return false;
         }
      }
   }
   if( document.details.upgrade_date ) {
      var r;
      if( document.details.upgrade[0].checked ) r=1;
      else r=0;
      if( r == 1 ) {
         if( document.details.upgrade_date.value != '00/00/0000' ) {
            if( !Validatedate( document.details.upgrade_date.value ) ) {
               return false;
            }
         }
         if( ispastdate( document.details.today.value, document.details.upgrade_date.value ) == 1 ) {
            alert("Upgrade date should not be less than the current date");
            document.details.upgrade_date.focus();
            return false;
         }
      }
      else {
         // No need to consider the date
          if( document.details.upgrade_date.value != '00/00/0000' ) {
             if( !Validatedate( document.details.upgrade_date.value ) ) {
                return false;
             }
             if( ispastdate( document.details.upgrade_date.value, document.details.today.value ) == 1 ) {
                alert("Upgrade date Must be less than the current date");
                document.details.upgrade_date.focus();
                return false;
             }
          }
       }
       if( r != document.details.actualupgrade.value ) {
         if(document.details.upgrade_date.value == document.details.actualupgradedate.value ) {
            alert( "Please enter new upgrade date" );
            document.details.upgrade_date.focus();
            return false;
          }
       }
   }
   if( document.details.licence_key ) {
      if ( document.details.edit_type.value == "" ) {
         if( !Trim( document.details.licence_key.value ) || ( document.details.licence_key.value.length < 32 ) ) {
            if( document.details.licence_key.value.length != 13 ) {
               alert("Enter the License Key");
               document.details.licence_key.focus();
               return false;
            }
         }
      }
   }
   if ( document.details.task_old.value == "seeditcustomer" ) {
      if( !check_textbox( "details", "comments", "customization comment" ) ) {
         return false;
      }
   }
   if( document.details.techanical_comments ) {
      if( !check_textbox( "details", "techanical_comments", "reason for editing" ) ) {
         return false;
      }
      if ( document.details.techanical_comments.value.length < 10 ) {
         alert("Reason for editing must be greater than 10 character");
         document.details.techanical_comments.focus();
         return false;
      }
   }
   var m='';
   for( i=0; i<document.details.mods.length; i++ ) {
      if( document.details.mods[i].checked == true ) {
         m = m + document.details.mods[i].value;
      }
   }
   document.details.modules.value = m;
   m=","+m;
   return true;
}

function checkremoveentity( loginid, entityid ) {
   if( confirm( "Delete this entity after getting the approval from Sri Krishnan Sir" ) ) {
      if( confirm( "Warning! Information associated with this entity will also be deleted. Do you want to delete the entity details?" ) ) {
         location ="index.php?task=removeentity&loginid="+loginid+"&entityid="+entityid;
      }
   }
}

function checknewemployee() {
   if( document.add_emp.entityid ) {
      if( !check_select( "add_emp", "entityid", "employee type") ) {
         return false;
      }
   }
   if( document.add_emp.branchid ) {
      if( !check_select( "add_emp", "branchid", "branch") ) {
         return false;
      }
   }
   if( document.add_emp.loginname ) {
      if( !check_textbox( "add_emp", "loginname", "login name" ) ) {
         return false;
      }
      if( document.add_emp.loginname.value.length < 5 ) {
         alert("Login name should be 5 characters");
         document.add_emp.loginname.focus();
         return false;
      }
      if( !validchar(document.add_emp.loginname.value) ) {
         alert("Loginname should not contain special characters");
         document.add_emp.loginname.focus();
         return false;
      }
   }
   if( document.add_emp.loginpwd ) {
      if( !check_textbox( "add_emp", "loginpwd", "login password" ) ) {
         return false;
      }
      if( !validchar(document.add_emp.loginpwd.value) ) {
         alert("Login Password should not contain special characters");
         document.add_emp.loginpwd.focus();
         return false;
      }
      if( document.add_emp.loginpwd.value.length < 6 ) {
         alert("Password should be 6 characters");
         document.add_emp.loginpwd.focus();
         return false;
      }
   }
   if( document.add_emp.cloginpwd ) {
      if( !check_textbox( "add_emp", "cloginpwd", "confirm login password" ) ) {
         return false;
      }
      if( document.add_emp.loginpwd.value != document.add_emp.cloginpwd.value ) {
         alert("Login password and confirm login password should be same");
         document.add_emp.cloginpwd.focus();
         return false;
      }
   }
   if( !check_textbox( "add_emp", "companyname", "company name" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "salutation", "salutation" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "contactname", "contact name" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "title", "designation" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "add1", "address" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "location", "city" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "pincode", "pincode" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "country", "country" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "email", "email" ) ) {
      return false;
   }
   if( !checkemailid(document.add_emp.email.value) ) {
      document.add_emp.email.focus();
      return false;
   }
   if( ( document.add_emp.cellno.value == "" ) || !validnostring( document.add_emp.cellno.value ) || ( document.add_emp.cellno.value.length < 7 ) ) {
      alert("Please enter phone number");
      document.add_emp.cellno.focus();
      return false;
   }
   if( !check_textbox( "add_emp", "fathername", "father's name" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "dob", "date of birth" ) || !Validatedate( document.add_emp.dob.value ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "pob", "place of birth" ) ) {
      return false;
   }
   if( document.add_emp.marital[0].checked == true ) {
      if( !check_textbox( "add_emp", "spousename", "spouse name" ) ) {
         return false;
      }
   }
   if( document.add_emp.marital[1].checked == true ) {
      if( document.add_emp.spousename.value.length > 0 ) { 
         alert("spouse name should be blank");
         document.add_emp.spousename.focus();
         return false;
      }
   }
   if( !check_textbox( "add_emp", "pemail", "personal email" ) ) {
      return false;
   }
   if( !checkemailid(document.add_emp.pemail.value) ) {
      document.add_emp.pemail.focus();
      return false;
   }
   if( document.add_emp.p_address.checked == false ) {
      document.add_emp.p_address.value=0;
      if( !check_textbox( "add_emp", "p_add1", "permanent address" ) ) {
         return false;
      }
      if( !check_textbox( "add_emp", "p_location", "city" ) ) {
         return false;
      }
      if( !check_textbox( "add_emp", "p_pincode", "pincode" ) ) {
        return false;
      }
      if( !check_textbox( "add_emp", "p_country", "country" ) ) {
         return false;
      }
   }
   else {
      document.add_emp.p_address.value=1;
   }
   if( !check_textbox( "add_emp", "qualification", "degree/diploma" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "institution", "institution" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "marks", "marks" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "l_speak", "languages known to speak" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "l_read", "languages known to read" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "l_write", "languages known to write" ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "new_salary", "salary" ) ) {
      return false;
   }
   if( !validno( document.add_emp.new_salary.value ) ) {
      alert("Enter numerical value of salary");
      document.add_emp.new_salary.focus();
      return false;
   }
   if( !check_textbox( "add_emp", "new_doj", "date of joining" ) || !Validatedate( document.add_emp.new_doj.value ) ) {
      return false;
   }
   if( !check_textbox( "add_emp", "new_position", "position offered" ) ) {
      return false;
   }
   return true;
}

function checkeditsuplink() {
   var supportid;
   supportid = document.form1.support.value;
   location = "index.php?task=editsupportsupervisor&support="+supportid;
}

function checkrejectlogin( loginid ) {
   if( confirm( "Do you want to delete the details of this prospect ?" ) ) {
      location = "index.php?task=rejectnewlogin&loginid="+loginid;
   }
}

function checkrejectunconfirmed( loginid ) {
   if( confirm( "Do you want to delete the unconfirmed prospect?" ) ) {
      location = "index.php?task=rejectunconfirmed&loginid="+loginid;
   }
}

function checkdeleteprospect( loginid ) {
   if( confirm( "Are you sure you want to delete the prospect" ) ) {
      location = "index.php?task=deleteresellerprospect&loginid="+loginid;
   }
}

function checkdeleteticket( ticketid, customerid ) {
   if( confirm( "Do you want to delete ?" ) ) {
      location = "index.php?task=sedeletenewtickets&ticketid="+ticketid+"&customerid="+customerid;
   }
}

function checknewentity() {
   if( document.form.entityid ) {
      if( !check_select( "form", "entityid", "entity") ) {
         return false;
      }
   }
   if( document.form.loginname ) {
      if( !check_textbox( "form", "loginname", "login name" ) ) {
         return false;
      }
      if( document.form.loginname.value.length < 5 ) {
         alert("Login name should be 5 characters");
         document.form.loginname.focus();
         return false;
      }
      if( !validchar(document.form.loginname.value) ) {
         alert("Loginname should not contain special characters");
         document.form.loginname.focus();
         return false;
      }
   }
   if( document.form.loginpwd ) {
      if( !check_textbox( "form", "loginpwd", "login password" ) ) {
         return false;
      }
      if( !validchar(document.form.loginpwd.value) ) {
         alert("Login password should not contain special characters");
         document.form.loginpwd.focus();
         return false;
      }
      if( document.form.loginpwd.value.length < 6 ) {
         alert("Login password should be 6 characters");
         document.form.loginpwd.focus();
         return false;
      }
   }
   if( document.form.cloginpwd ) {
      if( !check_textbox( "form", "cloginpwd", "confirm login password" ) ) {
         return false;
      }
      if( !validchar(document.form.cloginpwd.value) ) {
         alert("Confirm login password should not contain special characters");
         document.form.cloginpwd.focus();
         return false;
      }
      if( document.form.loginpwd.value != document.form.cloginpwd.value ) {
         alert("Login password and confirm login password should be same");
         document.form.cloginpwd.focus();
         return false;
      }
   }
   if( !check_textbox( "form", "companyname", "company name" ) ) {
      return false;
   }
   if( !check_textbox( "form", "salutation", "salutation" ) ) {
      return false;
   }
   if( !check_textbox( "form", "contactname", "contact name" ) ) {
      return false;
   }
   if( !check_textbox( "form", "title", "designation" ) ) {
      return false;
   }
   if( !check_textbox( "form", "add1", "address" ) ) {
      return false;
   }
   if( !check_textbox( "form", "location", "city" ) ) {
      return false;
   }
   if( !check_textbox( "form", "pincode", "pincode" ) ) {
      return false;
   }
   if( !check_textbox( "form", "country", "country" ) ) {
      return false;
   }
   if( !check_textbox( "form", "email", "email" ) ) {
      return false;
   }
   if( !checkemailid(document.form.email.value) ) {
      document.form.email.focus();
      return false;
   }
   if( ( document.form.cellno.value == "" ) || !validnostring( document.form.cellno.value ) || ( document.form.cellno.value.length < 7 ) ) {
      alert("Please enter phone number.");
      document.form.cellno.focus();
      return false;
   }
   return true;
}

function checkselectentity() {
   if( !check_select( "form", "entityid", "entity") ) {
      return false;
   }
   return true;
}

function checkname1() {
   if( !check_textbox( "form", "companyname", "Company Name") ) {
      return false;
   }
   return true;
}

function checkcontact() {
   if( !check_select( "searchform", "loginid", "Company Name") ) {
      return false;
   }
   return true;
}

function checkcontact1() {
   if( !check_select( "searchform", "customerid", "Company Name") ) {
      return false;
   }
   return true;
}

function checkticket() {
   if( document.form1.nooftickets ) {
      if( !validno( document.form1.nooftickets.value ) || document.form1.nooftickets.value == "" ) {
         alert( "Please enter number of tickets" );
         document.form1.nooftickets.focus();
         return false;
      }
      if( document.form1.nooftickets.value == 0 ) {
         alert( "Number of tickets cannot be zero" );
         document.form1.nooftickets.focus();
         return false;
      }
   }
   if( document.form1.fromcustomerid ) {
      if( !check_select( "form1", "fromcustomerid", "customer from whom ticket has to be transferred") ) {
         return false;
      }
   }
   if( document.form1.fromloginid ) {
      if( !check_select( "form1", "fromloginid", "customer from whom ticket has to be transferred") ) {
         return false;
      }
   }
   if( document.form1.noofticketstotransfer ) {
      if( !validno( document.form1.noofticketstotransfer.value ) || document.form1.noofticketstotransfer.value == "" ) {
         alert( "Please enter number of tickets" );
         document.form1.noofticketstotransfer.focus();
         return false;
      }
      if( document.form1.noofticketstotransfer.value == 0 ) {
         alert( "Number of tickets cannot be zero" );
         document.form1.noofticketstotransfer.focus();
         return false;
      }
   }
   if( document.form1.satickets ) {
      var a = document.form1.satickets.value;
      if( a == "" ) {
         a = 0;
      }
      var b = document.form1.noofticketstotransfer.value;
      if( parseInt(a) < parseInt(b) ) {
         alert("sales admin does not have " + b +" tickets to transfer");
         document.form1.noofticketstotransfer.focus();
         return false;
      }
   }
   if( !check_textbox( "form1", "expirydate", "expiry date" ) ) {
      return false;
   }
   if( !Validatedate( document.form1.expirydate.value ) ) {
      return false;
   }
   if( document.form1.todaydate ) {
      var today = document.form1.todaydate.value;
      var expiry = document.form1.expirydate.value;
      if( ispastdate( today, expiry ) == 1 ) {
         alert("Expiry date should not be less than the current date");
         return false;
      }
   }
   return true;
}

function checkpassword() {
   if( document.form.oldpwd ) {
      if( !check_textbox( "form", "oldpwd", "old password" ) ) {
         return false;
      }
      if( !validchar(document.form.oldpwd.value) ) {
         alert("Old password should not contain special characters");
         document.form.oldpwd.focus();
         return false;
      }
   }
   if( !check_textbox( "form", "newpwd", "new password" ) ) {
      return false;
   }
   if( !validchar(document.form.newpwd.value) ) {
      alert("New password should not contain special characters");
      document.form.newpwd.focus();
      return false;
   }
   if( document.form.newpwd.value.length < 6 ) {
      alert("Password should be 6 characters");
      document.form.newpwd.focus();
      return false;
   }
   if( !check_textbox( "form", "conpwd", "confirm password" ) ) {
      return false;
   }
   if( !validchar(document.form.conpwd.value) ) {
      alert("Confirm password should not contain special characters");
      document.form.conpwd.focus();
      return false;
   }
   if( document.form.newpwd.value != document.form.conpwd.value ) {
      alert("Login password and confirm login password should be same");
      document.form.conpwd.focus();
      return false;
   }
   return true;
}

function checknoofticket() {
   if( document.form1.nooftickets.value == "" || !validno(document.form1.nooftickets.value) ) {
      alert("Please enter the number of tickets");
      document.form1.nooftickets.focus();
      return false;
   }
   return true;
}

function checktransferfrom() {
   if( !check_select( "form", "transferfrom", "ticket transfer from") ) {
      return false;
   }
   return true;
}

function checklinks() {
   if( !check_select( "form1", "support", "support engineer") ) {
      return false;
   }
   if( !check_select( "form1", "supervisor", "supervisor") ) {
      return false;
   }
   return true;
}

function checksearchclient() {
   if( !Trim( document.form.companyname.value ) ) {
      if( !check_textbox( "form", "contactname", "either company name or contact name" ) ) {
         return false;
      }
   }
   return true;
}

function check_se_status_incident1() {
   if( !check_textbox( "form", "companyname", "company name" ) ) {
      return false;
   }
   return true;
}

function check_se_status_incident2() {
   if( !check_select( "searchform", "customerid", "company name") ) {
      return false;
   }
   if( document.searchform.soptiondate.checked == true ) {
      if( !Trim( document.searchform.datefrom.value ) || !Validatedate( document.searchform.datefrom.value ) ) {
         alert("Please enter the start date");
         document.searchform.datefrom.focus();
         return false;
      }
      if( !Trim( document.searchform.dateto.value ) || !Validatedate( document.searchform.dateto.value ) ) {
         alert("Please enter the end date");
         document.searchform.dateto.focus();
         return false;
      }
      var date1 = document.searchform.datefrom.value;
      var date2 = document.searchform.dateto.value;
      if( ispastdate( date1, date2 ) == 1 ) {
         alert("Please check the 'from' and 'to' dates");
         return false;
      }
   }
}
function check_updatecontact() {
   if( document.form.companyname.value == "")
   {
	alert("Please enter value for company name");
        return false;
   }
   return true;
}

function check_updatecontact1() {
   if( document.searchform.id_customer.value == "" )
   {
	alert("Please select a customer location");
	return false;
   }
   return true;
}

function check_se_create_incident() {
   if( !check_textbox( "form", "companyname", "company name" ) ) {
      return false;
   }
   return true;
}

function check_create_incident1() {
   var customerid;
   customerid = document.form.customerid.value;
   location = "index.php?task=createticket&customerid="+customerid;
}

function check_reseller_create_incident1() {
   var customerid;
   customerid = document.form.customerid.value;
   location = "index.php?task=createresellerticket&customerid="+customerid;
}

function check_se_create_incident0() {
   var customerid,companyname;
   loginid = document.form.loginid.value;
   companyname = document.form.companyname.value;
   location = "index.php?task=secreateincident_step1&loginid="+loginid+"&companyname="+companyname;
}

function check_se_create_incident1() {
   var customerid,companyname;
   loginid = document.form.loginid.value;
   customerid = document.form.customerid.value;
   companyname = document.form.companyname.value;
   location = "index.php?task=secreateincident_step1&loginid="+loginid+"&customerid="+customerid+"&companyname="+companyname;
}

function check_se_create_incident2() {
   if( !check_select( "form", "loginid", "company name") ) {
      return false;
   }
   if( !check_select( "form", "customerid", "installation") ) {
      return false;
   }
   if( !checktextarea(document.form) ) {
      return false;
   }
   return true;
}

function checkresellerticket() {
   if( !check_select( "form", "customerid", "customer") ) {
      return false;
   }
   if( !check_textbox( "form", "comment", "problem" ) ) {
      return false;
   }
   return true;
}

function checkediting() {
   if( document.form.loginname ) {
      if( !check_textbox( "form", "loginname", "login name" ) ) {
         return false;
      }
      if( document.form.loginname.value.length < 5 ) {
         alert("Login name should be 5 characters");
         document.form.loginname.focus();
         return false;
      }
   }
   if( !check_textbox( "form", "salutation", "salutation" ) ) {
      return false;
   }
   if( !check_textbox( "form", "contactname", "contact name" ) ) {
      return false;
   }
   if( !check_textbox( "form", "title", "designation" ) ) {
      return false;
   }
   if( !check_textbox( "form", "companyname", "company name" ) ) {
      return false;
   }
   if( !check_textbox( "form", "add1", "address" ) ) {
      return false;
   }
   if( !check_textbox( "form", "pincode", "pincode" ) ) {
      return false;
   }
   if( !check_textbox( "form", "country", "country" ) ) {
      return false;
   }
   if( !check_textbox( "form", "location", "location" ) ) {
      return false;
   }
   if( !check_textbox( "form", "email", "email" ) ) {
      return false;
   }
   if( !checkemailid(document.form.email.value) ) {
      document.form.email.focus();
      return false;
   }
   if( document.form.cellno.value == "" || !validnostring( document.form.cellno.value ) || ( document.form.cellno.value.length < 7 ) ) {
      alert("Please enter phone number");
      document.form.cellno.focus();
      return false;
   }
   return true;
}

function checkprofile() {
   if( !check_textbox( "profileform", "salutation", "salutation" ) ) {
      return false;
   }
   if( !check_textbox( "profileform", "name", "name" ) ) {
      return false;
   }
   if( !check_textbox( "profileform", "title", "designation" ) ) {
      return false;
   }
   if( !check_textbox( "profileform", "email", "email" ) ) {
      return false;
   }
   if( !check_textbox( "profileform", "add1", "address" ) ) {
      return false;
   }
   if( !check_textbox( "profileform", "pincode", "pincode" ) ) {
      return false;
   }
   if( !check_textbox( "profileform", "country", "country" ) ) {
      return false;
   }
   if( !validnostring( document.profileform.cellno.value ) || document.profileform.cellno.value == "" ) {
      alert( "Please enter cellno" );
      document.profileform.cellno.focus();
      return false;
   }
   return true;
}

function checksecurity() {
   if( Trim( document.form.loginpwd.value ) || Trim( document.form.cloginpwd.value ) ) {
      if( !check_textbox( "form", "loginpwd", "login password" ) ) {
         return false;
      }
      if( !validchar(document.form.loginpwd.value) ) {
         alert("Login password should not contain special characters");
         document.form.loginpwd.focus();
         return false;
      }
      if( document.form.loginpwd.value.length < 6 ) {
         alert("Password should be 6 characters");
         document.form.loginpwd.focus();
         return false;
      }
      if( !check_textbox( "form", "cloginpwd", "confirm login password" ) ) {
         return false;
      }
      if( !validchar(document.form.cloginpwd.value) ) {
         alert("Confirm login password should not contain special characters");
         document.form.cloginpwd.focus();
         return false;
      }
      if( document.form.loginpwd.value != document.form.cloginpwd.value ) {
         alert("Login password and confirm login password should be same");
         document.form.cloginpwd.focus();
         return false;
      }
   }
   if( ( document.form.accesstype[3].checked == false ) && Trim( document.form.iplist.value ) ) {
      alert( "No need to specify the IPs" );
      return false;
   }
   if( ( document.form.accesstype[3].checked == true ) && !Trim( document.form.iplist.value ) ) {
      alert( "Please specify the IPs" );
      return false;
   }
   var iplist = document.form.iplist.value;
   if( Trim( iplist ) ) {
      var iparray = iplist.split(",");
      for( var i=0; i<iparray.length; i++ ) {
         var ipparts = iparray[i].split(".");
         var iplength = (ipparts.length) - 1;
         if( !verifyIP( iparray[i], iplength ) ) {
            return false;
         }
      }
   }
   return true;
}

function verifyIP( IPvalue, iplength ) {
   var totlength = IPvalue.length-1;
   var lastindex = IPvalue.lastIndexOf('.');
   errorString = "";
   theName = "IPaddress";

   if( iplength == 1 ) {
      var ipPattern = /^(\d{1,3})\.$/;
   }
   else if( iplength == 2 ) {
      var ipPattern = /^(\d{1,3})\.(\d{1,3})\.$/;
   }
   else if( iplength == 3 ) {
      if( totlength > lastindex ) {
         var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
      }
      else {
         var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.$/;
      }
   }

   var ipArray = IPvalue.match(ipPattern);

   if( IPvalue == "0.0.0.0" )
      errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
   else if( IPvalue == "255.255.255.255" )
      errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
   if( ipArray == null )
      errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
   else {
      for( i = 0; i < 4; i++ ) {
         thisSegment = ipArray[i];
         if( thisSegment > 255 ) {
            errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
            i = 4;
         }
         if( ( i == 0 ) && ( thisSegment > 255 ) ) {
            errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
            i = 4;
         }
      }
   }
   extensionLength = 3;
   if( errorString == "" ) {
      return true;
   }
   else {
      alert( errorString );
      return false;
   }
}

function taketopage( pg ) {
   document.form.pgno.value = pg;
   document.form.action = "index.php?task=ticketattendedview";
   document.form.method = "post";
   document.form.submit();
}

function check_add_dept() {
   if( !check_textbox( "adddept", "dept_name", "department name" ) ) {
      return false;
   }
   if( !check_select( "adddept", "id_entity", "entity type") ) {
      return false;
   }
   return true;
}

function check_edit_dept() {
   if( !check_textbox( "editdept", "dept_name", "department name" ) ) {
      return false;
   }
   if( !check_select( "editdept", "dept_head", "department head") ) {
      return false;
   }
   return true;
}

function check_delete_dept() {
   if( confirm( "Are you sure that you want to delete the department?" ) ) {
      if( confirm( "Department will be deleted only if there is no employee in the department" ) ) {
         return true;
      }
   }
   return false;
}

function check_view_emp() {
   if( !check_select( "viewemp", "dept_id", "department") ) {
      return false;
   }
   return true;
}

function check_edit_emp() {
   if( !check_select( "editemp", "salutation", "salutation") ) {
      return false;
   }
   if( !check_textbox( "editemp", "contactname", "contact name" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "title", "designation" ) ) {
      return false;
   }
   if( !check_select( "editemp", "branchid", "branch") ) {
      return false;
   }
   if( !check_textbox( "editemp", "add1", "address" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "location", "city" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "pincode", "pincode" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "country", "country" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "email", "email" ) ) {
      return false;
   }
   if( !checkemailid(document.editemp.email.value) ) {
      document.editemp.email.focus();
      return false;
   }
   if( !check_textbox( "editemp", "cellno", "phone number" ) ) {
      return false;
   }
   if( !validnostring( document.editemp.cellno.value ) || ( document.editemp.cellno.value.length < 7 ) ) {
      alert("Please enter phone number");
      document.editemp.cellno.focus();
      return false;
   }
   if( !check_textbox( "editemp", "fathername", "father's name" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "dob", "date of birth" ) || !Validatedate( document.editemp.dob.value ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "pob", "place of birth" ) ) {
      return false;
   }
   if( document.editemp.marital[0].checked == true ) {
      if( !check_textbox( "editemp", "spousename", "spouse name" ) ) {
         return false;
      }
   }
   if( !check_textbox( "editemp", "pemail", "personal email" ) ) {
      return false;
   }
   if( !checkemailid(document.editemp.pemail.value) ) {
      document.editemp.pemail.focus();
      return false;
   }
   if( document.editemp.p_address.checked == false ) {
      document.editemp.p_address.value=0;
      if( !check_textbox( "editemp", "p_add1", "permanent address" ) ) {
         return false;
      }
      if( !check_textbox( "editemp", "p_location", "location" ) ) {
         return false;
      }
      if( !check_textbox( "editemp", "p_pincode", "pincode" ) ) {
        return false;
      }
      if( !check_textbox( "editemp", "p_country", "country" ) ) {
         return false;
      }
   }
   else {
      document.editemp.p_address.value=1;
   }
   if( !check_textbox( "editemp", "qualification", "degree/diploma" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "institution", "institution" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "marks", "marks" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "l_speak", "languages known to speak" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "l_read", "languages known to read" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "l_write", "languages known to write" ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "new_salary", "salary" ) ) {
      return false;
   }
   if( !validno( document.editemp.new_salary.value ) ) {
      alert("Enter numerical value of salary");
      document.editemp.new_salary.focus();
      return false;
   }
   if( !check_textbox( "editemp", "new_doj", "date of joining" ) || !Validatedate( document.editemp.new_doj.value ) ) {
      return false;
   }
   if( !check_textbox( "editemp", "new_position", "position offered" ) ) {
      return false;
   }
   return true;
}

function check_delete_emp() {
   if( confirm( "Are you sure that you want to delete the employee?" ) ) {
      return true;
   }
   return false;
}

function check_assign_dept_head1() {
   location = "index.php?task=assign_dept_head&id_dept="+document.assigndepthead.department.value;
}

function check_assign_dept_head2() {
   if( !check_select( "assigndepthead", "department", "department") ) {
      return false;
   }
   if( !check_select( "assigndepthead", "employee", "employee name") ) {
      return false;
   }
}

function check_assign_dept1() {
   location = "index.php?task=assign_dept&emp_id="+document.assigndept.emp_id.value;
}

function check_assign_dept2() {
   if( !check_select( "assigndept", "emp_id", "employee name") ) {
      return false;
   }
   if( !check_select( "assigndept", "dept_id", "department") ) {
      return false;
   }
}

function check_assign_emp_head1() {
   location = "index.php?task=assign_emp_head&emp_id="+document.assignhead.employee.value;
}

function check_assign_emp_head2() {
   if( !check_select( "assignhead", "employee", "employee name") ) {
      return false;
   }
   if( !check_select( "assignhead", "emp_head", "employee head") ) {
      return false;
   }
}

function radio_button_checker() {
   // set var radio_choice to false
   var radio_choice = false;

   // Loop from zero to the one minus the number of radio button selections
   for( counter = 0; counter < radioform.task.length; counter++ ) {
      // If a radio button has been selected it will return true
      // (If not it will return false)
      if( radioform.task[counter].checked )
      radio_choice = true;
   }
   return true;
}

// function to display page numbers
function loadpage( value ) {
   window.location.href="index.php?task="+value+"&next="+document.newform.newcomp.value;
   return true;
}

function loadpageser( value, value1 ) {
   window.location.href="index.php?task="+value+"&searchkey="+value1+"&next="+document.newform.newcomp.value;
   return true;
}

function check_incident_status() {
   if(!( document.radioform.company_name.checked == true || document.radioform.incidentnumber.checked== true )) {
      alert("Select Company name or Incident Number");
      return false;
   }
   //select either company name or incident number 
   if( document.radioform.company_name.checked == true && document.radioform.incidentnumber.checked== true ) {
      alert("Select Only One Field");
      return false;
   }
   if( document.radioform.companyname.value != "" && document.radioform.incident_number.value != "" ) {
      alert("Enter Only One Field");
      return false;
   }
   //enter company name if company name fieled is checked
   if( document.radioform.company_name ) {
      if( document.radioform.company_name.checked == true ) {
         if( !Trim( document.radioform.companyname.value ) ) {
            alert("Enter the Company Name");
            document.radioform.companyname.focus();
            return false;
         }
      }
   }
   //enter incident number if incident number fieled is checked
   if( document.radioform.incidentnumber ) {
      if( document.radioform.incidentnumber.checked == true ) {
         if( !Trim( document.radioform.incident_number.value ) ) {
            alert("Enter Incident Number");
            document.radioform.incident_number.focus();
            return false;
         }
         //to enter only numbers to incident number field
         if( !validno( document.radioform.incident_number.value ) ) {
             alert("Enter numerical value For Incident Number");
             document.radioform.incident_number.focus();
             return false;
         }
      }
   }
}

