function checkEnterKeyToSubmit(e, functionToBeCalled)
{
  var keycode;
  if (window.event)
  {
    keycode = window.event.keyCode;
  }
  else
  {
    keycode = e.which;
  }

  if (keycode == 13)
  {
    getFunction(functionToBeCalled);
  }
  else
  {
    return true;
  }
}
function isValidNaturalNumber(num) // integer number > 0 (0-9)
{  
     return /^[1-9][0-9]*$/.test(num);
}
function getFunction(str)
{
  window[str]();
}

function verify()
{
  if((document.forms[0].userId.value == "") || (document.forms[0].password.value == ""))
   {    
     alert("Both User Name and Password are mandatory.");
     document.forms[0].userId.focus();
     return false;
   }
  return true;  
}
function getNext()
{
  //alert ("while login");
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="login";
  document.forms[0].action="Login.do";
  document.forms[0].submit();
} 

function login()
{  
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="default";
  document.forms[0].action="Login.do";
  document.forms[0].submit();
} 

function goToHome()
{  
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="";
  document.forms[0].action="Index.jsp";
  document.forms[0].submit();
} 

function getMyOption()
{
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="default";
  document.forms[0].action="ViewMyOptions.do";
  document.forms[0].submit();
}
function viewCart()
{ 
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="viewCart";
  document.forms[0].action="PurchaseSubscription.do";   
  document.forms[0].submit();
}
function logout()
{
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="logout";
  document.forms[0].action="Login.do";
  document.forms[0].submit();
}
function salesRepresentativelogout()
{
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="logout";
  document.forms[0].action="SalesRepresentativeLogin.do";
  document.forms[0].submit();
}
function forgotPassword()
{
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="default";
  document.forms[0].action="ForgotPassword.do";
  document.forms[0].submit();
}
function purchaseApplication(id,pType)
{
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="viewContents";
  document.forms[0].productId.value=id;
  document.forms[0].productType.value=pType;
  document.forms[0].action="PurchaseSubscription.do";
  document.forms[0].submit();
}

function ViewProduct(productType, productPurchaseType)
{
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="viewSubCatalog";
  document.forms[0].productType.value=productType;
  document.forms[0].productPurchaseType.value=productPurchaseType;
  document.forms[0].action="ProductCatalog.do";
  document.forms[0].submit();
}

function openNewWindow()
{
  popupWin = window.open('popup_one.htm', 'open_window','menubar=0, toolbar=0, addressbar=0,location=0, directories=0, status=0, scrollbars=1, resizable=1, dependent=0, width=470, height=420, left=0, top=0')
}
function openNewWindow2()
{
  popupWin = window.open('popup_two.htm','open_window','menubar=0, toolbar=0, addressbar=0,location=0, directories=0, status=0, scrollbars=1, resizable=1, dependent=0, width=470, height=420, left=0, top=0')
}
function openNewWindow1()
{
  popupWin = window.open('popup_box2.htm','open_window','menubar=0, toolbar=0, addressbar=0,location=0, directories=0, status=0, scrollbars=1, resizable=1, dependent=0, width=420, height=500, left=0, top=0')
}
function openNewWindowdemo()
{
  var centerX=(screen.width-815)/2;
  var centerY=(screen.height-635)/2;
  popupWin = window.open('popup_demo_econtent.htm','Demonstration','menubar=0,toolbar=0,addressbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=815,height=635,left='+centerX+',top='+centerY);
}
function openNewWindowdemo1()
{
  var centerX=(screen.width-815)/2;
  var centerY=(screen.height-635)/2;
  popupWin = window.open('popup_demo_eschool.htm','Demonstration','menubar=0,toolbar=0,addressbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=815,height=635,left='+centerX+',top='+centerY);
}
function openNewWindowdemo2()
{
  var centerX=(screen.width-815)/2;
  var centerY=(screen.height-635)/2;
  popupWin = window.open('popup_demo_flash_card.htm','Demonstration','menubar=0,toolbar=0,addressbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=815,height=490,left='+centerX+',top='+centerY);
}
function openNewWindowdemo3()
{
  var centerX=(screen.width-760)/2;
  var centerY=(screen.height-630)/2;
  popupWin = window.open('popup_demo_CD_software.htm','Demonstration','menubar=0,toolbar=0,addressbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=760,height=630,left='+centerX+',top='+centerY);
}
function productGuide()
{
  document.forms[0].method="POST";
  document.forms[0].nextStep.value="default";
  document.forms[0].action="PurchaseSubscription.do";
  document.forms[0].submit();
}

function close_window()
{
  self.close();
}
function openELearnScreenShots()
{
  popupWin = window.open('popup_elearn_screenshots.jsp','ELearn_Screenshots','menubar=0,toolbar=0,addressbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=815,height=635,left=100,top=50');
}
  
  
function openESchoolScreenShots()
{
  popupWin = window.open('popup_eschool_screenshots.jsp','ESchool_Screenshots','menubar=0,toolbar=0,addressbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=815,height=635,left=100,top=50');
}

function openEContentScreenShots()
{
  popupWin = window.open('popup_econtent_screenshots.jsp','EContent_Screenshots','menubar=0,toolbar=0,addressbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=815,height=635,left=100,top=50');
}
  
function viewCatalogDetail(pId)
{
  var width =990;
  var height=500;
  document.forms[0].productId.value=pId;
  var strURL = "ProductCatalog_PrpareProductSpecification.jsp";
  var myWindow=window.open(strURL, "Specification", "location=no,menubar=no,resizable=no,titlebar=no,width="+width+",status=no,toolbar=no,height="+height+",scrollbars=yes,top=120,left=100");
  if (myWindow == null || typeof(myWindow) == "undefined")
  {
     alert("You browser has a Pop Up Blocker enabled. Please disable the Pop Up Blocker option and try to open the site.");
  }
  else
  {
    window.opener=self;
  }
}
function isValidString(name) // String (a-z A-Z _ 0-9 . - $ # & ' ' ( ) { } [ ] )
{
  //  alert(/^[a-zA-Z_0-9\.\-]+$/.test(name));
  // return /^[a-zA-Z_0-9\.\-]+$/.test(name);
  return /^[a-zA-Z_0-9\.\-\$#&' '\(\)\{}\[\]\?@,/]+$/.test(name);
}
function isValidContactNumber(num) // Phone & Mobile Number (0-9 + ( ) ' ') not start/end with space
{
  return /^[0-9\-\+\(\)][0-9\-\+\(\)\s]*[0-9\-\+\(\)]?$/.test(num);
}
function isMoreThanOneEmail(email)
{
	    var status=true;
	    var mailArr;
		if(email.indexOf(",") > 0)
		{
		 mailArr=email.split(",");
		var i=0;
			for(i=0;i<mailArr.length;i++)
			{
			  if(!isValidEmailId(mailArr[i]))
			  {
				  status = false;
			  }
			}
			if(status == true)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{   
			mailArr=email;
			if(!isValidEmailId(mailArr))
			  {
				return false;
			  }
			else
			{
				return true;
			}
	}
}
function isValidEmailId(email)
{

  if (email==null)
  {
    return true;
  }
  if (email.length==0)
  {
    return true;
  }
  if (! allValidChars(email))  // check to make sure all characters are valid
  {
    return false;
  }
  if (email.indexOf("@") < 1)  //  must contain @, and it must not be the first character
  {
    return false;
  }
  else if (email.lastIndexOf(".") <= email.indexOf("@"))  // last dot must be after the @
  {
    return false;
  }
  else if (email.indexOf("@") == email.length)   // @ must not be the last character
  {
    return false;
  }
  else if (email.indexOf("..") >=0)  // two periods in a row is not valid
  {
    return false;
  }
  else if (email.lastIndexOf(".") == (email.length -1))   // . must not be the last character
  {
    return false;
  }
  else if (email.indexOf(".") == 0)   // . must not be the first character
  {
    return false;
  }
  else if (email.indexOf("@@") >=0)  // two @ in a row is not valid
  {
    return false;
  }
  var str3 = email.substring(email.lastIndexOf(".")+1,email.length);
  if( str3.length < 2 || str3.length > 3  )
  {
    return false;
  }
  var arrSpChar = new Array('!','&','#','$','%','*','?','|', '\"', '=', '~', '`', '/','\'', '\\', ':', ';', '<', '>', ',', '^', '(', ')', '[', ']', '{', '}', '+');
  for(h=0; h<arrSpChar.length; h++)
  {
    if(email.indexOf( arrSpChar[h] ) >= 0)
    {
    return false;
    }
  }
  return true;
}
function allValidChars(email)
{
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++)
  {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
    continue;
    parsed = false;
    break;
  }
  return parsed;
}

function launchEAssessApp()
{
  //alert('This functionality is in under construction. It will be made avaliable very soon.');

  var width = screen.width;
  var height= screen.height;
  var strURL = "/EAssess/MathPlacementRegistration.do";
  var myWindow=window.open(strURL, "EAssess", "location=yes,menubar=yes,resizable=yes,titlebar=yes,width="+width+",status=no,toolbar=yes,height="+height+",scrollbars=yes,top=0,left=0");
  if (myWindow == null || typeof(myWindow) == "undefined")
  {
     alert("You browser has a Pop Up Blocker enabled. Please disable the Pop Up Blocker option and try to open the site.");
  }
  else
  {
    window.opener=self;
  }

}
