
var WindowObjectReference = null; // global variable
				
	function openFFPromotionPopup(path , imgName , width , height)
	{
		var myImg = new String(imgName);
					
	if(WindowObjectReference == null || WindowObjectReference.closed)
	
	{
		WindowObjectReference = window.open(path + "?img=" + imgName,
			"PromoteFirefoxWindowName", "resizable=yes,scrollbars=yes,top=100,left=100,status=yes,width="+width+",height="+height );
	
	}
	else
	{
		WindowObjectReference.focus();
	
	};
}

function noenter() 
{
	return !(window.event && window.event.keyCode == 13); 
}

// 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 isValidEmail(email) {

  
 var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
  
 var check=/@[\w\-]+\./;
  
 var checkend=/\.[a-zA-Z]{2,4}$/; 
 if(((email.search(exclude) != -1) ||
       (email.search(check)) == -1) ||
       (email.search(checkend) == -1)){
      return false;
   } else {
      return true;
   }
}


function trim(inputString) {
   
   if (typeof inputString != "string") { return inputString; }
   var myVal = inputString;
   var ch = myVal.substring(0, 1);
   while (ch == " ") { 
      myVal = myVal.substring(1, myVal.length);
      ch = myVal.substring(0, 1);
   }
   ch = myVal.substring(myVal.length-1, myVal.length);
   while (ch == " ") { 
      myVal = myVal.substring(0, myVal.length-1);
      ch = myVal.substring(myVal.length-1, myVal.length);
   }
   while (myVal.indexOf("  ") != -1) { 
      myVal = myVal.substring(0, myVal.indexOf("  ")) + myVal.substring(myVal.indexOf("  ")+1, myVal.length); 
   }
   return myVal; 
} 


function isChecked(object) {
    if (object.checked) return true;
    else return false;
}

function CloseDivs(){

	document.getElementById("divContent").style.display="inline";
	document.getElementById("divMessage").style.display="none";
}

function ValidateRegister()
{//debugger;
	  var errorMessage = "Please fix the following errors: \n\n";
	 
	  var errorFound = 0;
	 
	  var email = trim(document.getElementById("RightMenu1_txtValidateMail").value)
	
	
	  if (email.indexOf("salesforce.com") >= 0) 
	{
   		
	  errorFound = 1;
		
	  errorMessage += "The sender's Email address can not contain 'salesforce.com'. \n"
	
	  }
	  if ((email.indexOf("gmail.com") >= 0) ||
	      (email.indexOf("yahoo.com") >= 0) ||
	      (email.indexOf("yahoo.ca") >= 0) ||
	      (email.indexOf("hotmail.com") >= 0) ||
	      (email.indexOf("googlemail.com") >= 0) ||
	      (email.indexOf("mail.ru") >= 0) ||
	      (email.indexOf("list.ru") >= 0) ||
	      (email.indexOf("free.fr") >= 0) )
	{
   		
	  errorFound = 1;
		
	  errorMessage += "You must provide a corporate email address. \n"
	
	  }
	  

	  
	if ( isValidEmail(email)==false )
	{
		errorFound = 1;
		errorMessage += " Email was not in a correct format ex: name@domain. \n"
	}
	if (trim(document.getElementById("RightMenu1_txtValidatePswd").value)=="")
	{
		errorFound = 1;
		errorMessage += " password can not be empty. \n"
	}
	if (errorFound==1)
	{
		alert (errorMessage)
		return false;
	}
	return true;
}
function ChangeSelectState(num)
{
	var objCountry; 
	var objState ;
	
	if (num==0){
	objCountry = document.getElementById("ddlCountry");
	objState = document.getElementById("ddlState");
	}
	else{
	objCountry = document.getElementById("ContactForm1_ddlCountry");
	objState = document.getElementById("ContactForm1_ddlState");
	}
	
	if (objCountry.options[objCountry.selectedIndex].value==225)
	{	objState.disabled = false}
	else{
		objState.selectedIndex=0;
		objState.disabled = true
		}
}

function validateForm(formId) {
   
 
var objCountry;
   var objState;
   p = new Array();
 

if (formId == 1) {         // Quick contact
      p[0] = "ContactForm1_txtFirstName";
     
p[1] = "ContactForm1_txtLastName";
      p[2] = "ContactForm1_txtJob";
     
p[3] = "ContactForm1_txtCompany";
      p[4] = "ContactForm1_txtPhone";
      
p[5] = "ContactForm1_txtEmail";
      
objCountry = document.getElementById("ContactForm1_ddlCountry")
      
objCity = document.getElementById("ContactForm1_ddlState")
   }
    
else if (formId == 2) {  // Partners
      p[0] = "txtFirstName";
      p[1] = "txtLastName";
   
p[2] = "txtJob";
      p[3] = "txtCompany";
      p[4] = "txtPhone";
      p[5] = "txtEmail";
     
objCountry = document.getElementById("ddlCountry")
      
objCity = document.getElementById("ddlState")
   }  
   
else if(formId == 3){//eval download
	  p[0] = "txtFirstName";
      p[1] = "txtLastName";
    
p[2] = "txtJob";
      p[3] = "txtCompany";
      p[4] = "txtPhone";
      p[5] = "txtEmail";
  
// p[6] = "chkLoadTesting"
      //p[7] = "chkFunctionalTesting"
      //p[8] = "chkMgTest";
//checkMgTest  
      
objCountry = document.getElementById("ddlCountry")
       
objCity = document.getElementById("ddlState")
   }
    
else if (formId == 4) {  // Partners
      p[0] = "txtFirstName";
      p[1] = "txtLastName";
   
p[2] = "txtJob";
      p[3] = "txtCompany";
      p[4] = "txtPhone";
      p[5] = "txtEmail";
   
objCountry = document.getElementById("ddlCountry")
    
objCity = document.getElementById("ddlState")
   } 

  
var errorMessage = "Please fix the following errors: \n\n";
   
var errorFound = 0;
   
   
if ( trim( document.getElementById(p[0]).value)==""){
		
errorMessage = errorMessage + " First Name can not be empty. \n"
		errorFound=1;
  }
	
 
if ( trim( document.getElementById(p[1]).value)==""){
		
errorMessage = errorMessage + " Last Name can not be empty. \n"
		errorFound = 1;
   }
   
if ( trim( document.getElementById(p[2]).value)==""){
		
errorMessage = errorMessage + " Job Title can not be empty. \n"	
		errorFound = 1;
   }
 
if ( trim( document.getElementById(p[3]).value)==""){
		
errorMessage = errorMessage + " Company can not be empty. \n"	 		 
		errorFound = 1;
	}
	
	var phone =trim(document.getElementById(p[4]).value)
	if (checkInternationalPhone(phone)==false){
		errorMessage = errorMessage + " Phone number is not valid. \n"
		errorFound = 1;
	}
	
	var email = trim(document.getElementById(p[5]).value)
	
if (email.indexOf("salesforce.com") >= 0) {
	 	errorFound = 1;
		errorMessage += "The sender's Email address can not contain 'salesforce.com'. \n"
	}	 
	

 if ((email.indexOf("gmail.com") >= 0) ||
	      (email.indexOf("yahoo.com") >= 0) ||
	      (email.indexOf("yahoo.ca") >= 0) ||
	      (email.indexOf("googlemail.com") >= 0) ||
	      (email.indexOf("hotmail.com") >= 0) ||
	      (email.indexOf("mail.ru") >= 0) ||
	      (email.indexOf("list.ru") >= 0) ||
	      (email.indexOf("free.fr") >= 0) )
	{
   		
	  errorFound = 1;
		
	  errorMessage += "You must provide a corporate email address. \n"
	
	  }

if ( isValidEmail(email)==false )
	{
		errorFound = 1;
		errorMessage += " Email was not in a correct format ex: name@domain. \n"
	}
	
	if (objCountry.options[objCountry.selectedIndex].value==0)
		{
			errorFound = 1;
			errorMessage += " You must select a country. \n"
		}
	else if (objCountry.options[objCountry.selectedIndex].value==225 && objCity.options[objCity.selectedIndex].value==0)
		{
			errorFound = 1;
			errorMessage += " You must select a state. \n"
		}
	
	
	/*if (formId ==3)
	{
		if (!isChecked(document.getElementById(p[6])) && !isChecked(document.getElementById(p[7]))  )
		{
			errorFound = 1;
			errorMessage += " You must select at least one product to download. \n"
		}
		
	}*/
		
			
	if (formId==4)
	{
		if (errorFound==1)
		{
			alert (errorMessage)
			return false;
		}
		return true;
	}

	
	if (errorFound==1)
	{
		alert (errorMessage)
		return false;
	}
	return true;
}

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		
		$(this).children('div').each(function(i){
		    if($(this).innerHeight() > currentTallest) {currentTallest = $(this).innerHeight(); }
		    //if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
			//alert($(this).height());
		});
		//alert(currentTallest);
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		var cssname = 'min-height';
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children('div').css({'min-height': currentTallest}); 
		$(this).children('div').css({'height': currentTallest}); 
		$(this).height(currentTallest - ($(this).innerHeight() - $(this).height())); 
	});
	return this;
};
