function get_focus(elem, str_text, change) {
	if(change==1){
			elem.className='sel';
			if (elem.value==str_text) elem.value='';
		}
	else {
		if (elem.value==str_text) elem.value='';
		}
	
}
//----------------------------------------------------------------------------------------
function lose_focus(elem, str_text, change) {
	if(change==1){
			elem.className='out';
			if (elem.value=='') elem.value=str_text;
		}
	else {
		if (elem.value=='') elem.value=str_text;
		}
	
}
//----------------------------------------------------------------------------------------
function check_field(field_name, label){
	var sfield_name = field_name.value;
	var ifield_name = sfield_name.length;
	
	if(ifield_name== 0) {
	alert ("'" + label + "' is a required field.");
	field_name.focus();
	return 0;
	}
	
	var OK = false;
	for(var i = 0;i<ifield_name;i++) if(sfield_name.charAt(i) != " ") {	OK = true;	break;	}  
	if(OK == false) { alert("'" + label + "' field contains only whitespaces."); field_name.focus(); return 0; }
	return 1;
}

//-------------------------------------------------------------------------

function check_textarea(field_name, label){
	var sfield_name = field_name.value;
	var ifield_name = sfield_name.length;
	
	if(ifield_name== 0) {
	alert ("'" + label + "' is a required field.");
	field_name.focus();
	return 0;
	}
	
	var OK = false;
	for(var i = 0;i<ifield_name;i++) if(sfield_name.charAt(i) != " ") {	OK = true;	break;	}  
	if(OK == false) { alert("'" + label + "' field contains only whitespaces."); field_name.focus(); return 0; }
	if(ifield_name>1000){alert("Only 1000 characters are allowed for the "+label+" field"); field_name.focus(); return 0; }
	
	return 1;
}

//-------------------------------------------------------------------------

function check_email(field_name, label){
	var sfield_name = field_name.value;
	var ifield_name = sfield_name.length;
	var Amp = false;
	var Period = false;
	for(var i = 0;i<ifield_name;i++) if(sfield_name.charAt(i)=="@"){Amp = true; break;}
	for(var i = 0;i<ifield_name;i++) if(sfield_name.charAt(i)=="."){Period = true; break;}
	if(Amp == false || Period == false) {alert("Please enter a valid e-mail address");	field_name.focus();	return 0;}
	return 1;
}
//-------------------------------------------------------------------------
function validate_quote(){
	if(check_field(document.form_quote.name, "Your Name")==0) return;
	if(check_field(document.form_quote.company, "Your Company")==0) return;
	
	if(document.form_quote.project_type.value=="") {
		alert ("Please select the project type.");
		document.form_quote.project_type.focus();
		return;		
	}

	
	//if(document.form_quote.project_type.value=="an existing website") {
	//	if(check_field(document.form_quote.website_address, "Your website address")==0) return;
	//}
	
	
	if( document.form_quote.website_design.checked!=true && document.form_quote.web_aplication_development.checked!=true &&  document.form_quote.software_development.checked!=true &&  document.form_quote.logo_branding_identity.checked!=true &&  document.form_quote.website_hosting.checked!=true &&  document.form_quote.content_management_system.checked!=true &&	document.form_quote.shopping_cart.checked!=true &&  document.form_quote.kiosk_software.checked!=true   &&  document.form_quote.iphone_application_development.checked!=true   &&  document.form_quote.droid_application_development.checked!=true  ) {
		alert ("Please select at least one service you require.");
		return;
	}
	
	if(document.form_quote.budget.value=="") {
		alert ("Please select your budget.");
		document.form_quote.budget.focus();
		return;		
	}

	if(document.form_quote.time.value=="") {
		alert ("Please select the timeline.");
		document.form_quote.time.focus();
		return;		
	}
	
	if(document.form_quote.found_us.value=="") {
		alert ("Please select how you found us.");
		document.form_quote.found_us.focus();
		return;		
	}


	if(document.form_quote.found_us.value=="Someone liked me so much that they told me about Stone Soup.") {
		if(check_field(document.form_quote.who, "Who referred you?")==0) return;
	}
	
	if(check_textarea(document.form_quote.project_description, "Description of your project")==0) return;
	if(check_field(document.form_quote.phone_number, "Your best daytime phone number")==0) return;
	if(check_email(document.form_quote.email_address, "Your email address")==0) return;
	
	if(document.form_quote.secure.value!="100") {
		alert ("You did not answer the math quiz correctly.");
		document.form_quote.secure.focus();
		return;		
	}
	
	document.form_quote.letter_content.value = document.getElementById("message").innerHTML;
	
	document.form_quote.submit();
}
//-------------------------------------------------------------------------
function validate_quote_simple(){
	if(check_field(document.form_quote.name, "Name")==0) return;
	if(check_email(document.form_quote.email, "Email")==0) return;
	document.form_quote.submit();
}
//-------------------------------------------------------------------------
function popup(loc,width,height)
{
	var winl = (screen.width-width)/2;
	var wint = (screen.height-height)/2;	 
	mywindow = window.open (loc, "mywindow","location=0,status=0,scrollbars=0,top="+wint+",left="+winl+",width="+width+",height="+height);
}
//-------------------------------------------------------------------------
function validate_rfq(){

	if(check_field(document.form_quick_upload.upload_doc, "File")==0) return;
	if(check_field(document.form_quick_upload.name, "Name")==0) return;
	if(check_field(document.form_quick_upload.company, "Company")==0) return;
	
	if(!document.form_quick_upload.method[0].checked && !document.form_quick_upload.method[1].checked){alert("Please select your preffered method of communication."); document.form_quick_upload.method[0].focus(); return;}
	
	//radio 1
	
	if(document.form_quick_upload.method[0].checked){
		if(check_email(document.form_quick_upload.email, "E-mail")==0) return;
	}
	
	//radio 2 
	
	if(document.form_quick_upload.method[1].checked){
		if(check_field(document.form_quick_upload.phone, "Phone")==0) return;
	}
	
	document.form_quick_upload.submit();
}
//-------------------------------------------------------------------------
function validate_resume(){
	if(check_field(document.form_quick_upload.name, "Name")==0) return;
	if(check_email(document.form_quick_upload.email, "E-mail")==0) return;
	if(check_field(document.form_quick_upload.upload_doc, "File")==0) return;
	document.form_quick_upload.submit();
}
//-------------------------------------------------------------------------
function validate_invoice(){
	if(check_field(document.form_invoice.x_invoice_num, "Invoice No.")==0) return;
	if(check_field(document.form_invoice.x_amount, "Payment Amount")==0) return;
	if(isNaN(document.form_invoice.x_amount.value)) {alert("Only numbers and periods allowed for the 'Payment Amount' field."); document.form_invoice.x_amount.focus(); return;}
	
	if(check_field(document.form_invoice.x_first_name, "Cardholder First Name")==0) return;
	if(check_field(document.form_invoice.x_last_name, "Cardholder Last Name")==0) return;
	if(check_field(document.form_invoice.x_address_1, "Billing Address 1")==0) return;
	if(check_field(document.form_invoice.x_city, "City")==0) return;
	if(check_field(document.form_invoice.x_zip, "Zipcode")==0) return;
	if(check_email(document.form_invoice.x_email, "Email Address")==0) return;
	if(check_field(document.form_invoice.x_phone, "Telephone")==0) return;
	
	if(check_field(document.form_invoice.x_card_num, "Credit Card Number")==0) return;
	if(check_field(document.form_invoice.x_card_code, "Card Verification Number")==0) return;
	if(check_field(document.form_invoice.x_exp_date, "Expiration Date")==0) return;
	
	document.form_invoice.submit();
}
//-------------------------------------------------------------------------
function startGallery() {
		var myGallery = new gallery($('myGallery'), { timed: true });
	}
//-------------------------------------------------------------------------
function expandIntro() {
			$('mask').set('morph', { duration: 1000, link:'cancel' }).morph({height: 589});
			$('a_expand').setProperty('class', 'display_none' ) ;
			$('a_collapse').setProperty('class', 'display_inline' ) ;
}
//-------------------------------------------------------------------------
function collapseIntro() {
			$('mask').set('morph', { duration: 1000, link:'cancel' }).morph({height: 154});
			$('a_expand').setProperty('class', 'display_inline' ) ;
			$('a_collapse').setProperty('class', 'display_none' ) ;
}
//-------------------------------------------------------------------------
function highlight(obj) {
	document.getElementById(obj).className="highlighted";
}
function blank(obj) {
	document.getElementById(obj).className="blank";
}
