function textCounter(textarea, counterID, maxLen) {
cnt = document.getElementById(counterID);
if (textarea.value.length > maxLen)
{
textarea.value = textarea.value.substring(0,maxLen);
}
cnt.innerHTML = maxLen - textarea.value.length;
if (cnt.innerHTML==0)
{
	alert("Maximum limit exceeded. Only 500 characters are allowed.");
}
}

function echeck(str) 
{
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("Email address is invalid.  Please try again.");
     return false;
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Email address is invalid.  Please try again.");
     return false;
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Email address is invalid.  Please try again.");
      return false;
  }

   if (str.indexOf(at,(lat+1))!=-1){
      alert("Email address is invalid.  Please try again.");
      return false;
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Email address is invalid.  Please try again.");
      return false;
   }

   if (str.indexOf(dot,(lat+2))==-1){
      alert("Email address is invalid.  Please try again.");
      return false;
   }
  
   if (str.indexOf(" ")!=-1){
      alert("Email address is invalid.  Please try again.");
      return false;
   }

    return true;     
 }

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

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;
    }
    // All characters are numbers.
    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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function reset_form()
{	
	document.forms[0].FirstName.focus();
}
function textCounter(textarea, counterID, maxLen) {
cnt = document.getElementById(counterID);
if (textarea.value.length > maxLen)
{
textarea.value = textarea.value.substring(0,maxLen);
}
cnt.innerHTML = maxLen - textarea.value.length;
if (cnt.innerHTML==0)
{
	alert("Maximum limit exceeded. Only 500 characters are allowed.");
}
}


function validator_form(theform)
{
	document.forms[0].my_email.value = "jcomply_demo@tabaqsoftware.com";
	document.forms[0].subject.value = "Demo Inquiry";
	var Flag = 0;
	if (Flag == 0){
		if (theform.FirstName.value == ""){ 
			alert ("Please enter your first name.\n");
			document.forms[0].FirstName.focus();
			return false;
  		} 
    	if (theform.LastName.value == ""){
			alert ("Please enter your last name.\n");
			document.forms[0].LastName.focus();
			return false;
  		} 
		if(theform.FirstName.value == theform.LastName.value ){
	  		alert("The first name and last name can not be the same.\n");
			document.forms[0].LastName.focus();
			return false;
  		}
    	if (theform.CompanyName.value == ""){
			alert("Please enter your company name.\n");
			document.forms[0].CompanyName.focus();
			return false;
  		}
   		if (theform.CompanyName.value == theform.FirstName.value){
			alert("The first name and company name can not be the same.\n");
			document.forms[0].CompanyName.focus();
			return false;
		}
  		if (theform.CompanyName.value == theform.LastName.value){
			alert("The last name and company name can not be the same.\n");
			document.forms[0].CompanyName.focus();
			return false;
 		 }    

 	 var emailID=theform.email;

 		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please enter your email address.");
			document.forms[0].email.focus();
		return false;
	 	}
		if (echeck(emailID.value)==false){
  			document.forms[0].email.focus();
  		return false;
 		}


 		var PhoneNumber=theform.Phone;
 
 		if ((PhoneNumber.value==null)||(PhoneNumber.value=="")){
  			alert("Please enter your phone number.");
  			document.forms[0].Phone.focus();
  			return false;
 		}

 		if (checkInternationalPhone(PhoneNumber.value)==false){
  		alert("Please enter your phone number including country code.");
  		document.forms[0].Phone.focus();
  		return false;
 		}
 		if (theform.Country.options[0].selected == true){
			alert("Please select country from the drop-down list.\n");
			document.forms[0].Country.focus();
   			return false;
  		} 
   		if (theform.OrganisationSize.options[0].selected == true){
			alert("Please select organisation size from the drop-down list.\n");
			document.forms[0].OrganisationSize.focus();
    		return false;
  		} 
   	   	if (theform.industry.options[0].selected == true){
 			alert ("Please select the industry type from the drop-down list.\n");
			document.forms[0].industry.focus();
	 		return false;
  		} 
	} // end if Flag = 0;
		Flag = 1;
		if(Flag==1){
		//return getParameter();
		return	MM_openBrWindow('/resources/demoregistrationsuccess.html','success','width=580,height=500'); 
		}
			Flag = 2;
			if(Flag==2){
			return	MM_openBrWindow('/resources/demoregistrationfailure.html','failure','width=580,height=500'); 
			}
}// end of validate function

var queryString = window.top.location.search.substring(1);

function getParameter (  ) 
{

var queryString = window.top.location.search.substring(1);
document.forms[0].subject.value = queryString+ " downloaded";
if(queryString.length>0)
{

var test = "/documents/"+queryString;
window.open(test);
return true;
}
} function textCounter(textarea, counterID, maxLen) {
cnt = document.getElementById(counterID);
if (textarea.value.length > maxLen)
{
textarea.value = textarea.value.substring(0,maxLen);
}
cnt.innerHTML = maxLen - textarea.value.length;
if (cnt.innerHTML==0)
{
	alert("Maximum limit exceeded. Only 500 characters are allowed.");
}
}

function echeck(str) 
{
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("Email address is invalid.  Please try again.");
     return false;
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Email address is invalid.  Please try again.");
     return false;
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Email address is invalid.  Please try again.");
      return false;
  }

   if (str.indexOf(at,(lat+1))!=-1){
      alert("Email address is invalid.  Please try again.");
      return false;
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Email address is invalid.  Please try again.");
      return false;
   }

   if (str.indexOf(dot,(lat+2))==-1){
      alert("Email address is invalid.  Please try again.");
      return false;
   }
  
   if (str.indexOf(" ")!=-1){
      alert("Email address is invalid.  Please try again.");
      return false;
   }

    return true;     
 }

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

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;
    }
    // All characters are numbers.
    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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function reset_form()
{	
	document.forms[0].FirstName.focus();
}
function textCounter(textarea, counterID, maxLen) {
cnt = document.getElementById(counterID);
if (textarea.value.length > maxLen)
{
textarea.value = textarea.value.substring(0,maxLen);
}
cnt.innerHTML = maxLen - textarea.value.length;
if (cnt.innerHTML==0)
{
	alert("Maximum limit exceeded. Only 500 characters are allowed.");
}
}


function validator_form(theform)
{
document.forms[0].my_email.value = "jcomply_demo@tabaqsoftware.com";
document.forms[0].subject.value = "Demo Inquiry";
var Flag = 0;
if (Flag == 0){
	if (theform.FirstName.value == ""){ 
		alert ("Please enter your first name.\n");
		document.forms[0].FirstName.focus();
		return false;
  	} 
    if (theform.LastName.value == ""){
		alert ("Please enter your last name.\n");
		document.forms[0].LastName.focus();
		return false;
  	} 
	if(theform.FirstName.value == theform.LastName.value ){
	  	alert("The first name and last name can not be the same.\n");
		document.forms[0].LastName.focus();
		return false;
  	}
    if (theform.CompanyName.value == ""){
		alert("Please enter your company name.\n");
		document.forms[0].CompanyName.focus();
		return false;
  	}
   if (theform.CompanyName.value == theform.FirstName.value){
		alert("The first name and company name can not be the same.\n");
		document.forms[0].CompanyName.focus();
		return false;
	}
   if (theform.CompanyName.value == theform.LastName.value){
		alert("The last name and company name can not be the same.\n");
		document.forms[0].CompanyName.focus();
		return false;
  }    

  var emailID=theform.email;

  if ((emailID.value==null)||(emailID.value=="")){
	alert("Please enter your email address.");
	document.forms[0].email.focus();
	return false;
 }
 if (echeck(emailID.value)==false){
  document.forms[0].email.focus();
  return false;
 }


 var PhoneNumber=theform.Phone;
 
 if ((PhoneNumber.value==null)||(PhoneNumber.value=="")){
  alert("Please enter your phone number.");
  document.forms[0].Phone.focus();
  return false;
 }
 
 if (checkInternationalPhone(PhoneNumber.value)==false){
  alert("Please enter your phone number including country code.");
  document.forms[0].Phone.focus();
  return false;
 }
 if (theform.Country.options[0].selected == true){
	alert("Please select country from the drop-down list.\n");
	document.forms[0].Country.focus();
    return false;
  } 
   if (theform.OrganisationSize.options[0].selected == true){
	alert("Please select organisation size from the drop-down list.\n");
	document.forms[0].OrganisationSize.focus();
    return false;
  } 
    if (theform.industry.options[0].selected == true){
 	alert ("Please select the industry type from the drop-down list.\n");
	document.forms[0].industry.focus();
	 	return false;
  } 
} // end if Flag = 0;
	Flag = 1;
	if(Flag==1){
	//return getParameter();
	return	MM_openBrWindow('/resources/demoregistrationsuccess.html','success','width=580,height=500'); 
}
	Flag = 2;
	if(Flag==2){
	return	MM_openBrWindow('/resources/demoregistrationfailure.html','failure','width=580,height=500'); 
	}
}

var queryString = window.top.location.search.substring(1);

function getParameter (  ) 
{

var queryString = window.top.location.search.substring(1);
document.forms[0].subject.value = queryString+ " downloaded";
if(queryString.length>0)
{

var test = "/documents/"+queryString;
window.open(test);
return true;
}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function validator_becomeapartner_form(theform)
{
	document.forms[0].my_email.value = "jcomply_demo@tabaqsoftware.com";
	document.forms[0].subject.value = "Demo Inquiry";
	var Flag = 0;
	if (Flag == 0){
		if (theform.FirstName.value == ""){ 
			alert ("Please enter your first name.\n");
			document.forms[0].FirstName.focus();
			return false;
  		} 
    	if (theform.LastName.value == ""){
			alert ("Please enter your last name.\n");
			document.forms[0].LastName.focus();
			return false;
  		} 
		if(theform.FirstName.value == theform.LastName.value ){
	  		alert("The first name and last name can not be the same.\n");
			document.forms[0].LastName.focus();
			return false;
  		}
    	if (theform.CompanyName.value == ""){
			alert("Please enter your company name.\n");
			document.forms[0].CompanyName.focus();
			return false;
  		}
   		if (theform.CompanyName.value == theform.FirstName.value){
			alert("The first name and company name can not be the same.\n");
			document.forms[0].CompanyName.focus();
			return false;
		}
  		if (theform.CompanyName.value == theform.LastName.value){
			alert("The last name and company name can not be the same.\n");
			document.forms[0].CompanyName.focus();
			return false;
 		 }    

 	 var emailID=theform.email;

 		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please enter your email address.");
			document.forms[0].email.focus();
		return false;
	 	}
		if (echeck(emailID.value)==false){
  			document.forms[0].email.focus();
  		return false;
 		}

 		var PhoneNumber=theform.Phone;
 
 		if ((PhoneNumber.value==null)||(PhoneNumber.value=="")){
  			alert("Please enter your phone number.");
  			document.forms[0].Phone.focus();
  			return false;
 		}

 		if (checkInternationalPhone(PhoneNumber.value)==false){
  		alert("Please enter your phone number including country code.");
  		document.forms[0].Phone.focus();
  		return false;
 		}
 		if (theform.Country.options[0].selected == true){
			alert("Please select country from the drop-down list.\n");
			document.forms[0].Country.focus();
   			return false;
  		}
   		if (theform.pertnerprog.options[0].selected == true){
			alert("Please select partnership program from the drop-down list.\n");
			document.forms[0].pertnerprog.focus();
    		return false;
  		}
		if (theform.jobtitle.value == ""){ 
			alert ("Please enter your job title.\n");
			document.forms[0].jobtitle.focus();
			return false;
  		} 
		if (theform.datetime.value == ""){ 
			alert ("Please enter your preffered date & time.\n");
			document.forms[0].datetime.focus();
			return false;
  		}
		if (theform.notify.checked==false){
		alert("Please check the checkbox.");
  			document.forms[0].notify.focus();
  		return false;
 		} 
    	
	} // end if Flag = 0;
		Flag = 1;
		if(Flag==1){
		//return getParameter();
		return	MM_openBrWindow('/resources/demoregistrationsuccess.html','success','width=580,height=500'); 
		}
			Flag = 2;
			if(Flag==2){
			return	MM_openBrWindow('/resources/demoregistrationfailure.html','failure','width=580,height=500'); 
			}
}// end of validate function