﻿/*-------------------------------------------------------------
	Function toggleLanguage
	Open/Close language dropdown
---------------------------------------------------------------*/

function toggleLanguage(width){
	
	theDropDown = document.getElementById("language")

	if(theDropDown.style.display == "none"){
		theDropDown.style.display = "block";
	}else{
		theDropDown.style.display = "none";
	}
}


/*-------------------------------------------------------------
	Function dropDownProduct
	Open/Close the product dropdown depending on it's state
---------------------------------------------------------------*/

function dropDownProduct(width){
	
	theDropDown = document.getElementById("dropDown" + width)

	if(theDropDown.style.display == "none"){
		theDropDown.style.display = "block";
		document.getElementById("dropDownHolder" + width).className = "dropDownHolder"+ width +"_up_over";
	}else{
		theDropDown.style.display = "none";
		document.getElementById("dropDownHolder"+ width ).className = "dropDownHolder" + width;
	}
}

/*-------------------------------------------------------------
	Function dropDownOver
	Toggle the over/out state for the custom dropdown
---------------------------------------------------------------*/

function dropDownOver(width, state){
	if(state == "over"){
		if(document.getElementById("dropDownHolder" + width).className == "dropDownHolder"+ width +"_up"){
			document.getElementById("dropDownHolder" + width).className = "dropDownHolder"+ width +"_up_over";
		}else{
			document.getElementById("dropDownHolder" + width).className = "dropDownHolder"+ width +"_over";
		}
	}else{
		if(document.getElementById("dropDownHolder" + width).className == "dropDownHolder"+ width +"_up" || document.getElementById("dropDownHolder" + width).className == "dropDownHolder"+ width +"_up_over"){
			document.getElementById("dropDownHolder" + width).className = "dropDownHolder"+ width +"_up";
		}else{
			document.getElementById("dropDownHolder" + width).className = "dropDownHolder" + width;
		}
	}
}






/*-------------------------------------------------------------
	Function openSend
	Toggle visible the login popin
---------------------------------------------------------------*/




function openPopin(which){
	if (which != "home_curseur"){
		positionneDiv(which, 550, 650);
	}
	document.getElementById(which).style.display = "block";
}




/*-------------------------------------------------------------
	Function closeLogin
	Toggle invisible the login popin
---------------------------------------------------------------*/




function closePopin(){
	if(document.getElementById("popin")){
		document.getElementById("popin").style.display="none";
	}
	if(document.getElementById("home_curseur")){
		document.getElementById("home_curseur").style.display="none";
	}
	document.getElementById("pop_send").style.display="none";
	document.getElementById("pop_subscribe").style.display="none";
}






/*-------------------------------------------------------------
	Function openDiv
	Toggle visible the defined div (theId)
---------------------------------------------------------------*/




function openDiv(theId) {
	positionneDiv(theId, 220, 110);
	document.getElementById(theId).style.display="block";
}






/*-------------------------------------------------------------
	Function closeDiv
	Toggle invisible the defined div (theId)
---------------------------------------------------------------*/




function closeDiv(theId) {
	document.getElementById(theId).style.display="none";
}






/*-------------------------------------------------------------
	Function validateSupportRequest
	Validate the support request form.
---------------------------------------------------------------*/




function validateSupportRequest(){
	goon = 0;

	if(document.getElementById("firstname").value == ""){document.getElementById("l_firstname").className="error";goon=1;}else{document.getElementById("l_firstname").className=""}
	if(document.getElementById("lastname").value == ""){document.getElementById("l_lastname").className="error";goon=1;}else{document.getElementById("l_lastname").className="";}
	if(!checkEmail(document.getElementById("email").value)){document.getElementById("l_email").className="error";goon=1;}else{document.getElementById("l_email").className="";}
	if(document.getElementById("description").value == ""){document.getElementById("l_description").className="error";goon=1;}else{document.getElementById("l_description").className="";}
//	if(document.getElementById("subject").value == ""){document.getElementById("l_subject").className="error";goon=1;}else{document.getElementById("l_subject").className="";}

	if (goon == 1){
		document.getElementById("div_error").style.display = "block";
	}else{
		document.getElementById("div_error").style.display = "none";
		document.getElementById("submit_ticket").action = "support_request_thank_you.asp";
		document.getElementById("submit_ticket").submit();
	}
}






/*-------------------------------------------------------------
	Function validateSupportRequestDetail
	Validate the support request form.
---------------------------------------------------------------*/




function validateSupportRequestDetails(){
	goon = 0;

	if(document.getElementById("description").value == ""){goon=1;}else{}
	
	if (goon == 1){
		document.getElementById("div_error").style.display = "block";
	}else{
		document.getElementById("div_error").style.display = "none";
		document.getElementById("submit_ticket").action = "support_request_thank_you.asp";
		document.getElementById("submit_ticket").submit();
	}
}






/*-------------------------------------------------------------
	Function validateLogin
	Validate the login form.
---------------------------------------------------------------*/




function validateLogin(){
	goon = 0;
	
	if(document.getElementById("login_username").value == ""){document.getElementById("l_username").className="error";goon=1;}else{document.getElementById("l_username").className=""}
	if(document.getElementById("login_password").value == ""){document.getElementById("l_password").className="error";goon=1;}else{document.getElementById("l_password").className="";}
	
	if (goon == 1){
		document.getElementById("div_error_login").style.display = "block";
	}else{
		document.getElementById("div_error_login").style.display = "none";
		document.getElementById("login_form").action = "db_login.asp";
		document.getElementById("login_form").submit();
	}
}






/*-------------------------------------------------------------
	Function validateForgot
	Validate the forgot your password form.
---------------------------------------------------------------*/




function validateForgot(redirectTo){
	goon = 0;
	
	if(!checkEmail(document.getElementById("email_address").value)){document.getElementById("l_email_address").className="error";goon=1;}else{document.getElementById("l_email_address").className=""}
	
	if (goon == 1){
		document.getElementById("div_error_forgot").style.display = "block";
	}else{
		document.getElementById("div_error_forgot").style.display = "none";
		document.getElementById("login_forgot").action = "db_forgot.asp?path_query_url=" + redirectTo;
		document.getElementById("login_forgot").submit();
	}
}






/*-------------------------------------------------------------
	Function validateContactSales
	Validate the contact sales form
---------------------------------------------------------------*/

function validateContactSales(){
	goon = 0;
	
	if(document.getElementById("name").value == ""){document.getElementById("l_name").className = "error"; goon = 1;}else{document.getElementById("l_name").className = "";}
	if(!checkEmail(document.getElementById("business_email").value)){document.getElementById("l_business_email").className = "error"; goon = 1;}else{document.getElementById("l_business_email").className = "";}
	
	if(goon == 1){
		document.getElementById("div_error").style.display = "block";
	}else{
		document.getElementById("div_error").style.display = "none";
		document.getElementById("contact_sales").action = "db_contact_sales.asp";
		document.getElementById("contact_sales").submit();
	}
}



/*-------------------------------------------------------------
	Function validateFederalGuide
	Validate the form
---------------------------------------------------------------*/
function validateRegisterGuide(){
	goon = 0;
	action = "thank_you"+ document.getElementById("wpForm").value +".asp";

	if(document.getElementById("firstname").value == ""){document.getElementById("l_firstname").className = "error"; goon = 1;}else{document.getElementById("l_firstname").className = "";}
	if(document.getElementById("lastname").value == ""){document.getElementById("l_lastname").className = "error"; goon = 1;}else{document.getElementById("l_lastname").className = "";}
	if(!checkEmail(document.getElementById("email").value)){document.getElementById("l_email").className = "error"; goon = 1;}else{document.getElementById("l_email").className = "";}
	if(document.getElementById("phone").value != "" ) {if(checkInternationalPhone(document.getElementById("phone").value) == false){document.getElementById("l_phone").className = "error"; goon = 1;}else{document.getElementById("l_phone").className = "";}}else{document.getElementById("l_phone").className = "";}
	if(document.getElementById("country").value == "0"){document.getElementById("l_country").className = "error"; goon = 1;}else{document.getElementById("l_country").className = "";}

	if(document.getElementById("company").value == ""){document.getElementById("l_company").className = "error"; goon = 1;}else{document.getElementById("l_company").className = "";}
	if(document.getElementById("job_title").value == ""){document.getElementById("l_job_title").className = "error"; goon = 1;}else{document.getElementById("l_job_title").className = "";}

	if(goon == 1){
		document.getElementById("div_error").style.display = "block";
	}else{
		document.getElementById("div_error").style.display = "none";
		document.getElementById("federal_guide").action = action;
		document.getElementById("federal_guide").submit();
	}
}




/*-------------------------------------------------------------
	Function forgotPassword
	Toggle visiblility of fields in the login page
---------------------------------------------------------------*/




function forgotPassword(){
	if(document.getElementById("login_forgot").style.display == "none"){
		document.getElementById("login_form").style.display = "none";
		document.getElementById("login_forgot").style.display = "block";
	}else{
		document.getElementById("login_form").style.display = "block";
		document.getElementById("login_forgot").style.display = "none";
	}
}






/*-------------------------------------------------------------
	Function sendEmail
	Used to trigger the STF email
---------------------------------------------------------------*/




	function sendEmail(name,email,friendsname, friendsemail, comments,path_query_url){
		createRequestObject();
		http.open("get", "/4105/db_send.asp?friendsname=" + escape(friendsname) + "&name=" + escape(name) + "&friendsemail=" + friendsemail + "&email=" + email + "&comments=" + escape(comments) + "&path_query_url=" + path_query_url);
		http.onreadystatechange = closeSend;
		http.send(null);
	}

	function closeSend(){
		if(http.readyState == 4){
			var response = http.responseText.split(";");
			if(response[0] == "good"){
				document.getElementById("pop_send_thanks").style.display = "block";
				positionneDiv("pop_send_thanks", 550, 650);
			}
		}
		
	}




/* -------------------------------------------------------------------
   AJAX already define in commun/javascripts/pre-loader.js-------------------------------------------------------------- */
	/*
	function createRequestObject() {		
		var ro;
		if(browserName == "MSIE"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	var http = createRequestObject();
*/



/*-------------------------------------------------------------
	Function subscribe
	Used to subscribe to the newsletter
---------------------------------------------------------------*/




	function subscribe(firstname, lastname, email, company, emailpref, path_query_url){
		location.href = "/4105/db_signup.asp?firstname="+firstname+"&lastname="+lastname+"&email="+email+"&company="+company+"&prefered_format="+emailpref+"&path_query_url="+path_query_url;
	}
	
	
	
	
	
	
/*-------------------------------------------------------------
	Function checkInternationalPhone
	Phone validation
---------------------------------------------------------------*/




	// 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 openFAQ
	Toggle visible selected FAQ category
---------------------------------------------------------------*/




function openFAQ(theFAQ, theButton) {
	if(document.getElementById(theFAQ).style.display=="block"){
		document.getElementById(theFAQ).style.display="none";
		if(theButton != ""){
			document.getElementById(theButton).src="images/b_plus.gif";
		}
	}else{
		document.getElementById(theFAQ).style.display="block";
		if(theButton){
			document.getElementById(theButton).src="images/b_minus.gif";
		}
	}
}






/*-------------------------------------------------------------
	Function toggleTicket
	Toggle visible selected ticket
---------------------------------------------------------------*/




function toggleTicket(){
	if(document.getElementById("currentRequest").style.display == "block"){
		document.getElementById("currentRequest").style.display = "none";
		document.getElementById("a_plus_request").style.display = "block";
		document.getElementById("a_minus_request").style.display = "none";
	}else{
		document.getElementById("currentRequest").style.display = "block";
		document.getElementById("a_plus_request").style.display = "none";
		document.getElementById("a_minus_request").style.display = "block";
	}
}






/*-------------------------------------------------------------
	Function clearFields
	Reset all the initial fields values of a form
---------------------------------------------------------------*/



function clearFields(){
	var texts=document.getElementsByTagName('input')
	for (var i_tem = 0; i_tem < texts.length; i_tem++){
		if (texts[i_tem].type=='text'){
			texts[i_tem].value=''
		}
	}
	
	var textareas=document.getElementsByTagName('textarea')
	for (var i_tem = 0; i_tem < textareas.length; i_tem++){
		textareas[i_tem].value=''
	}
	
	var selects=document.getElementsByTagName('select')
	for (var i_tem = 0; i_tem < selects.length; i_tem++){
		selects[i_tem].selectedIndex = "0";
	}
}





/*-------------------------------------------------------------
	Function openCurseur
	open the curseur flash.
---------------------------------------------------------------*/



	





/*-------------------------------------------------------------
	Function closeCurseur
	close the curseur flash
---------------------------------------------------------------*/



	function closeCurseur(){
		document.getElementById("home_curseur").style.display = "none";
	}
	





/*-------------------------------------------------------------
	Function validateRequestDemo
	Validate the contact sales form
---------------------------------------------------------------*/




function validateRequestDemo(){
	goon = 0;
	
	if(document.getElementById("name").value == ""){document.getElementById("l_name").className = "error"; goon = 1;}else{document.getElementById("l_name").className = "";}
	if(document.getElementById("title_role").value == ""){document.getElementById("l_title_role").className = "error"; goon = 1;}else{document.getElementById("l_title_role").className = "";}
	if(document.getElementById("company").value == ""){document.getElementById("l_company").className = "error"; goon = 1;}else{document.getElementById("l_company").className = "";}
	if(document.getElementById("country").value == "0"){document.getElementById("l_country").className = "error"; goon = 1;}else{document.getElementById("l_country").className = "";}
	if(checkInternationalPhone(document.getElementById("business_phone").value) == false){document.getElementById("l_business_phone").className = "error"; goon = 1;}else{document.getElementById("l_business_phone").className = "";}
	if(!checkEmail(document.getElementById("business_email").value)){document.getElementById("l_business_email").className = "error"; goon = 1;}else{document.getElementById("l_business_email").className = "";}
	if(document.getElementById("products_interest").value == "0"){document.getElementById("l_products_interest").className = "error"; goon = 1;}else{document.getElementById("l_products_interest").className = "";}
	
	if(goon == 1){
		document.getElementById("div_error").style.display = "block";
	}else{
		document.getElementById("div_error").style.display = "none";
		document.getElementById("request_demo").action = "db_request_demo.asp";
		document.getElementById("request_demo").submit();
	}
}
	





/*-------------------------------------------------------------
	Function validateEmailQuestion
	Validate the contact sales form
---------------------------------------------------------------*/




function validateEmailQuestion(){
	goon = 0;
	
	if(document.getElementById("name").value == ""){document.getElementById("l_name").className = "error"; goon = 1;}else{document.getElementById("l_name").className = "";}
	if(!checkEmail(document.getElementById("business_email").value)){document.getElementById("l_business_email").className = "error"; goon = 1;}else{document.getElementById("l_business_email").className = "";}
	
	if(goon == 1){
		document.getElementById("div_error").style.display = "block";
	}else{
		document.getElementById("div_error").style.display = "none";
		document.getElementById("email_question").action = "db_email_question.asp";
		document.getElementById("email_question").submit();
	}
}






/*-------------------------------------------------------------
	Function SetCookie
---------------------------------------------------------------*/


function SetCookie (name, value) {  
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4)?argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;

    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}





/*-------------------------------------------------------------
	Function GetCookie
---------------------------------------------------------------*/


function GetCookie (name) {  
    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while (i < clen) {    
        var j = i + alen;    
        if (document.cookie.substring(i, j) == arg)      
        return getCookieVal (j);    
        i = document.cookie.indexOf(" ", i) + 1;    
        if (i == 0) break;   
    }  
    return null;
}




/*-------------------------------------------------------------
	Function getCookieVal
---------------------------------------------------------------*/


function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


/*-------------------------------------------------------------
	Function DeleteCookie
---------------------------------------------------------------*/
function DeleteCookie( name, path, domain ) {
    if ( GetCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
