﻿// initialize XMLHttpRequest object
var xmlobj=null;
// initialize global variables
var data=new Array();
var i=0;


window.onresize = function()
{
    if (document.getElementById('container')){
        fixPosition(document.getElementById('container'));
        fixBGPosition(document.getElementById('blackOut'));
    }
}
function contactUs(){
    try {
    var pageTracker = _gat._getTracker("UA-9352772-6");
    pageTracker._trackPageview("/contactUs.aspx");
    } catch(err) {}
    currentScroll = document.documentElement.scrollTop;
	document.getElementById('currentPageVar').value='contactUs';
    sendRequest('../scripts/contactUs.source.htm');
	
	

}
function getFaqs(){
    try {
    var pageTracker = _gat._getTracker("UA-9352772-6");
    pageTracker._trackPageview("/faqs.aspx");
    } catch(err) {}
    currentScroll = document.documentElement.scrollTop;
	document.getElementById('currentPageVar').value='contactUs';
    sendRequest('../scripts/faqs.source.htm');

}
function distributors(){
    try {
    var pageTracker = _gat._getTracker("UA-9352772-6");
    pageTracker._trackPageview("/distributors.aspx");
    } catch(err) {}
    currentScroll = document.documentElement.scrollTop;
	document.getElementById('currentPageVar').value='contactUs';
    sendRequest('../scripts/distributors.source.htm');

}
function video(){
    try {
    var pageTracker = _gat._getTracker("UA-9352772-6");
    pageTracker._trackPageview("/video.aspx");
    } catch(err) {}
    currentScroll = document.documentElement.scrollTop;
	document.getElementById('currentPageVar').value='contactUs';
    sendRequest('../scripts/video.source.htm');

}
function nfda(){
    try {
    var pageTracker = _gat._getTracker("UA-9352772-6");
    pageTracker._trackPageview("/nfda.aspx");
    } catch(err) {}
    currentScroll = document.documentElement.scrollTop;
	document.getElementById('currentPageVar').value='contactUs';
    sendRequest('../scripts/nfda.source.htm');

}



function contactUsSelect(theSelection){
	//document.getElementById('cbgStandard').style.backgroundPosition = '-352px';
	
	contactSelect(theSelection);
	document.getElementById('currentPageVar').value='contactUs'+ theSelection;
    sendRequest('../scripts/contactUs.source.' + theSelection + '.htm');
	
	
}
function contactSelect(theSelection){
	var theElements=new Array('Standard', 'Fleet', 'Signs', 'Cust', 'TBS');

    for (x=0; x<theElements.length; x++){
	     if(theElements[x] != theSelection){
             
		 	//document.getElementById('lnk' + theElements[x]).style.display='block';
			var theInnerHTML = "<a href=" + '"' +  "javascript:contactUsSelect("+"'"+theElements[x]+"')"+'"' +"class="+'"'+"contactProdSelContainer2 csLink"+'"' +" onmouseover="+'"'+"pSelect('cbg"+theElements[x]+"','ctxt"+theElements[x]+"',1)"+'"'+" onmouseout="+'"'+"pSelect('cbg"+theElements[x]+"','ctxt"+theElements[x]+"',2)"+'"'+" onmousedown="+'"'+"pSelect('cbg"+theElements[x]+"','ctxt"+theElements[x]+"',3)"+'"'+"></a>"
			//alert(theInnerHTML);
			document.getElementById('lnk' + theElements[x]).innerHTML=theInnerHTML;
			document.getElementById('cbg' + theElements[x]).style.backgroundPosition = '0px';
			document.getElementById('ctxt' + theElements[x]).style.textDecoration = 'none';
		 }else{
			document.getElementById('lnk' + theElements[x]).innerHTML = '';
			document.getElementById('cbg' + theElements[x]).style.backgroundPosition = '-352px';
		 }
	}
//<a href="javascript:contactUsStandardVehicles()" class="contactProdSelContainer2 csLink" onmouseover="pSelect('cbgStandard','ctxtStandard',1)" onmouseout="pSelect('cbgStandard','ctxtStandard',2)" onmousedown="pSelect('cbgStandard','ctxtStandard',2)" onmouseup="pSelect('cbgStandard','ctxtStandard',1)"></a>
}
function sendRequest(doc){
    // check for existing requests
    
    if(xmlobj!=null&&xmlobj.readyState!=0&&xmlobj.readyState!=4){
        xmlobj.abort();
    }
    try{
        // instantiate object for Firefox, Nestcape, etc.
        xmlobj=new XMLHttpRequest();
    }
    catch(e){
        try{
            // instantiate object for Internet Explorer
            xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e){
            // Ajax is not supported by the browser
            xmlobj=null;
            return false;
        }
    }
    // assign state handler
    xmlobj.onreadystatechange=stateChecker;
    // open socket connection
    xmlobj.open('GET',doc,true);
    // send request
    xmlobj.send(null);
}
function stateChecker(){
    // if request is completed
    if(xmlobj.readyState==4){
        // if status == 200 display text file
        if(xmlobj.status==200){
            // create data container
            createDataContainer();
            // display data into data container
            data=xmlobj.responseText.split('|');
            displayData();
        }
        else{
            alert('Failed to get response :'+ xmlobj.statusText);
        }
    }
}

function createDataContainer(){
	
	if (document.getElementById('currentPageVar').value == 'contactUs'){
		var div=document.createElement('div');
		var blackOutDiv=document.createElement('blackOutDiv');
		div.setAttribute('id','container');
		blackOutDiv.setAttribute('id','blackOut');
		// bodyWidth = Browser Width
		bodyWidth = document.body.offsetWidth;
		// minContactWidth = Minimum Dialoge Width
		minContactWidth = 1000;
		if (bodyWidth > minContactWidth){
			offset=((bodyWidth-minContactWidth) / 2);
			blackOutWidth=bodyWidth;
			//minContactWidth = bodyWidth;
		}else{
			offset=0;
			blackOutWidth=minContactWidth;
		}

		bodyHeight = document.body.offsetHeight;
		if(div.style){
		
			div.style.width=minContactWidth + 'px';
			div.style.height=bodyHeight + 'px';
			div.style.position='absolute';
			div.style.top='0px';

			div.style.left=offset + 'px';
			div.className='contactMain';
			
			blackOutDiv.style.width=blackOutWidth + 'px';
			blackOutDiv.style.height=bodyHeight + 'px';
			//blackOutDiv.style.height='10000px';
			blackOutDiv.style.left='0px';
			blackOutDiv.style.top='0px';
			blackOutDiv.style.position='absolute';
			blackOutDiv.style.display='none';
			document.getElementsByTagName('body')[0].appendChild(blackOutDiv);
			if (checkIE() == 1){
				divInnerHTML=fixIE6('img/contactBG.png',blackOutWidth,bodyHeight);

			}else{
				divInnerHTML = "<img src='../img/contactBG.png' width='" + blackOutWidth + "px' height='" + bodyHeight + "px' alt='' />";
			}
			document.getElementById('blackOut').innerHTML = divInnerHTML;
			//document.getElementById('blackOut').style.backgroundColor='blue';
            document.getElementsByTagName('body')[0].appendChild(div);
			//document.getElementById('blackOut').appendChild(div);
			//document.getElementsByTagName('body')[0].appendChild(div);
			
			var insideDiv=document.createElement('div');
			insideDiv.setAttribute('id','insideDiv');
			insideDiv.style.width=div.style.width;
			insideDiv.style.height=div.style.height;
			document.getElementById('container').appendChild(insideDiv);

			
			var insideDiv2=document.createElement('div');
			insideDiv2.setAttribute('id','insideDiv2');
			insideDiv2.style.width=div.style.width;
			insideDiv2.style.height=div.style.height;
			insideDiv2.style.position='absolute';
			insideDiv2.style.left='0px';
			
			
			document.getElementById('insideDiv').appendChild(insideDiv2);
			var insideDiv3=document.createElement('div');
			insideDiv3.setAttribute('id','insideDiv3');
			insideDiv3.style.width=div.style.width;
			insideDiv3.style.height=div.style.height;
			insideDiv3.style.left='0px';
			insideDiv3.style.position='absolute';
			document.getElementById('insideDiv').appendChild(insideDiv3);
			var insideDiv4=document.createElement('div');
			insideDiv4.setAttribute('id','insideDiv4');
			insideDiv4.style.left='0px';
			insideDiv4.className='contactInside';
			document.getElementById('insideDiv3').appendChild(insideDiv4);
			//alert(currentScroll);
			//document.getElementById('insideDiv2').style.top=(currentScroll+50) + 'px';
			//$('#contactusMainContainer').css({marginTop:(currentScroll+50) + 'px'});
			
			
		}
	}else if (document.getElementById('currentPageVar').value == 'contactUsStandard'){
		
		//var div=document.createElement('div');
		//div.setAttribute('id','standardVehiclesContainer');
		//div.style.width='980px';
		//div.style.height='100px';
		//div.style.float='left';
		//div.style.backgroundColor='red';
		//standardVehicles= document.getElementById('standardVehiclesContainer');	
		//document.getElementById('contactInsert').appendChild(div);

		
	}
}
function displayData(){

//$('#contactusMainContainer').css({marginTop:(currentScroll+50) + 'px'});
    //alert(document.getElementById('currentPageVar').value);
	if (document.getElementById('currentPageVar').value == 'contactUs'){
		var theDiv = 'insideDiv3';
		var theFocus = 'txtNameReq';
	}else if (document.getElementById('currentPageVar').value == 'contactUsStandard'){
		var theDiv = 'contactInsert';
		var theFocus = 'txtYearReq';
		document.getElementById(theDiv).innerHTML='';
	}else if(document.getElementById('currentPageVar').value == 'contactUsFleet'){
	    var theDiv = 'contactInsert';
		var theFocus = 'txtYearReq';	
	}else if(document.getElementById('currentPageVar').value == 'contactUsSigns'){
	    var theDiv = 'contactInsert';
		var theFocus = 'ddTypeReq';	
	}else if(document.getElementById('currentPageVar').value == 'contactUsCust'){
	    var theDiv = 'contactInsert';
		var theFocus = 'txtDetailsReq';	
	}else if(document.getElementById('currentPageVar').value == 'contactUsTBS'){
	    var theDiv = 'contactInsert';
		var theFocus = 'txtManuReq';	
	}else{
	    var theFocus = 'none';
	}

	if(theDiv){
        i=0;
        if(i==data.length){i=0};
        document.getElementById(theDiv).innerHTML=data[i];
        //setTimeout('displayData()',20*1000);
        $('#blackOut').fadeIn(200);
        $('#contactusMainContainer').css({marginTop:(currentScroll+100) + 'px'});
        //alert(bodyHeight);
        

		fixMid();
		diagHeight = document.getElementById('mainMid').offsetHeight;
		if((diagHeight+currentScroll+200) > bodyHeight){
		    bodyHeight=(diagHeight+currentScroll+200);
		    if (checkIE() == 1){
				divInnerHTML=fixIE6('img/contactBG.png',blackOutWidth,bodyHeight);

			}else{
				divInnerHTML = "<img src='../img/contactBG.png' width='" + blackOutWidth + "px' height='" + bodyHeight + "px' alt='' />";
			}
			document.getElementById('blackOut').style.height = bodyHeight+'px';
			document.getElementById('blackOut').innerHTML = divInnerHTML;
		}
		if (document.getElementById(theFocus)){
        txtBox=document.getElementById(theFocus);
        txtBox.focus();
        }
        
	}


	
}

function fixPosition(theDiv){

    var minContactWidth=theDiv.offsetWidth;
    var bodyWidth = document.body.offsetWidth;
    if (bodyWidth > minContactWidth){
        offset=((bodyWidth-minContactWidth) / 2);
    }else{
        offset=0;
    }
    theDiv.style.left=offset+'px';
}
function fixBGPosition(theDiv){

    theDiv.style.width=document.body.offsetWidth+'px';
    if (checkIE() == 1){
				divInnerHTML=fixIE6('img/contactBG.png',document.body.offsetWidth,bodyHeight);

			}else{
				divInnerHTML = "<img src='../img/contactBG.png' width='" + document.body.offsetWidth + "px' height='" + bodyHeight + "px' alt='' />";
			}
			theDiv.innerHTML = divInnerHTML;
}

function fixIE(theID, theIMG, theWidth, theHeight, theSizing){
    if (checkIE() == 1){
        if (!theSizing){
            theSizing = 'image';
        }
        theIMG="../img/" + theIMG + ".png";
        innerHTML=fixIE6(theIMG,theWidth,theHeight,theSizing);
        document.getElementById(theID).innerHTML = innerHTML;
    }
}
function contactClick(theID, theAction){
    if (theAction == 1){
        document.getElementById(theID).style.backgroundPosition='-' + (document.getElementById(theID).offsetWidth * 2) + 'px';
        if (theID == 'contactClose' || theID == 'btnCancel'){
            setTimeout('killContactUs()',100);
        }else{
            checkForm(document.contactForm);
        }
    }else if(theAction == 2){
        document.getElementById(theID).style.backgroundPosition='-' + document.getElementById(theID).offsetWidth +'px';
    }else if(theAction == 3){
        document.getElementById(theID).style.backgroundPosition='0px';
    }
}
function contactSample(theID, theAction){
    document.getElementById(theID).style.cursor='pointer';
    
}
function contactSampleClick(theID, theAction){
    if(document.getElementById('Sample').checked == true){
        document.getElementById('Sample').checked = false;
        document.getElementById('Sample').value = 'No';
    }else{
        document.getElementById('Sample').checked = true;
        document.getElementById('Sample').value = 'Yes';
    }
}
function checkForm(theForm){
    //alert(theForm.length);
    var elementName;
    var x=0;
    var formStatus = 'passed';
    for (i=0; i <theForm.length; ++i)
      {
		 
         elementName = theForm.elements[i].name;
		 elementType = theForm.elements[i].type;
		 if(elementType.indexOf('select') != -1){
		     selectedIdx = theForm.elements[i].selectedIndex;
	         elementValue = theForm.elements[i].options[selectedIdx].text;
		 }else{
             elementValue = theForm.elements[i].value;
		 }
         if(theForm.elements[i].name.indexOf("Req") != '-1'){
             if (elementValue == '' || elementValue == '(Select Type)'){

                 if (formStatus != 'failed'){
                     formStatus = 'failed';
                 }
                 theInnerHtml = document.getElementById(elementName + 'Text').innerHTML;
                 if (theInnerHtml.indexOf('*') == '-1'){
                     document.getElementById(elementName + 'Text').innerHTML = '*' + theInnerHtml;
                     document.getElementById(elementName + 'Text').style.color = 'red';
                     document.getElementById(elementName).style.border = '1px solid red';
                 }
             }
         }
      }
    if (formStatus=='passed'){
		
		
		
		$('#btnSubmit').hide();
		
        //theForm.submit();
		var theData = new Array(theForm.length);
		var dataString = '';
		for (i=0; i < theForm.length; ++i){
			elementType = theForm.elements[i].type;

			if(elementType.indexOf('select') != -1){
		         selectedIdx = theForm.elements[i].selectedIndex;
	             elementValue = theForm.elements[i].options[selectedIdx].text;
		     }else{
                 elementValue = theForm.elements[i].value;

		     }
			txtElement = theForm.elements[i].name + 'Text';
//alert(txtElement);
			//alert(txtElement + "\n" + "txtNameReqText");
//alert(theForm.elements[i].tabIndex-1);
			theData[(theForm.elements[i].tabIndex-1)] = theForm.elements[i].name + "=" +  elementValue;
//alert(theForm.elements[i].name + "=" +  elementValue);

		}
        for (i=0; i < theData.length; ++i){
			//alert(theData[0]);
//alert(theData[i]);
			dataString = dataString + theData[i]
			if(i<theData.length){
			    dataString = dataString + "&";
			}
			//alert(theData[i]);
			//alert(dataString);
		}
		dataString=dataString + "&theProduct=" + document.getElementById('currentPageVar').value;
		//alert(dataString);
		//alert(dataString);
		$('#contactForm').html("<div class='contactLoader'></div>");
		$.ajax({
            type: "POST",
            url: "contact.aspx",
            data: dataString,
            success: function() {
            $('#contactForm').html("<div id='message' class='contactItemFull' style='margin-top:20px'></div>");
            $('#message').html("<span class='contactUsTxtThin contactCenter'>Thank You! Your Message Has Been Submitted.</span>");
			$('#contactForm').append("<div id='messageButton' class='contactBtnContainer'><div class='btnCancelCenter'><a id='btnCancel' href='javascript:void(0)' class='btnCancel' onmousedown='contactClick(this.id,1)' onmouseup='contactClick(this.id,2)' onmouseover='contactClick(this.id,2)' onmouseout='contactClick(this.id,3)'></a></div></div>");
		    $('#message').hide().fadeIn(500 );
			$('#messageButton').hide().fadeIn(500 );
            },
			error: function() {
            $('#contactForm').html("<div id='message' class='contactItemFull' style='margin-top:20px'></div>");
            $('#message').html("<span class='contactUsTxtThin contactCenter'>Opps! An error has occurred, please try again later.</span>");
			$('#contactForm').append("<div id='messageButton' class='contactBtnContainer'><div class='btnCancelCenter'><a id='btnCancel' href='javascript:void(0)' class='btnCancel' onmousedown='contactClick(this.id,1)' onmouseup='contactClick(this.id,2)' onmouseover='contactClick(this.id,2)' onmouseout='contactClick(this.id,3)'></a></div></div>");
		    $('#message').hide().fadeIn(500 );
			$('#messageButton').hide().fadeIn(500 );
            }

				
            
			
        });
		
		

		
		
		
		
    }
}
function killContactUs(){
    //var div=document.getElementById('blackOut');
    var div2=document.getElementById('container');
    //$('#blackOut').fadeOut(200);
    //document.getElementsByTagName('body')[0].removeChild(div);
    document.getElementsByTagName('body')[0].removeChild(div2);
	document.getElementById('currentPageVar').value = '';
	$('#blackOut').fadeOut(200);
    setTimeout('killBlackOut()',200);
}
function killBlackOut(){
    var div=document.getElementById('blackOut');
    document.getElementsByTagName('body')[0].removeChild(div);
}
function fixMid(){
    var theIDtoMatch='contactMidContent';
    var theID1='mainMid';
    var theID2='contactMid';
    var theIMGID='contactUsMid';
    var newHeight=document.getElementById(theIDtoMatch).offsetHeight;
    
    var fixID = new Array(theID1, theID2, theIMGID);
    document.getElementById(fixID[0]).style.height=newHeight+'px';
    document.getElementById(fixID[1]).style.height=newHeight+'px';
    if (checkIE()==1){
        var newWidth='1000';
        var theIMG='../img/contactUsMid.png';
        theInnerHTML=fixIE6(theIMG,newWidth,newHeight,'scale');
        document.getElementById(fixID[1]).innerHTML = theInnerHTML;
    }else{
         document.getElementById(fixID[2]).style.height=newHeight+'px';
    }

}

function resizeTest(){

    theID='testDIV';
    currentHeight=document.getElementById(theID).offsetHeight;
    newHeight=(currentHeight + 20);
    document.getElementById(theID).style.height = newHeight + 'px';
    fixMid();
}
function fixContactSize(){
    if (checkIE() != 1){
        newHeight=document.getElementById('contactMid').offsetHeight;
        document.getElementById('contactUsMid').style.height=newHeight+'px';
    }else{
        newWidth='1000';
        theIMG='../img/contactUsMid.png';
        theInnerHTML=fixIE6(theIMG,newWidth,newHeight,'scale');
        document.getElementById('contactMid').innerHTML = theInnerHTML;
    }
}
function helpIEIn(theID){
    if(checkIE()==1){
        document.getElementById(theID).style.display='block';
    }
    
}
function helpIEOut(theID){
    if(checkIE()==1){
        document.getElementById(theID).style.display='none';
    }
}
function checkText(theDiv, theTxtArea){
    // feed in the containing div, and the textarea, only from the contactForm
    var theArea = document.getElementById('contactForm').elements[theTxtArea];
    var theDiv = document.getElementById(theDiv)
    var txtMeasure = document.getElementById('txtMeasure');
    var theWidth = (theArea.offsetWidth - 15);
    var currentDivHeight = theDiv.offsetHeight;
    txtMeasure.style.display = 'block';
    txtMeasure.style.width = theWidth + 'px';
    txtMeasure.innerHTML = 'TEST';
    lHeight = txtMeasure.offsetHeight;
    checkBreaks = theArea.value;
    txtMeasure.innerHTML = checkBreaks.replace(/(\r\n)|(\n)/g,"<br />");
    if(txtMeasure.innerHTML.substring(txtMeasure.innerHTML.length-1) == ">"){
        txtMeasure.innerHTML = txtMeasure.innerHTML + "<br />";
    }
    newLHeight = txtMeasure.offsetHeight;
    if(newLHeight/lHeight > 1){
        if (newLHeight > currentDivHeight || newLHeight < currentDivHeight){
            theDiv.style.height=(newLHeight + 8) + 'px';
            theArea.style.height=(newLHeight + 2) + 'px';
            fixMid();
        }
    }
    txtMeasure.style.display = 'none';
}
function pSelect(theBGID, theTXTID, theAct){
    if ( theAct == 1){
        document.getElementById(theBGID).style.backgroundPosition = '-176px';
        document.getElementById(theTXTID).style.textDecoration = 'underline';
    }else if (theAct == 2){
        document.getElementById(theBGID).style.backgroundPosition = '0px';
        document.getElementById(theTXTID).style.textDecoration = 'none';
    }else if (theAct == 3){
        document.getElementById(theBGID).style.backgroundPosition = '-352px';
        //document.getElementById(theTXTID).style.textDecoration = 'none';
    }
}
function clearFlag(theID){
   if (document.getElementById(theID + 'Text').innerHTML.indexOf('*') != '-1'){
        var theInnerHtml = document.getElementById(theID + 'Text').innerHTML;
        var newInner = theInnerHtml.split('*');
        document.getElementById(theID + 'Text').innerHTML = newInner[1];
        document.getElementById(theID + 'Text').style.color = document.getElementById('txtRefText').style.color;
        document.getElementById(theID).style.border = '1px solid #000000';
   }
}
