
/* Javascript file for Webplace Creations */

//----------------------------------------------------------------------------------------------------------------
// This section controls the fading of div headers on the prices page

//declare global variables
var proc;
var curGreen;
var curBlue;
var curRed;
var startRed;
var startBlue;
var startGreen;
var endRed;
var endGreen;
var endBlue;
var totTime;			//total time in ms to fade form start to end colour
var totSteps;			//total number of steps to fade from start to end colour
var stepInterval;		//time for each step
var stepCounter;

function startFade()
{
    stepCounter		= 0;
    totSteps		= 100; 
    totTime		= 7000;
    stepInterval	= Math.round(totTime/totSteps);
    setStartColor(0,0,128);
    setEndColor(255,255,255);
    
    proc = setInterval("change()",stepInterval);
}

function setStartColor(red,green,blue)
{
    startRed	= red;
    startGreen	= green;
    startBlue	= blue;
}

function setEndColor(red,green,blue)
{
    endRed	= red;
    endGreen	= green;
    endBlue	= blue;
}

function change()
{
    stepCounter = stepCounter+1;
    curRed 		= Math.round((endRed-startRed)*stepCounter/totSteps+startRed);
    curGreen 	= Math.round((endGreen-startGreen)*stepCounter/totSteps+startGreen);
    curBlue		= Math.round((endBlue-startBlue)*stepCounter/totSteps+startBlue);
	
    document.getElementById("fade1").style.color="rgb("+curRed+","+curGreen+","+curBlue+")";
    document.getElementById("fade2").style.color="rgb("+curRed+","+curGreen+","+curBlue+")";
    document.getElementById("fade3").style.color="rgb("+curRed+","+curGreen+","+curBlue+")";
    
    //window.status=curRed+" "+curGreen+" "+curBlue;    
    if(stepCounter+1 > totSteps)
    {
        clearInterval(proc);
    //startFade();
    }   
}
/* This function displays the XHTML Complaince logo */

function showXhtmlCompliance() {
    var xhtml_off   = './Pics/XHTML_tick_off.gif';
    var xhtml_on    = './Pics/XHTML_tick_on.gif';
    var currURL     = document.location.href;
    var w3cURL      = "http://validator.w3.org/check?uri="+currURL;

    document.write('<a href="javascript:void(0);" onclick="valWindow=openWindow('+"\'"+w3cURL+"');"+'">'+
        '<img onmouseover="this.src='+"'"+xhtml_on+"'"+';" onmouseout="this.src='+"'"+xhtml_off+"'"+
        ';" src="'+xhtml_off+'" alt="" title="View W3C Validation of this page" /></a>');
}
/* This function shows an email address as a link*/

function showEmail()
{
    var wbc1 	= "enquiries";
    var wbc2 	= "@";
    var wbc3 	= "webplacecreations.com";
    var wbc4 	= wbc1+wbc2+wbc3;
    
    var wbc5 	= "ma";
    var wbc6 	= "i";
    var wbc7 	= "l";
    var wbc8 	= "t";
    var wbc9 	= "o:";
    var wbc10	= wbc5+wbc6+wbc7+wbc8+wbc9;
    
    document.write('<a title="Click to write and send me an email." href="'+wbc10+wbc4+'">'+wbc4+'</a>');
}

/* This function shows a phone number as text*/

function showPhoneNo()
{
    var wbc1 	= "0417";
    var wbc2 	= "-";
    var wbc5	= "371";
    var wbc3 	= "185";
    var wbc4 	= "560";

    document.write(wbc1+wbc2+wbc3+wbc2+wbc4);
}

/* This function validates the request quote form */

function validateQuoteForm()
{
    var isDataValid = true;
    var errMsg 		= "The fields in red are missing or contain invalid characters.";
 
    //get form data and assign variables
    
    var fName		= Trim(document.forms[0].txtFname.value);
    var lName		= Trim(document.forms[0].txtLname.value);
    var cName		= Trim(document.forms[0].txtCname.value);
    var shipAddress	= Trim(document.forms[0].txtShipAddress.value);
    var shipSuburb	= Trim(document.forms[0].txtShipSuburb.value);
    var shipCity	= Trim(document.forms[0].txtShipCity.value);
    var shipState	= Trim(document.forms[0].txtShipState.value);
    var shipCountry	= Trim(document.forms[0].txtShipCountry.value);
    var shipZip		= Trim(document.forms[0].txtShipZip.value);
    var email		= Trim(document.forms[0].txtEmail.value);
    var areaCode	= Trim(document.forms[0].txtAreaCode.value);
    var phoneNo		= Trim(document.forms[0].txtPhoneNo.value);
    var isPPChecked	= document.getElementById("chkAcceptPP").checked;
   
    //set all the label texts to default color
    
    var cellFname 			= document.getElementById('tdFname');  
    cellFname.style.color 	= 'rgb(119,136,153)';       
    var cellLname 			= document.getElementById('tdLname');  
    cellLname.style.color 	= 'rgb(119,136,153)';            
    var cellCname			= document.getElementById('tdCname');       
    cellCname.style.color 	= 'rgb(119,136,153)';
    var cellAddress			= document.getElementById('tdShipAddress');
    cellAddress.style.color = 'rgb(119,136,153)';
    var cellSuburb			= document.getElementById('tdShipSuburb');
    cellSuburb.style.color 	= 'rgb(119,136,153)';
    var cellCity			= document.getElementById('tdShipCity');
    cellCity.style.color 	= 'rgb(119,136,153)';
    var cellState			= document.getElementById('tdShipState');
    cellState.style.color 	= 'rgb(119,136,153)';
    var cellZip				= document.getElementById('tdShipZip');
    cellZip.style.color 	= 'rgb(119,136,153)';
    var cellCountry			= document.getElementById('tdShipCountry');
    cellCountry.style.color = 'rgb(119,136,153)';
    var cellEmail			= document.getElementById('tdEmail');
    cellEmail.style.color 	= 'rgb(119,136,153)';
    var cellPhone			= document.getElementById('tdShipPhone');
    cellPhone.style.color 	= 'rgb(119,136,153)';
    var cellPP				= document.getElementById("lblAcceptPP");
    cellPP.style.color		= 'rgb(119,136,153)';
    //var cellPayOpt			= document.getElementById('tdPayOpt');
    //cellPayOpt.style.color 	= 'rgb(0,0,128)';
    
    //validate the first name
    
    if(fName == "" || !isLetters(fName)) 
    {
        isDataValid	= false;
        cellFname.style.color = 'rgb(255,0,0)';
    }
    
    //validate the surname
    
    if(lName == "" || !isSurname(lName)) 
    {
        isDataValid	= false;
        cellLname.style.color = 'rgb(255,0,0)';
    }
    
    //validate the company name
    
    if(!isStreetAddress(cName))
    {
        isDataValid	= false;
        cellCname.style.color = 'rgb(255,0,0)';
    }
    
    //validate the street address
    
    if(shipAddress != "" && !isStreetAddress(shipAddress))
    {
        isDataValid	= false;
        cellAddress.style.color = 'rgb(255,0,0)';
    }
    
    //validate the suburb
    
    if(shipSuburb != "" && !isLettersAndSpaces(shipSuburb))
    {
        isDataValid	= false;
        cellSuburb.style.color = 'rgb(255,0,0)';
    }
    
    //validate the city
    
    if(shipCity != "" && !isLettersAndSpaces(shipCity))
    {
        isDataValid	= false;
        cellCity.style.color = 'rgb(255,0,0)';
    }
    
    //validate the state
    
    if(shipState != "" && !isLettersAndSpaces(shipState))
    {
        isDataValid	= false;
        cellState.style.color = 'rgb(255,0,0)';
    }
    
    //validate the postcode
    
    if(shipZip != "" && !isPostcode(shipZip))
    {
        isDataValid	= false;
        cellZip.style.color = 'rgb(255,0,0)';
    } 
     
    //validate the country
    
    if(shipCountry != "" && !isLettersAndSpaces(shipCountry))
    {
        isDataValid	= false;
        cellCountry.style.color = 'rgb(255,0,0)';
    }
    
    //validate the phone 
    
    if((areaCode != "" && !isPostcode(areaCode)) || (phoneNo != "" && !isPostcode(phoneNo)))
    {
        isDataValid	= false;
        cellPhone.style.color = 'rgb(255,0,0)';
    }
    
    if((areaCode != "" && phoneNo == "") || (phoneNo != "" && areaCode == ""))
    {
        isDataValid	= false;
        cellPhone.style.color = 'rgb(255,0,0)';
    }
    
    //validate the email address
    
    if(email == "" || !validateEmailAddress(email))
    {
        isDataValid	= false;
        cellEmail.style.color = 'rgb(255,0,0)';
    }
    
    //check if the Privacy Policy has been accepted
       
    if(!isPPChecked)
    {
        isDataValid	= false;
        cellPP.style.color = 'rgb(255,0,0)';
    }
    
    //check if all the submitted data is valid
    
    if(!isDataValid)
    {
        window.location.href="#logo_container";
        alert(errMsg);
        return false
    }
    else	//form data is valid
    {
        //write trimmed data back to input boxes
        
        document.forms[0].txtFname.value		= fName;
        document.forms[0].txtLname.value		= lName;
        document.forms[0].txtCname.value		= cName;
        document.forms[0].txtShipAddress.value	= shipAddress;
        document.forms[0].txtShipSuburb.value	= shipSuburb;
        document.forms[0].txtShipCity.value		= shipCity;
        document.forms[0].txtShipState.value	= shipState;
        document.forms[0].txtShipCountry.value	= shipCountry;
        document.forms[0].txtShipZip.value		= shipZip;
        document.forms[0].txtEmail.value		= email;
        document.forms[0].txtAreaCode.value		= areaCode;
        document.forms[0].txtPhoneNo.value		= phoneNo;
     
        //submit the form using AJAX
        
        sendCaptchaResponse();	//function tests captcha response. If it is valid then the form is submitted
    }
}

//----------------------------------------------------------------------------

function sendQuoteRequestToMe()
{ 
    var ajaxObj = startAJAX();							//create an AJAX object
    if(ajaxObj == null) return;							//browser doesn't support AJAX 
    ajaxObj.onreadystatechange=requestHandler;  	    //set the function to execute when the request's state has changed
        
    var fName		= Trim(document.forms[0].txtFname.value);
    var lName		= Trim(document.forms[0].txtLname.value);
    var cName		= Trim(document.forms[0].txtCname.value);    
    var shipAddress	= Trim(document.forms[0].txtShipAddress.value);
    var shipSuburb	= Trim(document.forms[0].txtShipSuburb.value);
    var shipCity	= Trim(document.forms[0].txtShipCity.value);
    var shipState	= Trim(document.forms[0].txtShipState.value);
    var shipCountry	= Trim(document.forms[0].txtShipCountry.value);
    var shipZip		= Trim(document.forms[0].txtShipZip.value);
    var email		= Trim(document.forms[0].txtEmail.value);
    var areaCode	= Trim(document.forms[0].txtAreaCode.value);
    var phoneNo		= Trim(document.forms[0].txtPhoneNo.value);
    var projDesc	= document.getElementById("txtProjDescription").value;   
    var siteType1	= document.getElementById("selSiteType1").value;
    var siteType2	= document.getElementById("selSiteType2").value;   
    var audience	= document.getElementById("txtAudience").value;
    var objectives	= document.getElementById("txtObjectives").value;
    var existCont	= document.getElementById("txtExistingContent").value;
    var suppCont	= document.getElementById("txtSupplyContent").value;
    var numPages	= document.getElementById("txtNumPages").value;
    var createCont	= document.getElementById("txtCreateContent").value;
    var maintenance	= document.getElementById("txtMaintenance").value;
    var hosting		= document.getElementById("txtHosting").value;
    
    var url 		= "sendQuoteRequest.php";
    var params		= "";

    params 	= 	"txtFname="+fName+
    "&txtLname="+lName+
    "&txtCname="+cName+
    "&txtShipAddress="+shipAddress+
    "&txtShipSuburb="+shipSuburb+
    "&txtShipCity="+shipCity+
    "&txtShipCountry="+shipCountry+
    "&txtShipState="+shipState+
    "&txtShipZip="+shipZip+
    "&txtEmail="+email+
    "&txtAreaCode="+areaCode+
    "&txtPhoneNo="+phoneNo+
    "&txtProjDescription="+projDesc+
    "&selSiteType1="+siteType1+
    "&selSiteType2="+siteType2+
    "&txtAudience="+audience+
    "&txtObjectives="+objectives+
    "&txtExistingContent="+existCont+
    "&txtSupplyContent="+suppCont+
    "&txtNumPages="+numPages+
    "&txtCreateContent="+createCont+
    "&txtMaintenance="+maintenance+
    "&txtHosting="+hosting;
  
    ajaxObj.open("POST",url,true);													//open a connection to the PHP script on the server
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    //ajaxObj.setRequestHeader("Content-length", params.length);
    //ajaxObj.setRequestHeader("Connection", "close");
    splashWin=window.open("pleaseWaitSplash.htm","pleaseWaitSplash","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=300,height=100,left=200,top=50,screenX=200,screenY=50");
    ajaxObj.send(params);																//send the request to the server
               
    function requestHandler()
    {
        if(ajaxObj.readyState==4 && (ajaxObj.status == 200 || ajaxObj.status == 304))
        {
            if(splashWin) splashWin.close();
            var respString = ajaxObj.responseText;
            alert(respString);
        }
    }
}
//-------------------------------------------------------------------------------------------

function openWindow(fileName) {
    newWin=window.open(fileName,'tempWin','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
    newWin.focus();
}
//---------------------------------------------------------------------------------------------------------

function displayFlashVideo() {
    document.write('<div id="flash_container"> '+
        '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
        'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" '+
        'height="147" id="samplePages" width="200"> '+
        '<param name="movie" value="./flash/samplePages.swf"/> '+
        '<param name="quality" value="high"/> '+
        '<param name="loop" value="true"/> '+
        '<param name="wmode" value="transparent"/> '+
        '<embed autostart="true" height="147" loop="true" '+
        'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" '+
        'quality="high" src="./flash/samplePages.swf" '+
        'type="application/x-shockwave-flash" width="200"/> '+
        ' </object> '+
        '</div>');
}

//------------------------------------------------------------------------------------------------------

function openPrivacyPolicy(){
    newWin=window.open("privacyPolicy.php","privacyPolicy","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=850,height=1100,left=20,top=5,screenX=20,screenY=5");
    newWin.focus();
}
//------------------------------------------------------------------------------------------------------

function createAddFavouriteLink(elem)
{
    var linkElem = document.getElementById(elem);

    //create the appropriate link for the browser
    if (window.external && browserName != 'Chrome' && browserName != 'Safari') //Chrome has window.external but not window.external.AddFavorite
        linkElem.innerHTML = '<a id="lnkFav" title="Click to add this page to your browser favourites" href = "javascript:addFavouriteToBrowser()");">Add to Favourites</a>';
    else if (window.sidebar)
        linkElem.innerHTML = '<a id="lnkFav" title="Click to add this page to your browser bookmarks" href = "javascript:addFavouriteToBrowser()");">Bookmark Page</a>';
    else if (window.opera && window.print)
        linkElem.innerHTML = '<a id="lnkFav" title="Click to add this page to your browser bookmarks" href = "javascript:addFavouriteToBrowser()");">Add Bookmark</a>';
    else    //browser does not support Add to favourite Javascript
        document.getElementById("favLink").style.display = "none";
    
//set the elements.styles
//var aLink = document.getElementById("lnkFav");
//aLink.style.textDecoration = "none";

}
//-----------------------------------------------------------

function addFavouriteToBrowser()
{
    title 	= document.title;
    url 	= window.location.href;

    if (window.sidebar)
    {//  Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    }
    else if( window.external )
    {// IE Favorite and FF3
        window.external.AddFavorite( url, title);
    }
    else if(window.opera && window.print)
    { // Opera Hotlist
        alert("Press Ctl + D to add this page to your browser's bookmarks");
    }
    
}
//-----------------------------------------------------------

function loadCommonImgSrcs() {
    ImageHandler.loadImgSrc('logo','./Pics/logo.jpg');
    ImageHandler.loadImgSrc('as_logo','./Pics/web_hosting_sq.jpg');
}
//-----------------------------------------------------------

function loadCommonImages() {
    ImageHandler.loadScaledImageToImgId("logo", "logo", 900, 125);
    ImageHandler.loadScaledImageToImgId("as_logo", "as_logo", 150, 150);
}
//-----------------------------------------------------------

function loadImagesIndex()  {
    loadCommonImages();
    ImageHandler.loadScaledImageToImgId("my_photo", "my_photo", 100, 150);
}
//-----------------------------------------------------------

function loadImagesSamples()  {
    loadCommonImages();
    ImageHandler.loadScaledImageToImgId('mvc_sample', 'mvc_sample', 200, 200);
    ImageHandler.loadScaledImageToImgId('mhc_sample', 'mhc_sample', 200, 200);
    ImageHandler.loadScaledImageToImgId('dunston_sample', 'dunston_sample', 200, 200);
    ImageHandler.loadScaledImageToImgId('pol_sample', 'pol_sample', 200, 200);
    ImageHandler.loadScaledImageToImgId('brb_sample', 'brb_sample', 200, 200);
}
//-----------------------------------------------------------

function loadImagesProcess()  {
    loadCommonImages();
    ImageHandler.loadScaledImageToImgId('step_1', 'step_1', 80, 20);
    ImageHandler.loadScaledImageToImgId('step_2', 'step_2', 80, 20);
    ImageHandler.loadScaledImageToImgId('step_3', 'step_3', 80, 20);
    ImageHandler.loadScaledImageToImgId('step_4', 'step_4', 80, 20);
    ImageHandler.loadScaledImageToImgId('step_5', 'step_5', 80, 20);
    ImageHandler.loadScaledImageToImgId('step_6', 'step_6', 80, 20);
}
//-----------------------------------------------------------

function loadImagesPrices()  {
    loadCommonImages();
}
//-----------------------------------------------------------

function loadImagesHosting()  {
    loadCommonImages();
    ImageHandler.loadScaledImageToImgId('awardspace_logo_container', 'as_logo', 200, 200);
}
//-----------------------------------------------------------

function loadImagesDigitalPhotos()  {
    loadCommonImages();
}
//-----------------------------------------------------------

function loadImagesContact()  {
    loadCommonImages();
    ImageHandler.loadScaledImageToImgId('contact_photo', 'my_photo', 100, 150);
}
//-------------------------------------------------------------------------------------------

function unhideBody() {
    var bodyElems = document.getElementsByTagName("body");
    bodyElems[0].style.visibility = "visible";
    bodyElems[0].style.display = "block";
}


