//checkUncheck all
function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
			theForm[z].checked = theElement.checked;
		}
	}
}

/*// checkUncheck all for List Cust page in the admin section 
function checkUncheckAllCustPage(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall' && theForm[z].disabled != true){
			theForm[z].checked = theElement.checked;
		}
	}
}*/

//checkUncheck all for List Group page in admin section
function checkUncheckAllGroupPage(theElement) {
	var theForm = theElement.form, z = 0; 
	for(z=0; z<theForm.length;z++) {
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall' && theForm[z].disabled != true){
			theForm[z].checked = theElement.checked; 
		}
	}
}

//check checkbox checked
function checkCount(theElement) {
	var theForm=theElement, z = 0,i=1;
	for(z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
			if(theForm[z].checked==true) {
				i=0;
			}
		}
	}
	if(i==1) {
		alert("Please Select at least one checkbox");
		return false;
	}
	else {
		return true;
	}
}
//highlight active control
var currentlyActiveInputRef = false;
var currentlyActiveInputClassName = false;
function highlightActiveInput() {
  if(currentlyActiveInputRef) {
    currentlyActiveInputRef.className = currentlyActiveInputClassName;
  }
  currentlyActiveInputClassName = this.className;
  this.className = 'inputHighlighted';
  currentlyActiveInputRef = this;
}
function blurActiveInput() {
  this.className = currentlyActiveInputClassName;
}
function initInputHighlightScript() {
  var tags = ['INPUT','TEXTAREA','SELECT-ONE'];
  for(tagCounter=0;tagCounter<tags.length;tagCounter++){
    var inputs = document.getElementsByTagName(tags[tagCounter]);
    for(var no=0;no<inputs.length;no++){
      if(inputs[no].className && inputs[no].className=='doNotHighlightThisInput')continue;
      if(inputs[no].tagName.toLowerCase()=='textarea' || (inputs[no].tagName.toLowerCase()=='input' && inputs[no].type.toLowerCase()=='text')){
        inputs[no].onfocus = highlightActiveInput;
        inputs[no].onblur = blurActiveInput;
      }
    }
  }
}
//set focus control
function SetFocus() {
  if (document.forms.length > 0) {
    var field = document.forms[0];
    for (i=0; i<field.length; i++) {
      if ( (field.elements[i].type != "image") &&
           (field.elements[i].type != "hidden") &&
           (field.elements[i].type != "reset") &&
           (field.elements[i].type != "submit") ) {

        document.forms[0].elements[i].focus();

        if ( (field.elements[i].type == "text") ||
             (field.elements[i].type == "password") )
          //document.forms[0].elements[i].select();

        break;
      }
    }
  }
}


// Group Selection
function selectgrp() {
	obj = document.getElementById('groupid');
	if(obj.value != '' && obj.value != 0) {
		ObjectFrm = document.getElementById("frm");
		ObjectFrm.submit();
	} else {
		alert("Select the Group.");
		return false;
	}
}

//trim all the space from start and end of the string and return string
function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

// email validation
function email_validation(value) {
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value))) 
	{
		return false;
	} 
	else {
		return true;
	}
}

// validate the subscriber form
function validateadd_cust() {
	
	if(trimAll(document.frmAdd.first_name.value).length == 0) {
		alert("First name should be required.");
		document.frmAdd.first_name.value = '';
		document.frmAdd.first_name.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.last_name.value).length == 0) {
		alert("Last name should be required.");
		document.frmAdd.last_name.value = '';
		document.frmAdd.last_name.focus();
		return false;	
	}
	
	if(document.frmAdd.country_id.value == 0) {
		alert("please select Country.");
		document.frmAdd.country_id.focus();
		return false;
	}
	if(trimAll(document.frmAdd.email.value).length == 0)
	{
		alert("Email Address should be required.");
		document.frmAdd.email.value = '';
		document.frmAdd.email.focus();
		return false;
	} 
	else {
		var res = email_validation(trimAll(document.frmAdd.email.value))
		if(!res) {
			alert("Email Address like to be incorrect.");
			document.frmAdd.email.value = '';
			document.frmAdd.email.focus();
			return false;
		}
		
	}
	
	if(trimAll(document.frmAdd.pwd.value).length == 0) {
		alert("Password should be required.");
		document.frmAdd.pwd.value = '';
		document.frmAdd.pwd.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.weburl.value).length == 0) {
		alert("Web Domain should be required.");
		document.frmAdd.weburl.value = '';
		document.frmAdd.weburl.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.user_ip.value).length == 0) {
		alert("IP Address should be required.");
		document.frmAdd.user_ip.value = '';
		document.frmAdd.user_ip.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.company_name.value).length == 0) {
		alert("Company name should be required.");
		document.frmAdd.company_name.value = '';
		document.frmAdd.company_name.focus();
		return false;	
	}
	
	if(document.frmAdd.usergroupid.value == 0) {
		alert("Please select the Group");
		document.frmAdd.usergroupid.focus();
		return false;
	}
	if(trimAll(document.frmAdd.maxmonthvisit.value).length == 0) {
		alert("Maximum Month Visits should be required.");
		document.frmAdd.maxmonthvisit.value = '';
		document.frmAdd.maxmonthvisit.focus();
		return false;	
	} else {
		if(isNaN(document.frmAdd.maxmonthvisit.value)) {
			alert("Maximum Month Visits should be Number.");
			document.frmAdd.maxmonthvisit.value = '';
			document.frmAdd.maxmonthvisit.focus();
			return false;	
		}
	}
	
	if(trimAll(document.frmAdd.maxwebsite.value).length == 0) {
		alert("Maximum Websites should be required.");
		document.frmAdd.maxwebsite.value = '';
		document.frmAdd.maxwebsite.focus();
		return false;	
	}
	else {
		if(isNaN(document.frmAdd.maxwebsite.value)) {
			alert("Maximum Websites should be Number.");
			document.frmAdd.maxwebsite.value = '';
			document.frmAdd.maxwebsite.focus();
			return false;	
		}
	}
	
	if(trimAll(document.frmAdd.maxuser.value).length == 0) {
		alert("Maximum Users should be required.");
		document.frmAdd.maxuser.value = '';
		document.frmAdd.maxuser.focus();
		return false;	
	}
	else {
		if(isNaN(document.frmAdd.maxuser.value)) {
			alert("Maximum Users Visits should be Number.");
			document.frmAdd.maxuser.value = '';
			document.frmAdd.maxuser.focus();
			return false;	
		}
	}
	
	if(trimAll(document.frmAdd.ipcap.value).length == 0) {
		alert("IP Memory should be required.");
		document.frmAdd.ipcap.value = '';
		document.frmAdd.ipcap.focus();
		return false;	
	}
	else {
		if(isNaN(document.frmAdd.ipcap.value)) {
			alert("IP Memory should be Number.");
			document.frmAdd.ipcap.value = '';
			document.frmAdd.ipcap.focus();
			return false;	
		}
	}
	
	if(trimAll(document.frmAdd.maxvisit.value).length == 0) {
		alert("Maximum Search capacity should be required.");
		document.frmAdd.maxvisit.value = '';
		document.frmAdd.maxvisit.focus();
		return false;	
	}
	else {
		if(isNaN(document.frmAdd.maxvisit.value)) {
			alert("Maximum Search capacity should be Number.");
			document.frmAdd.maxvisit.value = '';
			document.frmAdd.maxvisit.focus();
			return false;	
		}
	}
}

// validate User
// validate the subscriber form
function validateadd_user() {
	
	if(trimAll(document.frmAdd.fname.value).length == 0) {
		alert("First name should be required.");
		document.frmAdd.fname.value = '';
		document.frmAdd.fname.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.lname.value).length == 0) {
		alert("Last name should be required.");
		document.frmAdd.lname.value = '';
		document.frmAdd.lname.focus();
		return false;	
	}

	if(trimAll(document.frmAdd.email.value).length == 0)
	{
		alert("Email Address should be required.");
		document.frmAdd.email.value = '';
		document.frmAdd.email.focus();
		return false;
	} 
	else {
		var res = email_validation(trimAll(document.frmAdd.email.value))
		if(!res) {
			alert("Email Address like to be incorrect.");
			document.frmAdd.email.value = '';
			document.frmAdd.email.focus();
			return false;
		}
		
	}
	
	if(trimAll(document.frmAdd.pwd.value).length == 0) {
		alert("Password should be required.");
		document.frmAdd.pwd.value = '';
		document.frmAdd.pwd.focus();
		return false;	
	}
} 
function validate_memory_form() {
	
   if(trimAll(document.frmAdd.ip_from.value).length == 0) {
		alert("IP-From should be required.");
		document.frmAdd.ip_from.value = '';
		document.frmAdd.ip_from.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.ip_to.value).length == 0) {
		alert("IP-to should be required.");
		document.frmAdd.ip_to.value = '';
		document.frmAdd.ip_to.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.company_name.value).length == 0) {
		alert("If you do not have information to enter into Company please type in a dash -.");
		document.frmAdd.company_name.value = '';
		document.frmAdd.company_name.focus();
		return false;	
	}
	
		if(trimAll(document.frmAdd.email.value).length == 0)
	{
		alert("If you do not have information to enter into Email Address please type in a dash -.");
		document.frmAdd.email.value = '';
		document.frmAdd.email.focus();
		return false;
	} 
	/*else {
		var res = email_validation(trimAll(document.frmAdd.email.value))
		if(!res) {
			alert("Email Address like to be incorrect.");
			document.frmAdd.email.value = '';
			document.frmAdd.email.focus();
			return false;
		}
		
	}*/
	
	if(trimAll(document.frmAdd.city.value).length == 0) {
		alert("If you do not have information to enter into City please type in a dash -.");
		document.frmAdd.city.value = '';
		document.frmAdd.city.focus();
		return false;	
	}
	
	if(trimAll(document.frmAdd.state.value).length == 0) {
		alert("If you do not have information to enter into State please type in a dash -.");
		document.frmAdd.state.value = '';
		document.frmAdd.state.focus();
		return false;	
	}

	if(trimAll(document.frmAdd.telephone.value).length == 0) {
		alert("If you do not have information to enter into Telephone please type in a dash -.");
		document.frmAdd.telephone.value = '';
		document.frmAdd.telephone.focus();
		return false;	
	}
	
	if(document.frmAdd.country_id.value == 0) {
		alert("please select the country.");	
		document.frmAdd.country_id.focus();
		return false;
	}
	
	if(trimAll(document.frmAdd.weburl.value).length == 0) {
		alert("If you do not have information to enter into Website please type in a dash -.");
		document.frmAdd.weburl.value = '';
		document.frmAdd.weburl.focus();
		return false;	
	}
}

function checkselected() {
	//if((document.frmQuery.chk1.checked != true) || (document.frmQuery.chk2.checked != true)) {
	if(document.frmQuery.chk2.checked != true) {
		alert("You must read and agree to the Terms & Conditions to continue.");
		return false;	
	}
}

function chkvalidate() {
	if(trimAll(document.frm.txtusername.value).length == 0)
	{
		alert("Please enter an email address into the username field and click Check Status to continue.");
		document.frm.txtusername.value = '';
		document.frm.txtusername.focus();
		return false;
	} /*
	else {
		var res = email_validation(trimAll(document.frm.txtusername.value))
		if(!res) {
			alert("Please enter an email address into the username field and click Check Status to continue.");
			document.frm.txtusername.value = '';
			document.frm.txtusername.focus();
			return false;
		}
		
	}*/
}
function twochkout_validate() {
	if(trimAll(document.frm.txtusername.value).length == 0)
	{
		alert("Please enter an email address into the username field and click Check Status to continue.");
		document.frm.txtusername.value = '';
		document.frm.txtusername.focus();
		return false;
	} /*
	else {
		var res = email_validation(trimAll(document.frm.txtusername.value))
		if(!res) {
			alert("Please enter an email address into the username field and click Check Status to continue.");
			document.frm.txtusername.value = '';
			document.frm.txtusername.focus();
			return false;
		}
	}*/
	
	if(!(document.frm.checkbox44.checked))  {
		alert("Please read and accept the Terms & Conditions.");
		return false;
	}
}
function chkisinteger(string,length) {
  	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	for (var i = 0; i < length; i++) {
	  	if (iChars.indexOf(string.charAt(i)) != -1) {
		  	return 1;
	  	} 
	}
}

function validate_group() {
	
  if(trimAll(document.frmAdd.group_name.value).length == 0) {
	alert("Group Name should be required.");
	document.frmAdd.group_name.value = '';
	document.frmAdd.group_name.focus();
	return false;	
 }

 if(chkisinteger(document.frmAdd.noofday.value,document.frmAdd.noofday.value.length) == 1) {
		alert ("No of Days should be Interger.");
		document.frmAdd.noofday.value = '';
		document.frmAdd.noofday.focus();
  		return false;
  }
  
  if(trimAll(document.frmAdd.maxmonthlyvisit.value).length == 0) {
		alert("Max Monthly Visit should be required.");
		document.frmAdd.maxmonthlyvisit.value = '';
		document.frmAdd.maxmonthlyvisit.focus();
		return false;	
  }

  if(chkisinteger(document.frmAdd.maxmonthlyvisit.value,document.frmAdd.maxmonthlyvisit.value.length) == 1) {
		alert ("Max Monthly Visit should be Interger.");
		document.frmAdd.maxmonthlyvisit.value = '';
		document.frmAdd.maxmonthlyvisit.focus();
  		return false;
  }

 if(chkisinteger(document.frmAdd.memorycapacity.value,document.frmAdd.memorycapacity.value.length) == 1) {
		alert ("Memory Capacity should be Interger.");
		document.frmAdd.memorycapacity.value = '';
		document.frmAdd.memorycapacity.focus();
  		return false;
  }
  if(trimAll(document.frmAdd.memorycapacity.value).length == 0) {
		alert("Memory Capacity should be required.");
		document.frmAdd.memorycapacity.value = '';
		document.frmAdd.memorycapacity.focus();
		return false;	
  }
  
  if(trimAll(document.frmAdd.maximumurl.value).length == 0) {
	alert("Maximum URL should be required.");
	document.frmAdd.maximumurl.value = '';
	document.frmAdd.maximumurl.focus();
	return false;	
  }
  if(chkisinteger(document.frmAdd.maximumurl.value,document.frmAdd.maximumurl.value.length) == 1) {
		alert ("Maximum URLs should be Interger.");
		document.frmAdd.maximumurl.value = '';
		document.frmAdd.maximumurl.focus();
  		return false;
  }
  
  if(trimAll(document.frmAdd.maximumusers.value).length == 0) {
		alert("Maximum Users should be required.");
		document.frmAdd.maximumusers.value = '';
		document.frmAdd.maximumusers.focus();
		return false;	
  }
  
  if(chkisinteger(document.frmAdd.maximumusers.value,document.frmAdd.maximumusers.value.length) == 1) {
		alert ("Maximum Users should be Interger.");
		document.frmAdd.maximumusers.value = '';
		document.frmAdd.maximumusers.focus();
  		return false;
  }
  
  if(chkisinteger(document.frmAdd.maximumsearch.value,document.frmAdd.maximumsearch.value.length) == 1) {
		alert ("Maximum Search should be Interger.");
		document.frmAdd.maximumsearch.value = '';
		document.frmAdd.maximumsearch.focus();
  		return false;
  }
  if(trimAll(document.frmAdd.maximumsearch.value).length == 0) {
		alert("Maximum Search should be required.");
		document.frmAdd.maximumsearch.value = '';
		document.frmAdd.maximumsearch.focus();
		return false;	
  }
  
  if(document.frmAdd.rdsubscribe[0].checked) {
  	 
  	if(trimAll(document.frmAdd.monthlypay.value).length == 0) {
		alert("Monthly Pay should be required.");
		document.frmAdd.monthlypay.value = '';
		document.frmAdd.monthlypay.focus();
		return false;	
  	}
  
  	if(trimAll(document.frmAdd.two_co_pid.value).length == 0 || document.frmAdd.two_co_pid.value == 0) {
		alert("2CO Product Id should be required and zero not allowed.");
		document.frmAdd.two_co_pid.value = '';
		document.frmAdd.two_co_pid.focus();
		return false;	
  	}
  	if(chkisinteger(document.frmAdd.two_co_pid.value,document.frmAdd.two_co_pid.value.length) == 1 || document.frmAdd.two_co_pid.value == 0) {
		alert ("2CO Product Id should be Interger and zero not allowed.");
		document.frmAdd.two_co_pid.value = '';
		document.frmAdd.two_co_pid.focus();
  		return false;
 	}
  }
}
function show(id) {
	
	obj = document.getElementById(id);
	if(document.frmAdd.rdsubscribe[0].checked) {
		obj.style.display = "block";
	} else { 
		obj.style.display="none";
	}
}
//FOR ATS
	function getAntiTheftControl() {
		if(document.frmReport.cmbWebUrl.value!="0") {
			document.frmReport.action="antitheftcontrolstab.php";
			document.frmReport.submit();
		}
		else {
			alert("Please select a computer");
		}
	}
	
	//FOR ATS Mobile
	function getAntiTheftMobileTab() {
		if(document.frmReport.cmbWebUrl.value!="0") {
			document.frmReport.action="antitheftcontrol_send_emailtab.php";
			document.frmReport.submit();
		}
		else {
			alert("Please select a computer");
		}
	}
	//FOR ATS Laptop
	function getAntiTheftLaptopTab() {
		if(document.frmReport.cmbWebUrl.value!="0") {
			document.frmReport.action="laptop_secure.php";
			document.frmReport.submit();
		}
		else {
			alert("Please select a computer");
		}
	}