﻿/*

JQuery code to make front page content switcher work

*/   

    //Load the specified flash file into the "SplashImage" div.
	function loadflash(url)
	{    
		swfobject.embedSWF(url, "SplashImage", "729", "588", "9.0.0"); 
	}	
		
	$(document).ready(function()
	{			
        $('#select1').click(function() {
        
                loadflash('swf/traffic_lights.swf');        
                                       
                $('#Testimonials').hide();
        
                $(this).removeClass().addClass("item1on");
                $('#select2').removeClass().addClass("item2off");
                $('#select3').removeClass().addClass("item3off");

                $('#toppanel').removeClass().addClass("topon");

                $('#content0').removeClass().addClass("hidden");
                $('#content1').removeClass().addClass("displaytext");
                $('#content2').removeClass().addClass("hidden");
                $('#content3').removeClass().addClass("hidden");

        });

        $('#select2').click(function() {
        
                loadflash('swf/cogs.swf');
                
                $('#Testimonials').hide();
        
                $(this).removeClass().addClass("item2on");
                $('#select1').removeClass().addClass("item1off");
                $('#select3').removeClass().addClass("item3off");

                $('#toppanel').removeClass().addClass("topon");

                $('#content0').removeClass().addClass("hidden");
                $('#content1').removeClass().addClass("hidden");
                $('#content2').removeClass().addClass("displaytext");
                $('#content3').removeClass().addClass("hidden");
        });

        $('#select3').click(function() {
        
                loadflash('swf/cube.swf');
                
                $('#Testimonials').hide();
        
                $(this).removeClass().addClass("item3on");
                $('#select2').removeClass().addClass("item2off");
                $('#select1').removeClass().addClass("item1off");
                
                $('#toppanel').removeClass().addClass("topon");

                $('#content0').removeClass().addClass("hidden");
                $('#content1').removeClass().addClass("hidden");
                $('#content2').removeClass().addClass("hidden");
                $('#content3').removeClass().addClass("displaytext");

        });

        $('.Revert').click(function() {
        
                loadflash('swf/home_page.swf');
                
                $('#Testimonials').show();
        
                $('#select1').removeClass().addClass("item1");
                $('#select2').removeClass().addClass("item2");
                $('#select3').removeClass().addClass("item3");

                $('#toppanel').removeClass().addClass("topoff");
                
                $('#content0').removeClass().addClass("displaytext");
                $('#content1').removeClass().addClass("hidden");
                $('#content2').removeClass().addClass("hidden");
                $('#content3').removeClass().addClass("hidden");

        });
    });

/*******

	***	Anchor Slider by Cedric Dugas   ***
	*** Http://www.position-absolute.com ***
	
	You can use and modify this script for any project you want, but please leave this comment as credit.
	
	Never have an anchor jumping your content, slide it.
	
	Just add the class anchor at your <a> tag and it will slide, user with no javascript will 
	still go to destination with the normal html anchor

	Don't forget to put an id to your anchor !
	
*****/
		
$(document).ready(function() {
	anchor.init()
});

anchor = {
	init : function()  {
		$("a.btn-slide").click(function () {	
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		  	return false;
		})
	}
}

$(document).ready(function() {
	anchoron.init()
});

anchoron = {
	init : function()  {
		$("a.active").click(function () {	
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		  	return false;
		})
	}
}


function validateemail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    //var address = document.forms[form_id].elements[email].value;
    if(reg.test(email) == false) {
        //alert('Invalid Email Address');
        return false;
    }
    else
    {
        return true;
    }
}


/*************************************************************************************

function RenderForm()

Uses ExtJS to write enquiry form to the page.

Accepts the form type as a parameter, the parameter will change the form title 
and then passes the paramete to mailer.aspx which also uses it in the email sending.

usage:  <script language="javascript" type="text/javascript">
            RenderForm("enquiry");
        </script>

*************************************************************************************/
function RenderForm(type, extrainfo, width)
{

    var strTitle = "";
    var strType = "";
    
    strType = type;
    
    var strTextArea = 'Your message here...';

    switch(type)
    {
        case "partner":
            strTitle = "Become a partner";
            extrainfo = 'Your message here...';
            break;
        case "trial":
            strTitle = "Request a trial of HSSmart";
            extrainfo = 'Your message here...';
            break;
        case "event":
            strTitle = "Booking details";
            break;            
        default:
            strType = "enquiry";
            strTitle = "Submit your enquiry";
            extrainfo = 'Your message here...';
    }

Ext.onReady(function(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';
        
    var fp = new Ext.Panel({
        labelAlign: 'side',
        //labelSeparator:'&nbsp',
        labelWidth: 180,
        frame:true,
        title: strTitle,
        bodyStyle:'padding:6;' ,
        width: width,		
        items: [
   		{   layout : 'form',   		    
		  items: [
		
		
		    {
            layout:'column',
            items:[                         
            {
                columnWidth:.5,
                layout: 'form',
                labelWidth: 80,
                items: [                
                {
                    xtype:'textfield'
                    ,id: 'txtName'
					,autoCreate : {tag: "input", type: "text", size: "50", maxlength:50, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					//,labelStyle:'display:none;'
                    ,fieldLabel: 'Name'
					//,emptyText:'First Name'
					,name: 'fullName'
					,allowBlank:false
					,anchor:'93%'
					                }, 
                {
                    xtype:'textfield'
                    ,id: 'txtCompany'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					//,labelStyle:'display:none'
					,fieldLabel: 'Company'					
					//,emptyText:'Company'
					,name: 'company'
					,allowBlank:true
					,anchor:'93%'
					                },
                {
                    xtype:'textfield'
                    ,id: 'txtPosition'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
						//				,labelStyle:'display:none'
                		,fieldLabel: 'Position'						
						//,emptyText:'Position'
								    ,name: 'position'
								    ,anchor:'93%'
								    		
                }
                  //enabled for testing
					                                
                ]
            },{
                columnWidth:.5,
                layout: 'form',
                labelWidth: 120,
                items: [
				{
                    xtype:'textfield'
                    ,id: 'txtPhone'
					,autoCreate : {tag: "input", type: "text", size: "20", maxlength:20, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
				    ,fieldLabel: 'Phone'
				    ,name: 'phone'
				    ,allowBlank:true
				    ,anchor:'93%'
				        								
                },
				{
                    xtype:'textfield'
                    ,id: 'txtEmail1'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					,fieldLabel: 'Email'
					,name: 'email'
					,vtype:'email'
					,allowBlank:false
					,anchor:'93%'
					                }
				,{
                    xtype:'textfield'
                    ,id: 'txtEmail2'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
				    ,fieldLabel: 'Email Confirmation'
                    ,labelWidth: 400
				    ,name: 'email2'
				    ,vtype:'email'
					,validator: function() {
					  //var email = fp.getForm().findField('email').getValue();
			 		  //var email2 = fp.getForm().findField('email2').getValue();
			 		  var email = Ext.get("txtEmail1").dom.value;
			 		  var email2 = Ext.get("txtEmail2").dom.value;
					  if(email!=email2){
						  return "Emails need to be the same.";
					  }	else return true;
					}
				    ,allowBlank:false
				    ,anchor:'93%'
				                    }
				
				   //enabled for testing
					     
				
				]
            }]
        	},
			{
            //layout:'column',
            //items:[
            //{
                layout: 'form',
                labelWidth: 80,
                items: [                
                {
                    xtype:'textarea'
                    ,id: 'txtMessage'
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					//,labelStyle:'display:none;'
                    ,fieldLabel: 'Message'
					//,emptyText: 'Your message here...'
					,emptyText: strTextArea
					,name: 'message'
					,allowBlank:false
					,anchor:'96.5%'
					                }                     
                ]
            //}]
			
        	}
		  
		  ]}
		  
		]		
		,
		buttons: [
  		{
		  text: 'Submit Details',
		  handler: function(){
          
            if(validateemail(Ext.get("txtEmail1").dom.value) && validateemail(Ext.get("txtEmail2").dom.value) && Ext.get("txtName").dom.value != "" && Ext.get("txtEmail1").dom.value != "" && Ext.get("txtEmail2").dom.value != "" && Ext.get("txtMessage").dom.value !== "")
            {
                window.location.href = 'Mailer.aspx?type=' + strType + '&extra=' + extrainfo + '&txtName=' + Ext.get("txtName").dom.value + "&txtCompany=" + Ext.get("txtCompany").dom.value + "&txtPosition=" + Ext.get("txtPosition").dom.value + "&txtPhone=" + Ext.get("txtPhone").dom.value + "&txtEmail1=" + Ext.get("txtEmail1").dom.value + "&txtMessage=" + Ext.get("txtMessage").dom.value;
            }
            else
            {
                alert("Please fill in all the required fields correctly");                
            }
  			  	//enabled for testing
  			  //window.location.href = 'confirmation.php?' + fp.getForm().getValues(true )+ '&ezineId=' + ezineId;
          }
        }

	  	//enabled for testing
				]
    });
        
    fp.render(Ext.get("formdetails"));    
    
    if(type == 'event')
    {
        Ext.get("txtMessage").dom.value = extrainfo;
    }
    
    //Don't focus the form on the channel partner page as it shifts the page down
    if(type != 'partner')
    {
        //Ext.get("txtName").dom.focus();
    }
    	
});
}

function RenderTestForm(type, extrainfo, width)
{

    var strTitle = "";
    var strType = "";
    
    strType = type;

    switch(type)
    {
        case "partner":
            strTitle = "Become a partner";
            break;
        case "trial":
            strTitle = "Request a trial of HSSmart";
            break;
        case "event":
            strTitle = "Book an event";
            break;            
        default:
            strType = "enquiry";
            strTitle = "Submit your enquiry";
    }


Ext.onReady(function(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';


    var fp = new Ext.Panel({
        labelAlign: 'side',
        labelSeparator:'&nbsp',
        frame:true,
        title: strTitle,
        bodyStyle:'padding:0;' ,
        width: width,		
        items: [
   		{ layout : 'form',
		  items: [
		
		
		    {
            layout:'column',
            items:[                         
            {
                columnWidth:.5,
                layout: 'form',
                items: [                
                {
                    xtype:'textfield'
                    ,id: 'txtName'
					,autoCreate : {tag: "input", type: "text", size: "50", maxlength:50, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					//,labelStyle:'display:none;'
                    ,fieldLabel: 'Name'
					//,emptyText:'First Name'
					,name: 'fullName'
					,allowBlank:false
					,anchor:'80%'
					 ,value: 'a'                 }, 
                {
                    xtype:'textfield'
                    ,id: 'txtCompany'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					//,labelStyle:'display:none'
					,fieldLabel: 'Company'					
					//,emptyText:'Company'
					,name: 'company'
					,allowBlank:true
					,anchor:'80%'
					 ,value: 'c'                 },
                {
                    xtype:'textfield'
                    ,id: 'txtPosition'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
						//				,labelStyle:'display:none'
                		,fieldLabel: 'Position'						
						//,emptyText:'Position'
								    ,name: 'position'
								    ,allowBlank:true
								    ,anchor:'80%'
								     ,value: 'b' 		
                }
                  //enabled for testing
					, {
	                    xtype:'textfield'
	                    ,id: 'txtEmailto'
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
						//,labelStyle:'display:none'
						,fieldLabel: 'Email To (Test)'						
						//,emptyText:'Email To (Test)'
						,name: 'emailTo'
						,allowBlank:false
						,anchor:'80%'
						,value: 'dlam@arkworkplacerisk.co.uk'
					}                                 
                ]
            },{
                columnWidth:.5,
                layout: 'form',
                labelWidth: 120,
                items: [
				{
                    xtype:'textfield'
                    ,id: 'txtPhone'
					,autoCreate : {tag: "input", type: "text", size: "20", maxlength:20, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
				    ,fieldLabel: 'Phone'
				    ,name: 'phone'
				    ,allowBlank:true
				    ,anchor:'93%'
				     ,value: 'd'     								
                },
				{
                    xtype:'textfield'
                    ,id: 'txtEmail1'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					,fieldLabel: 'Email'
					,name: 'email'
					,vtype:'email'
					,allowBlank:false
					,anchor:'93%'
					 ,value: 'abc@abc.com'                 }
				,{
                    xtype:'textfield'
                    ,id: 'txtEmail2'
					,autoCreate : {tag: "input", type: "text", size: "100", maxlength:100, autocomplete: "off"} 
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
				    ,fieldLabel: 'Email Confirmation'
				    ,name: 'email2'
				    ,vtype:'email'
					,validator: function() {
			 		  var email = Ext.get("txtEmail1").dom.value;
			 		  var email2 = Ext.get("txtEmail2").dom.value;
					  if(email!=email2){
						  return "Emails need to be the same.";
					  }	else return true;
					}
				    ,allowBlank:false
				    ,anchor:'93%'
				     ,value: 'abc@abc.com'                 }
				
				   //enabled for testing
				    /*	, {
	                    xtype:'textfield'
						,readOnly: true
					    ,labelStyle: 'font-size:11px;'
					    ,style: 'font-size:11px;'
						//,labelStyle:'display:none'
						,fieldLabel: 'EzineId'						
						//,emptyText:'Email To (Test)'
						,name: 'ezineId'
						,allowBlank:false
						,anchor:'80%'
						,value: ezineId
					}      
					*/
				
				]
            }]
        	},
			{
            //layout:'column',
            //items:[                         
            //{                
                layout: 'form',
                items: [                
                {
                    xtype:'textarea'
                    ,id: 'txtMessage'
					//,labelStyle: 'font-size:11px;'
					//,style: 'font-size:11px;'
					//,labelStyle:'display:none;'
                    ,fieldLabel: 'Message'
					,emptyText: 'Your message here...'
					,name: 'message'
					,allowBlank:false
					,anchor:'96.5%'
					,value: 'Test message'                 }                     
                ]
            //}]
			
        	}
		  
		  ]}
		  
		]		
		,
		buttons: [
  		{
		  text: 'Submit Details',
		  handler: function(){		  	  	  
            if(validateemail(Ext.get("txtEmailto").dom.value) && validateemail(Ext.get("txtEmail1").dom.value) && validateemail(Ext.get("txtEmail2").dom.value) && Ext.get("txtName").dom.value != "" && Ext.get("txtEmail1").dom.value != "" && Ext.get("txtEmail2").dom.value != "" && Ext.get("txtMessage").dom.value !== "")
            {
                window.location.href = 'Mailer.aspx?test=1&TestEmail=' + Ext.get("txtEmailto").dom.value + '&type=' + strType + '&extra=' + extrainfo + '&txtName=' + Ext.get("txtName").dom.value + "&txtCompany=" + Ext.get("txtCompany").dom.value + "&txtPosition=" + Ext.get("txtPosition").dom.value + "&txtPhone=" + Ext.get("txtPhone").dom.value + "&txtEmail1=" + Ext.get("txtEmail1").dom.value + "&txtMessage=" + Ext.get("txtMessage").dom.value;
            }
            else
            {
                alert("Please fill in all the required fields correctly");                
            }
          }
        }

	  	//enabled for testing
		/*
			, {
				text: 'Reset (Test)',
				handler: function(){				
					fp.getForm().findField('fullName').setValue('');
					fp.getForm().findField('position').setValue('');
					fp.getForm().findField('company').setValue('');
					fp.getForm().findField('phone').setValue('');
					fp.getForm().findField('email').setValue('');
					fp.getForm().findField('email2').setValue('');
					fp.getForm().findField('message').setValue('');
				}
	
			}, {
				text: 'Default (Test)',
				handler: function(){
					fp.getForm().findField('emailTo').setValue('gerard.sans@gmail.com');				
					fp.getForm().findField('fullName').setValue('a');
					fp.getForm().findField('position').setValue('b');
					fp.getForm().findField('company').setValue('c');
					fp.getForm().findField('phone').setValue('d');
					fp.getForm().findField('email').setValue('abc@abc.com');
					fp.getForm().findField('email2').setValue('abc@abc.com');
					fp.getForm().findField('message').setValue('test text');
				}
				
			} */		]
    });
		
    fp.render(Ext.get("formdetails"));    

	
});


}


function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function checkVersion()
{
  var ver = 10;
  var ver = getInternetExplorerVersion();
  
  return ver;

}