
function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );
  return sInString.replace( /\s+$/g, "" );
}

function isEmptyString(str){
	var string = trimString(str);
	if (string == ""){
    	return true;
     }
	return false;
}

function checkFirstName(str){
	if (isEmptyString(str)){
    	alert('Please enter your First name.');
    	return false;
     }
	return true;
}

function checkLastName(str){
	if (isEmptyString(str)){
    	alert('Please enter your Last name.');
    	return false;
     }
	return true;
}

function checkCompany(str){
	if (isEmptyString(str)){
    	alert('Please enter your Company name.');
    	return false;
     }
	return true;
}

function checkPhone(str){
	if (isEmptyString(str)){
    	alert('Please enter your Phone number.');
    	return false;
     }
	return true;
}


function checkBillingPhone(str){
	if (isEmptyString(str)){
    	alert('Please enter your Billing phone number.');
    	return false;
     }
	return true;
}

function checkAddress(str){
	if (isEmptyString(str)){
    	alert('Please enter your Address.');
    	return false;
     }
	return true;
}

function checkCity(str){
	if (isEmptyString(str)){
    	alert('Please enter your City.');
    	return false;
     }
	return true;
}

function checkProvince(str){
	if (isEmptyString(str)){
    	alert('Please select a province/state.');
    	return false;
     }
	return true;
}

function checkCountry(str){
	if (isEmptyString(str)){
    	alert('Please select a country.');
    	return false;
     }
	return true;
}

function checkTopic(str){
	if (isEmptyString(str)){
    	alert('Please enter topic.');
    	return false;
     }
	if (str.length < 5){
    	alert('Please enter at least 5 characters for the topic.');
    	return false;
     }
	return true;
}

function checkDetails(str){
	if (isEmptyString(str)){
    	alert('Please enter details.');
    	return false;
     }
	
	if (str.length < 15){
    	alert('Please eter at least 15 characters for details.');
    	return false;
     }
	
	if (str.length > 250){
    	alert('Maximum 250 characters for details.');
    	return false;
     }
	return true;
}

function checkPostalCode(str){
	if (isEmptyString(str)){
    	alert('Please enter your Postal Code/Zip Code.');
    	return false;
     }
	return true;
}


function checkAnnualRevenue(str){
	if (isEmptyString(str)){
    	alert('Please enter annual revenue');
    	return false;
     }
	return true;
}


function checkCreditCardNumber(str){
	if (isEmptyString(str)){
    	alert('Please enter your Credit Card number.');
    	return false;
     }
	
	var no = trimString(str);

	if((no.length != 16 && no.length != 15 && no.length != 13) || !IsNumeric(no)){
		alert('Please enter a valid Credit Card number.');
    	return false;
	}
	return true;
}


function checkExpiryMonth(str){
	if (isEmptyString(str)){
    	alert('Please enter expiry month.');
    	return false;
     }
	return true;
}



function checkExpiryYear(str){
	if (isEmptyString(str)){
    	alert('Please enter expiry year.');
    	return false;
     }
	
	return true;
}

function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function checkCreditCardType(str){
	if (isEmptyString(str)){
    	alert('Please select Credit Card type.');
    	return false;
     }
	return true;
}

function checkMeetingKey(str){
	
	if (isEmptyString(str)){
    	alert('Please enter a meeting key');
    	return false;
     }
	return true;
}

function checkMeetingUserName(str){
	if (isEmptyString(str)){
    	alert('Please enter a user name.');
    	return false;
     }
	return true;
}

function checkMeetingPassword(str){
	if (isEmptyString(str)){
    	alert('Please enter a password');
    	return false;
     }
	return true;
}

function checkIndustry(str){
	if (isEmptyString(str)){
    	alert('Please enter industry');
    	return false;
     }
	return true;
}


function checkNumberOfPeople(frmName, rbGroupName){ 
		 var radios = document[frmName].elements[rbGroupName]; 
		 for (var i=0; i <radios.length; i++) { 
		  if (radios[i].checked) { 
		   return true; 
		  } 
		 } 
		 alert('Please select how many people in your organization.');
		 return false; 
}


function checkWhenToUse(frmName, rbGroupName){ 
	 var radios = document[frmName].elements[rbGroupName]; 
	 for (var i=0; i <radios.length; i++) { 
	  if (radios[i].checked) { 
	   return true; 
	  } 
	 } 
	 alert('Please select when you likely to begin using PictureTalk.');
	 return false;
}


function checkPlan(frmName, rbGroupName){ 
	 var radios = document[frmName].elements[rbGroupName]; 
	 for (var i=0; i <radios.length; i++) { 
	  if (radios[i].checked) { 
	   return true; 
	  } 
	 } 
	 alert('Please select a plan.');
	 return false; 
}

function checkJobfunction(str){
	if (isEmptyString(str)){
    	alert('Please enter job function.');
    	return false;
     }
	return true;
}


function checkDepartment(str){
	if (isEmptyString(str)){
    	alert('Please enter department.');
    	return false;
     }
	return true;
}


function isSameEmail(email1, email2){
	var e1 = trimString(email1);
	var e2 = trimString(email2);
	if(e1 != e2){
		alert('Email addresses provided are not identical.');
		return false;
	}
	return true;
}

function checkEmail(str) {
	str = trimString(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("Please enter valid e-mail address.");
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter valid e-mail address.");
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter valid e-mail address.");
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter valid e-mail address.");
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter valid e-mail address.");
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter valid e-mail address.");
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter valid e-mail address.");
		    return false
		 }

 		 return true					
	}


