// Author Tristan Wogan (Majorbet / Stilgar)
// Contact tristanwogan@gmail.com
// Copyright JAN 2008

// INDEX

// show(object) 							Shows hidden layer where object is layer ID
// hide(object) 							Hides visible layer where object is layer ID
//function focus_it(focus_area)				Focus to given element where 'focus_area' id of element
//function validate_form ()					Validate form before submit
//function echeck(str)						Check construction of email (called from validate_form ())
// function remove_spaces(string)			Removes/ replaces spaces from string sent via (string)




<!--

// Shows Layers
function show(object) 
{ 
	if (document.getElementById) 
{ 	// DOM3 = IE5, NS6 
	document.getElementById(object).style.visibility = 'visible'; 
} 	
	else 
{ 
	if (document.layers) 
{	// Netscape 4 
	document.object.visibility = 'visible'; 
} 
	else 
{	// IE 4 
	document.all.object.style.visibility = 'visible'; 
} 
} 
} 
// Hides layers
function hide(object) 
{ 
	if (document.getElementById) 
{ 	// DOM3 = IE5, NS6 
	document.getElementById(object).style.visibility = 'hidden'; 
} 
	else 
{ 
	if (document.layers) 
{ 	// Netscape 4 
	document.object.visibility = 'hidden'; 
} 
	else 
{ 	// IE 4 
	document.all.object.style.visibility = 'hidden'; 
} 
} 
}

//Set Focus form 1 first_name textbox
function focus_it(){
		document.form1.first_name.focus();
}
// Validate form before submit
function validate_form (){
{
    var valid = true;
	
    if ( document.form1.first_name.value == "" )					//first name
    {
        alert ( "Please fill in your 'First Name'." );
		
        valid = false;
    }

	
	    if ( document.form1.second_name.value == "" ) 				// Second name
    {
        alert ( "Please fill in your 'Surname Name'." );
        valid = false;
    }
	
	var emailID=document.form1.email
	
	if ((emailID.value==null)||(emailID.value=="")){				// Check email
		alert("Please Enter your Email Address")
		emailID.focus()
		valid = false;
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid = false;
	}

	    if ( document.form1.phone_number.value == "" ) 				// Phone Number
    {
        alert ( "Please fill in your 'Phone Number'." );
        valid = false;
    }	
	
    var numericExpression = /^[0-9]+$/;								// Check Phone Number
	var phoneNumber=remove_spaces(document.form1.phone_number.value)
	if(phoneNumber.match(numericExpression)){
	
	//	valid = false;
	}              
	else{
        alert ( "Phone Number can only contain Numbers." );
        valid = false;
    }

	    if ( document.form1.address_line_1.value == "" ) 				// Address Line 1
    {
        alert ( "Please fill in 'Address Line 1'." );
        valid = false;
    }	
	
	    if ( document.form1.town.value == "" ) 							// Town 
    {
        alert ( "Please fill in your 'Town'." );
        valid = false;
    }	
		
		if ( document.form1.county.value == "" ) 						// county
    {
        alert ( "Please fill in your 'County'." );
        valid = false;
    }

	    if ( document.form1.post_code.value == "" ) 					// Post Code
    {
        alert ( "Please fill in your 'Post Code'." );
        valid = false;
    }		
	
// AT THIS POINT SECTION 'CONTACT DETAILS' FULLY VALIDATED	

		    if ( document.form1.x_dim.value == "" ) 				// Check X_Dim
    {
        alert ( "Please fill the first Dimension Box" );
        valid = false;
    }	
	
	var numericExpression = /^[0-9.]+$/;
	var x_dim=document.form1.x_dim.value
	if(x_dim.match(numericExpression)){
	
	//	valid = false;
	}              
	else{
        alert ( "Dimension can only contain Numbers and Decimal Points." );
        valid = false;
    }

	if ( document.form1.y_dim.value == "" ) 							// Check Y_Dim
    {
        alert ( "Please fill the second Dimension Box" );
        valid = false;
    }	
	
	var y_dim=document.form1.y_dim.value								// Check Y_Dim
	if(y_dim.match(numericExpression)){
	//	valid = false;
	}              
	else{
        alert ( "Dimension can only contain Numbers and Decimal Points." );
        valid = false;
    }

	if ( document.form1.character_number.value=="" ){				// Upload Pressed Character check
	
		if ( document.form1.upload_pressed.value == "no" ) { 							
			alert ( "Please fill in 'Number of Characters' or 'Upload Design'." );
			valid = false;
		}
	}
	
	if ( document.form1.thickness.value == "" ) 							// Panel thickness
    {
        alert ( "Please fill in panel 'Thickness' required." );
        valid = false;
    }	    
		
	var numericExpression = /^[0-9.]+$/;									// Panel thickness
	var thickness=remove_spaces(document.form1.thickness.value)
	if(thickness.match(numericExpression)){
	
	//	valid = false;
	}              
	else{
        alert ( "Thickness can only contain Numbers and Decimal Points." );
        valid = false;
    }	

	if ( document.form1.panel_colour.value == "" ) 							// Panel Colour 
    {
        alert ( "Please fill in 'Panel Colour' required." );
        valid = false;
    }		

	if ( document.form1.design_colour.value == "" ) 							// design Colour 
    {
        alert ( "Please fill in 'Design Colour' required." );
        valid = false;
    }			
	
    return valid;
	
//valudation web page http://www.elated.com/articles/form-validation-with-javascript/	
}

}
// Check construction of email
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}


 // Remove spaces from string
function remove_spaces(string){
	var str = string;
		str = str.replace(/\s+/g, "");
//		alert (str);							//D-bug Line
	
	return str
}
//Form lameekam deal with expanding paint
function expand_reveal(){

	var drop_value=document.form1.material.value;
	
	if (drop_value.search(/^[1-9]$/)){
		document.getElementById('powder_colour').style.position = 'relative';
		document.getElementById('panel_details').style.height = '210px'; 
		document.getElementById('powder_colour').style.visibility = 'visible'; 
	
		document.getElementById('powder_colour_lablel').style.position = 'relative';
		document.getElementById('powder_colour_lablel').style.visibility = 'visible';
		
		document.form1.panel_colour.value = ""
		
		}
	else{
		document.getElementById('powder_colour').style.position = 'absolute';
		document.getElementById('panel_details').style.height = '175px'; 
		document.getElementById('powder_colour').style.visibility = 'hidden'; 
	
		document.getElementById('powder_colour_lablel').style.position = 'absolute';
		document.getElementById('powder_colour_lablel').style.visibility = 'hidden';
		
		document.form1.panel_colour.value = "none"
	}
	
}

//Change upload status
function upload_status(){
		
		document.form1.upload_pressed.value="yes"
		document.form1.character_number.disabled="true";
		document.form1.character_number.style.background='#eeeeee';
		
}






 
//-->
