var accordion='';

Image1=new Image(697,313);
Image1.src="lib/images/envelopes/envelope_ten.png";
Image2=new Image(697,313);
Image2.src="lib/images/envelopes/envelope_ten_w.png";
Image3=new Image(697,313);
Image3.src="lib/images/envelopes/envelope_nine.png";
Image4=new Image(697,313);
Image4.src="lib/images/envelopes/envelope_nine_w.png";
Image5=new Image(697,313);
Image5.src="lib/images/envelopes/envelope_six.png";


function generate_random_number(int_length) {
	var str_random="";
	var int_number="";

	for(i=0;i<int_length;i++) {
		int_number=Math.floor(Math.random()*10);
		str_random=str_random+int_number+"";
	}
	return str_random;
}


function is_email(str_email) {
	if(str_email=="") {
		return false;
	}
	else {
		var obj_regex=/^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;
		return obj_regex.test(str_email);
	}
}


function is_url(str_url) {
	if(str_url=="") {
		return false;
	}
	else {
		var obj_regex=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		return obj_regex.test(str_url);
	}
}


function check_extension(str_file) {
	var str_file_name=str_file;
	var str_file_length=parseInt(str_file_name.length)-3;
	var str_file_ext=str_file_name.substring(str_file_length,str_file_length+3);
	str_file_ext=str_file_ext.toLowerCase();
	
	if(str_file_ext=="gif"||str_file_ext=="jpg"||str_file_ext=="bmp"||str_file_ext=="png") {
		return true;
	}
	else {
		return false;
	}
}
function check_extension2(str_file) {
	var str_file_name=str_file;
	var str_file_length=parseInt(str_file_name.length)-3;
	var str_file_ext=str_file_name.substring(str_file_length,str_file_length+3);
	str_file_ext=str_file_ext.toLowerCase();
	
	if(str_file_ext=="pdf") {
		return true;
	}
	else {
		return false;
	}
}

function validate_upload_form() {
	if(check_extension($("image_file").getProperty("value"))) {
		parent.document.getElementById("oc_image").value="no_image.png";
		parent.document.getElementById("envelope_graphic").src="http://"+location.host+"/Uploads/edits/no_image.png";
		$("upload_delay").setStyle("display","block");
		$("upload_wrapper").setStyle("display","none");
		$("upload_new_image").submit();
	}
	else {
		alert("That file type is not accepted. Please choose .gif, .jpg, .bmp, .png");
	}
}
function validate_upload_form2() {
	if(check_extension2($("pdf_file").getProperty("value"))) {
		parent.document.getElementById("oc_image").value="no_image.png";
		parent.document.getElementById("envelope_graphic").src="http://"+location.host+"/Uploads/edits/no_image.png";
		$("upload_delay").setStyle("display","block");
		$("upload_wrapper").setStyle("display","none");
		$("upload_new_pdf").submit();
	}
	else {
		alert("That file type is not accepted. Please choose .pdf");
	}
}

function place_image(int_image_width,int_image_height,int_original_width,int_original_height,str_image_id,str_image_name) {
	$("envelope_graphic").src="Uploads/image_resizer.php?width="+int_image_width+"&height="+int_image_height+"&image=http://"+location.host+"/Uploads/edits/"+str_image_id+"_"+str_image_name;
	$("envelope_graphic").setStyle("width",int_image_width);
	$("envelope_graphic").setStyle("height",int_image_height);
	$("oc_image").setProperty("value",str_image_id+"_"+str_image_name);
	$("line_container").setStyle("left",(int_image_width+5));
	update_options_chosen(1);
	accordion.display(2);
}
function place_image2(str_image_id, str_image_name) {
	$("oc_file").setProperty("value",str_image_id+"_"+str_image_name);
	update_options_chosen(1);
	accordion.display(2);
}


function place_cropped_image(int_width,int_height,str_name) {
	$("envelope_graphic").src="Uploads/image_resizer.php?width="+int_width+"&height="+int_height+"&image=http://"+location.host+"/Uploads/edits/"+str_name;
	$("envelope_graphic").setStyle("width",int_width);
	$("envelope_graphic").setStyle("height",int_height);
	$("oc_image").setProperty("value",str_name);
	$("line_container").setStyle("left",(int_width+5));
	update_options_chosen(1);
	accordion.display(2);
}


function get_extension(str_name) {
	var str_file_length=parseInt(str_name.length)-3;
	var str_file_ext=str_name.substring(str_file_length,str_file_length+3);
	return str_file_ext;
}


function remove_extension(str_name) {
	return str_name.substring(0,str_name.length-4);
}


function validate_contact_form() {
	if($("c_name").getProperty("value")=="") {
		alert("Please enter your name.");
		$("c_name").focus();
		return false;
	}
	
	if($("c_email").getProperty("value")=="") {
		alert("Please enter your email address.");
		$("c_email").focus();
		return false;
	}
	else {
		if(!is_email($("c_email").getProperty("value"))) {
			alert("Your email address is not valid.");
			$("c_email").focus();
			return false;
		}
	}

	if($("c_telephone").getProperty("value") == "") {
		alert("Please enter your telephone number.");
		$("c_telephone").focus();
		return false;
	}

	if($("c_company").getProperty("value")=="") {
		$("c_company").setProperty("value","N/A");
	}

	if($("c_address").getProperty("value")=="") {
		$("c_address").setProperty("value","N/A");
	}

	if($("c_city").getProperty("value")=="") {
		$("c_city").setProperty("value","N/A");
	}

	if($("c_state").getProperty("value")=="") {
		$("c_state").setProperty("value","N/A");
	}
	
	if($("c_zip").getProperty("value")=="") {
		$("c_zip").setProperty("value","N/A");
	}

	if($("c_comments").getProperty("value") == "") {
		$("c_comments").setProperty("value","N/A");
	}

	$("submit_form").disabled=true;
	$("submit_form").setProperty("value","Submitting");
	return true;
}
