// JavaScript Document

	var cWindow;
    
	function linkNAPP()
	{
		      cWindow = window.open("http://www.photoshopuser.com/","compWindow");
              cWindow.focus();
	}	
	
	function linkPPA()
	{
		      cWindow = window.open("http://www.ppa.com/splash.cfm","compWindow");
              cWindow.focus();
	}
	
	function assignHidden()
	{
		window.document.contact_form.name_hidden.value = window.document.contact_form.name.value;
		window.document.contact_form.email_hidden.value = window.document.contact_form.email.value;
		window.document.contact_form.phone_hidden.value = window.document.contact_form.phone.value;
		window.document.contact_form.location_hidden.value = window.document.contact_form.location.value;
		window.document.contact_form.company_hidden.value = window.document.contact_form.company.value;
		window.document.contact_form.howsoon_hidden.value = window.document.contact_form.howsoon.value;
		window.document.contact_form.ideas_hidden.value = window.document.contact_form.ideas.value;
	}
	
	function validateForm()
	{
		var error_string = "";
		if (window.document.contact_form.name.value == "")
		{
			error_string += "Please enter your name before sending.\n";
		}
		if (window.document.contact_form.email.value == "")
		{
			error_string += "Please enter your email address before sending.\n";
		}		
		if (error_string == "")
		{
			var chkmail;
    		chkmail = checkEmail(window.document.contact_form.email.value);
			if (chkmail)
			{
				trimTextareas();
				assignHidden();
				return true;
			} else {
				error_string += "Sorry, your email address is invalid.\nPlease try again.\n";
				error_string = "The following needs to be corrected: \n" + error_string;
				alert(error_string);
				return false;
			}
		} else {
			alert(error_string);
			return false;
		}
	}
	
				
	function checkEmail(the_email)
	{
    	var the_at = the_email.indexOf("@");
    	var the_dot = the_email.lastIndexOf(".");
    	var a_space = the_email.indexOf(" ");
    	if ((the_at != -1) &&  // if there's an '@'
       	 	(the_at != 0) &&  // and it's not at position 0
        	(the_dot != -1) && // and there's a '.'
        	(the_dot > the_at + 1) &&  // and something between the '@' and '.'
        	(the_dot < the_email.length - 1) && // and something after the '.'
        	(a_space  == -1))  // and there're no spaces
    	{
        	    return true;
    	}  else {
//        	    alert("sorry, your email address is invalid!\nPlease try again.");
        	    return false;
    	}
   }

	  

	function trimTextareas() 
	{
		var maxcharsLoc = 500; // Change number to maximum characters.
		var maxcharsIdeas = 1500;
		if (window.document.contact_form.location.value.length > maxcharsLoc) 
			window.document.contact_form.location.value = window.document.contact_form.location.value.substring(0,maxcharsLoc);
		if (window.document.contact_form.ideas.value.length > maxcharsIdeas) 
			window.document.contact_form.ideas.value = window.document.contact_form.ideas.value.substring(0,maxcharsIdeas);
	} 
	
//The following numbers make the func return a number between 10,000 and 99,999.  Setup: max number minus (min number -1).  Second number = min number.
	function randnum()
	{
		var rand_no = Math.floor((99999-9999)*Math.random()) + 10000;
		var textstring1 = "Your Glamour Package Drawing number is ";
		var textstring2 = ".  Please enter it the 'Services/Ideas you have in mind' field below, along with your Name, Email and (optional) Phone number - and click Send";
//		var textstring2 = "The Glamour Package Drawing is temporarily suspended to due maximum bookings from winning number responses.  Please
//		check again later.  If you can turn the spotlight on our Home Page to green by mousing over it, that means the Drawing is active;  if it's red, it 
//		is not active at this time.  Thanks.";
//WARNING: TEXT IN QUOTES MUST ALWAYS BE ON THE SAME LINE.
		return(textstring1 + rand_no + textstring2);	
	}


