﻿// JScript File

function GetWindowPosY()
{
	var ie=document.all && !window.opera
    var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	return ((ie)? standardbody.clientHeight: window.innerHeight) + 100;
}

function GetWindowPosX()
{
	var ie=document.all && !window.opera
	var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers
    var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	return ((ie)? standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)) ;
}

function getCheckedValue( radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function resetName()
{
    var objName = document.getElementById('customerName');
    if (objName.value == 'Name –Provide information for an extra 10% off your next order.')
    {
        objName.value = '';
    }
}

function resetEmail()
{
    var objEmail = document.getElementById('emailId');
    if (objEmail.value == 'Email')
    {
        objEmail.value = '';
    }
}

function resetPhone()
{
    var objPhone = document.getElementById('phone');
    if (objPhone.value == 'Phone')
    {
        objPhone.value = '';
    }
}
      
function resetQuestion()
{
    var objQuestion = document.getElementById('question');
    if (objQuestion.value == 'Question')
    {
        objQuestion.value = '';
    }
}


function imposeMaxLength(Object, MaxLen)
{
    return (Object.value.length <= MaxLen);
}

function BuildParameterListInitialSurvey()
{
    var customerType = document.forms['customerType'].elements['new_or_old_customer'];
    var task = document.forms['purpose'].elements['purpose_of_visit'];
    var other = document.forms['otherInput'].elements['other'];
    var params = "customer=" + getCheckedValue(customerType) + "&task=" + getCheckedValue(task) + "&other=" + other.value;
    return params;

}  


function checkFields() 
{
var customerTypeObject = document.forms['customerType'].elements['new_or_old_customer'];
var taskObject = document.forms['purpose'].elements['purpose_of_visit'];
var customerType = getCheckedValue( customerTypeObject);
var purpose = getCheckedValue( taskObject);
var otherUserInput = document.getElementById('other').value;
if ((customerType == "") && (purpose == "") && (otherUserInput=="")) 
{
    var elementRef = document.getElementById("errorText")
    var elementValue = "Please answer a question above.";

    if ( elementRef.textContent )
    {
     // Firefox...
     elementRef.textContent = elementValue;
    }
    else if ( elementRef.innerText )
    {
     // IE...
     elementRef.innerText = elementValue;
    }
    return false;
    }
    else 
    {
        return true;
    }
} 

var surveyWindow = null; 
function ServerResponse( page_request)
{
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
        if ( GetCookie( "isQB") == "1")
        {
            surveyWindow = window.open('/fsg/survey/ExperienceSurvey.aspx','Survey','width=360,height=435,left=' + GetWindowPosX() + ',top='+ GetWindowPosY());
        }
        else 
        {
            surveyWindow = window.open('/fsg/survey/ExperienceSurvey.aspx?focus=self','Survey','width=360,height=435,left=100,top=100');
        }
        
	}    
}
function SendHbxData()
{
    var customerType = document.forms['customerType'].elements['new_or_old_customer'];
    var task = document.forms['purpose'].elements['purpose_of_visit'];
    var other = document.forms['otherInput'].elements['other'];
    var otherval = '';
    if ( getCheckedValue(task) == 'other')
    {
        if ( other.value != '')
            otherval = '_' + other.value;
        else
            otherval = '_NO_RESPONSE';
    }
    var customerTypeval = getCheckedValue(customerType);
    var taskval = getCheckedValue(task);
    if ( customerTypeval=='') customerTypeval = 'NO_RESPONSE';
    if ( taskval=='') taskval = 'NO_RESPONSE';
    
    var strHbx =  customerTypeval + "|" + taskval + otherval;
   _hbSet("c3", strHbx);
    _hbSend();
}
function SubmitData( url, params)
{
    if (!checkFields())
        return;
    if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE6 or below
        try {
        page_request = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (e){
            try{
            page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e){}
        }
    }
    else
        return false

        bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
        page_request.onreadystatechange=function(){ServerResponse(page_request)}

        page_request.open('POST', url+bustcacheparameter, true)
        page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        page_request.setRequestHeader("Content-length", params.length);
        page_request.setRequestHeader("Connection", "close");
        page_request.send(params);
        SendHbxData();
        CloseClick();
        
}


function CheckFieldsandClose()
    {
    var customerTypeObject = document.forms['customerType'].elements['new_or_old_customer'];
    var taskObject = document.forms['purpose'].elements['purpose_of_visit'];
    var customerType = getCheckedValue( customerTypeObject);
    var purpose = getCheckedValue( taskObject);
    var otherUserInput = document.getElementById('other').value;
    if((customerType == "") && (purpose == "") && (otherUserInput==""))
        CloseClick();
    }
            

function CloseInitialSurvey()
   {
    var howLong = 5000;
    setTimeout("CheckFieldsandClose()",howLong);
   }
   
   
