// JavaScript Document

function checkmail(x)
{
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (filter.test(x)) return true;
  else return false;
}

// Removes all whitespace characters 
// from start and end of a string 
function trim(sString) 
{ 
  sTrimmedString = ""; 
  if (sString != "") 
  { 
    var iStart = 0; 
    var iEnd = sString.length - 1; 
    var sWhitespace = " \t\f\n\r\v"; 
		   
    while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) 
    { 
      iStart++; 
      if (iStart > iEnd) 
        break; 
    } 
	    
    // If the string not just whitespace 
    if (iStart <= iEnd) 
    { 
      while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1) 
        iEnd--; 
     
      sTrimmedString = sString.substring(iStart,++iEnd); 
    } 
  } 
  return sTrimmedString; 
} 

function Check_signin()
{
  var result = false
  var jEmailId = window.document.ppSignOn.ppEmail.value;			
  jEmailId = trim(jEmailId);
  if ((checkmail(jEmailId) == false && jEmailId.length>0 ) || (trim(jEmailId)==''))
  {
    alert('Please enter your e-mail address');
    window.document.ppSignOn.ppEmail.focus()
    return false;
  }		
  return true;
}

//
// function: Check_Data()
// Validate the values on the prism pass registration form
//
function Check_Data() {
  // get form values
  var result = false
  var theStr = window.document.ppCreateAccount.businessEmail.value;
  var index = theStr.indexOf("@")
  var jEmailId = window.document.ppCreateAccount.businessEmail.value;
  jEmailId = trim(jEmailId);
  var strFName =  trim(window.document.ppCreateAccount.firstName.value);  
  var strLName =  trim(window.document.ppCreateAccount.lastName.value);  
  var strCompName = trim(window.document.ppCreateAccount.companyName.value); 
  var strPhoneNum = trim(window.document.ppCreateAccount.businessPhone.value);   
  var txtCountry = window.document.ppCreateAccount.businessCountry.value;

  var msg = 'Required information is partial/missing.';
  var emailmsg = 'Sorry - we do not accept free E-mail addresses such as Hotmail, Yahoo etc.';   
  var strIndustry = trim(window.document.ppCreateAccount.industry.value); 			

// Older form values which are no longer needed
//  var txtState = window.document.ppCreateAccount.companyState.value;		
//  var strAdd1 = trim(window.document.ppCreateAccount.companyAddress1.value);
//  var strCity = trim(window.document.ppCreateAccount.companyCity.value);    
//  var strJobTitle = window.document.ppCreateAccount.jobTitle.value;
//  var strJobRole =  window.document.ppCreateAccount.cboJobRole.value;
//  var strZip = window.document.ppCreateAccount.postalCode.value;

  if (trim(strFName).length < 1 )
  {				
    alert('Please enter your "First name".');
    window.document.ppCreateAccount.firstName.focus();
    return (false);
  }
  if (checktext(strFName) == false)
  {
    alert('Invalid characters entered in "First name"');
    window.document.ppCreateAccount.firstName.focus();
    return (false);
  }
  if (trim(strLName).length < 1 )
  {				
    alert('Please enter your "Last name".');
    window.document.ppCreateAccount.lastName.focus();
    return (false);
  }			
  if (checktext(strLName) == false)
  {
    alert('Invalid characters found in "Last name"');
    window.document.ppCreateAccount.lastName.focus();
    return (false);
  }
  if ((checkmail(jEmailId) == false ) || (trim(jEmailId)==''))
  {
    alert('Please enter a valid Business e-mail');
    window.document.ppCreateAccount.businessEmail.focus();
    return false;
  }	
  
  var aEmailId = jEmailId.split('@')
  var jSiteName = aEmailId[1].toLowerCase();
  var aSiteSplit = jSiteName.split('.')
  var jURL = aSiteSplit[1].toLowerCase();						

/*
 * We will allow public email systems
 *
  if(jSiteName.substring(0,3)=='msn')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,5)=='yahoo')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,7)=='hotmail')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,3)=='aol')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,5)=='gmail')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,5)=='lycos')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
*/
  if(jSiteName.substring(0,3)=='123')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,11)=='spamgourmet')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,7)=='spambob')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,10)=='mailinator')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,11)=='mytrashmail')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,7)=='dodgeit') 
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,10)=='rediffmail')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,3)=='126')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,3)=='163')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  
/*
 * No checking of country
 *  
  if(jURL.substring(0,2)=='pk')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
				
  if(jURL.substring(0,2)=='ru')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jURL.substring(0,2)=='gr')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
 */
 
  if ((strPhoneNum).length <5)
  {
    alert('Please enter your complete "Phone Number".');
    window.document.ppCreateAccount.businessPhone.focus();
    return (false);
  }
  if (checkPhone(strPhoneNum)==false)
  {
    alert('Please enter your complete and valid "Phone Number"'); 
    window.document.ppCreateAccount.businessPhone.focus();
    return (false);
  }
			
  if (trim(strCompName).length < 1)
  {
    alert('Please enter your  "Company name"');
    window.document.ppCreateAccount.companyName.focus();
    return (false);
  }
  else if (checkComp(strCompName) == false)
  {
    alert('Invalid characters found in "Company name"');
    window.document.ppCreateAccount.companyName.focus();
    return (false);
  }
			
  if (txtCountry == '0')
  {
    alert('Please select the "Country".');
    window.document.ppCreateAccount.businessCountry.focus();
    return (false);
  }
			
/*
 * NOT USED
 *
  if (checkZip(strZip)==false && trim(strZip).length >0)
  {
    alert('Please enter valid "Zip code"');
    window.document.ppCreateAccount.postalCode.focus();
    return (false);
  }
*/
  
  var x;
	
  if(strIndustry=='0')
  {
    alert('Please select your "Industry".');
    window.document.ppCreateAccount.industry.focus();
    return (false);
  }

/*
 * NOT USED
 *
  var strEvtCat="";
  if(strEvtCat!="1")
  {
 
    var strComputer=window.document.ppCreateAccount.computer.value;
    var strTimeframe=window.document.ppCreateAccount.timeframe.value;
    if (document.forms.length > 0) 
    {
      var field = document.forms[0];
      for (i = 0; i < field.length; i++) 
      {
      if (field.elements[i].type == "checkbox")
      {
        if(field.elements[i].checked)
        {
          bool="1"
         break;
        }	
      }
    }
  }
  
  if(bool!="1")
  {
    alert("Please select the 'Important features'.");
    document.ppCreateAccount.chkFeature1.focus();
    return false;
  }  
														
  if(strComputer=="0")
  {
    alert('Please select "How Many Computers".');
    window.document.ppCreateAccount.computer.focus();
    return (false);
  }		
  if(strTimeframe=="0")
  {
    alert('Please select "Timeframe for Purchase".');
    window.document.ppCreateAccount.timeframe.focus();
    return (false);
  }		
  }
*/			
  
  if (check_Cookie()==false)
  {
    alert('We have detected that you have blocked cookies on your browser. To view premium content you are required to allow cookies.')
    return false;
  }

  return (true);
}			

function checkInteger(x)
{
  var filter  = /^([0-9])+$/;
  if (filter.test(x)) return true;
  else return false;
}

function checkmail(x)
{
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (filter.test(x)) return true;
  else return false;
}

function checktext(x)
{
  var filter  = /^([a-zA-Z \''\.\-])+$/;
  if (filter.test(x)) return true;
  else return false;
}

function checkPhone(x)
{
  var retval = false;
  strString = trim(x);
  var phonelen = x.length;
			
  var filter  = /^([a-zA-Z \0-9\.\-])+$/;
  if (filter.test(x))
    retval = true;
  else retval= false;
    iStart=0;
  
  iFound=0
  var strValidChars = "0123456789";
  var strChar;
			
  //  test strString consists of valid characters listed above
  for (iStart= 0; iStart < phonelen ; iStart++)
  {
    strChar = strString.charAt(iStart);
    if (strValidChars.indexOf(strChar) > -1)
    {
      iFound++;
    }
				
  }
			
  if (iFound>4 && retval==true)
    return true;
  else
    return false;
}	
	
function checkComp(x)
{
  var filter  = /^([a-zA-Z \0-9\''\.\-])+$/;
  if (filter.test(x)) return true;
  else return false;
}
function checkZip(x)
{
  var filter  = /^([a-zA-Z\0-9])+$/;
  if (filter.test(x)) return true;
  else return false;
}

// Removes all whitespace characters 
// from start and end of a string 
function trim(sString) 
{ 
  sTrimmedString = ""; 
  if (sString != "") 
  { 
    var iStart = 0; 
    var iEnd = sString.length - 1; 
    var sWhitespace = " \t\f\n\r"; 
		      
    while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) 
    { 
      iStart++; 
      if (iStart > iEnd) 
        break; 
    } 
		      
    // If the string not just whitespace 
    if (iStart <= iEnd) 
    { 
      while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1) 
        iEnd--; 

      sTrimmedString = sString.substring(iStart,++iEnd); 
    } 
  } 
  return sTrimmedString; 
} 
		
function reset_form()
{			
  window.document.ppCreateAccount.reset();
}
		
function check_Cookie()
{
  // remember, these are the possible parameters for Set_Cookie:
  // name, value, expires, path, domain, secure
  Set_Cookie( 'test', 'none', '', '/', '', '' );
  
  // if Get_Cookie succeeds, cookies are enabled, since 
  //the cookie was successfully created.
  if ( Get_Cookie( 'test' ) )
  {	
    return true;
    // and these are the parameters for Delete_Cookie:
    // name, path, domain
    // make sure you use the same parameters in Set and Delete Cookie.
    Delete_Cookie('test', '/', '');
  }
  // if the Get_Cookie test fails, cookies 
  //are not enabled for this session.
  else
  {
    return false;
  }
}
	
function Get_Cookie(name) 
{ 
  var start = document.cookie.indexOf(name+"="); 
  var len = start+name.length+1; 
  if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
  if (start == -1) return null; 
  var end = document.cookie.indexOf(";",len); 
  if (end == -1) end = document.cookie.length; 
  return unescape(document.cookie.substring(len,end)); 
} 

function Set_Cookie(name,value,expires,path,domain,secure) 
{ 
  var cookieString = name + "=" +escape(value) + 
        ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") + 
        ( (secure) ? ";secure" : ""); 
        document.cookie = cookieString; 
} 

function Delete_Cookie(name,path,domain) 
{ 
  if (Get_Cookie(name)) document.cookie = name + "=" + 
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") + 
        ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
} 
	
function openChromelessWindow(winUrl, w, h) 
{ 
  if(w == "")
    w = '300';
	
  if(h == "") 
    h = '300';
	
  openWindowRef = window.open(winUrl,'openChromeless',
'left=20,top=20,width='+w+',height='+h+',toolbar=0,resizable=0,location=0,directories=0,status=0,menubar=0,scrollbars=1');
//  window (openWindowRef.focus());
  
  if (window.focus) {openWindowRef.focus()}
	return false;

  return;
} 

function openLinkInParent(winUrl) 
{ 
  self.opener.location = winUrl;
  self.opener.focus();
} 

//
// function: demoFormCheck()
// Validate the values on the request demo form
//
function demoFormCheck() {
  // get form values
  var result = false
  var theStr = window.document.ppCreateAccount.businessEmail.value;
  var index = theStr.indexOf("@")
  var jEmailId = window.document.ppCreateAccount.businessEmail.value;
  jEmailId = trim(jEmailId);
  var strFName =  trim(window.document.ppCreateAccount.firstName.value);  
  var strLName =  trim(window.document.ppCreateAccount.lastName.value);  
  var strCompName = trim(window.document.ppCreateAccount.companyName.value); 
  var strPhoneNum = trim(window.document.ppCreateAccount.businessPhone.value);   

  var msg = 'Required information is partial/missing.';
  var emailmsg = 'Sorry - we do not accept free E-mail addresses such as Hotmail, Yahoo etc.';   

  if (trim(strFName).length < 1 )
  {				
    alert('Please enter your "First name".');
    window.document.ppCreateAccount.firstName.focus();
    return (false);
  }
  if (checktext(strFName) == false)
  {
    alert('Invalid characters entered in "First name"');
    window.document.ppCreateAccount.firstName.focus();
    return (false);
  }
  if (trim(strLName).length < 1 )
  {				
    alert('Please enter your "Last name".');
    window.document.ppCreateAccount.lastName.focus();
    return (false);
  }			
  if (checktext(strLName) == false)
  {
    alert('Invalid characters found in "Last name"');
    window.document.ppCreateAccount.lastName.focus();
    return (false);
  }
  if ((checkmail(jEmailId) == false ) || (trim(jEmailId)==''))
  {
    alert('Please enter a valid Business e-mail');
    window.document.ppCreateAccount.businessEmail.focus();
    return false;
  }	
  
  var aEmailId = jEmailId.split('@')
  var jSiteName = aEmailId[1].toLowerCase();
  var aSiteSplit = jSiteName.split('.')
  var jURL = aSiteSplit[1].toLowerCase();						

  if(jSiteName.substring(0,3)=='123')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,11)=='spamgourmet')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,7)=='spambob')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,10)=='mailinator')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,11)=='mytrashmail')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,7)=='dodgeit') 
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,10)=='rediffmail')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,3)=='126')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
  if(jSiteName.substring(0,3)=='163')
  {
    alert(emailmsg);
    window.document.ppCreateAccount.businessEmail.focus();
    return (false);
  }
 
  if ((strPhoneNum).length <5)
  {
    alert('Please enter your complete "Phone Number".');
    window.document.ppCreateAccount.businessPhone.focus();
    return (false);
  }
  if (checkPhone(strPhoneNum)==false)
  {
    alert('Please enter your complete and valid "Phone Number"'); 
    window.document.ppCreateAccount.businessPhone.focus();
    return (false);
  }
			
  if (trim(strCompName).length < 1)
  {
    alert('Please enter your  "Company name"');
    window.document.ppCreateAccount.companyName.focus();
    return (false);
  }
  else if (checkComp(strCompName) == false)
  {
    alert('Invalid characters found in "Company name"');
    window.document.ppCreateAccount.companyName.focus();
    return (false);
  }
			
  if (txtCountry == '0')
  {
    alert('Please select the "Country".');
    window.document.ppCreateAccount.businessCountry.focus();
    return (false);
  }
			  
  if (check_Cookie()==false)
  {
    alert('We have detected that you have blocked cookies on your browser. To view premium content you are required to allow cookies.')
    return false;
  }

  return (true);
}	

//
// function: rightClick()
// prevent a right click
//
function rightClick(e) {
  if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) 
  {
    return false;
  }
  else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) 
  {
    alert("Sorry, you do not have permission to right click.");
    return false;
  }
  return true;
}

// set up the event captures
document.onmousedown=rightClick;
document.onmouseup=rightClick;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=rightClick;
window.onmouseup=rightClick;

