function set_cookie(name, value) {
	var today = new Date();
        var expire = new Date();
        expire.setTime(today.getTime() + (3600000 * 24)); // expire in 1 day
        document.cookie = name + "=" + escape(value) + ";expires=" + expire.toGMTString();
}
function get_cookie(name) {
	 var theCookie = " " + document.cookie;
         var ind = theCookie.indexOf(" " + name + "=");
         if(ind == -1) { ind = theCookie.indexOf(";" + name + "="); }
         if(ind == -1 || name == "") { return ""; }
         var ind1 = theCookie.indexOf(";", ind + 1);
         if (ind1 == -1) { ind1 = theCookie.length; }
         return unescape(theCookie.substring(ind + name.length + 2, ind1));
}
function start_file_upload(input, form_name, sid) {
	var valid_graphic_types = new Array("eps", "jpg", "psd", "ai", "tif", "pdf", "zip", "sit", "png");	
	var tokens = input.value.split("\.");
	var ext = tokens[tokens.length - 1];
	ext = ext.toLowerCase();
	valid_types_error = "Invalid File Type.\n\nThe following file types are valid for upload";
	valid_types_error += "\n\n";
	found = false;
	for(i = 0; i < valid_graphic_types.length; i++) {
		valid_types_error += "." + valid_graphic_types[i] + " ";

		if(ext == valid_graphic_types[i]) {
			found = true;
			break;
		}
	}
	if(!found) {
		alert(valid_types_error);	
	}						
	else {
		alert("The following file is being queued for upload:\n\n" + input.value + "\n\nPlease wait for the transfer to complete before leaving this page.\n\n");	
		document.getElementById(form_name + "_container_name").style.visibility = "visible";
		document.getElementById(form_name + "_container_name").style.display = "block";	
		document.getElementById(form_name + "_progress_frame").src = "/personalization/upload_progress.php?sid=" + sid;
		document.getElementById(form_name).submit();		
		input.disabled = true;
	}
}
function record_spec(input, pid) {
	spec_url = "/personalization/record_specification.php?pid=" + pid + "&spec_name=" + input.name + "&spec_value=" + input.value;
	document.getElementById("spec_target_frame").src = spec_url;
}
function record_spec_select(input, pid) {
	spec_url = "/personalization/record_specification.php?pid=" + pid + "&spec_name=" + input.name + "&spec_value=" + input.options[input.selectedIndex].value;
	document.getElementById("spec_target_frame").src = spec_url;
}
function record_spec_checkbox(input, name, pid) {
	value = '';
	if(input.checked) { value = 'Use Default'; }
	spec_url = "/personalization/record_specification.php?pid=" + pid + "&spec_name=" + name + "&spec_value=" + value;
	document.getElementById("spec_target_frame").src = spec_url;
}
function record_spec_graphic(pid, name, value) {
	spec_url = "/personalization/record_specification.php?pid=" + pid + "&spec_name=" + name + "&spec_value=" + value;
	document.getElementById("spec_target_frame").src = spec_url;
}
function validate_email(email) {
	var emailFilter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	if(!emailFilter.test(email)) {
		alert('Invalid email address entered: [' + email + ']\n\nPlease enter a valid email address.\n');
		return false;
	}
	else { return true; }
}
function view_color_and_font_guide(id) {
	if(document.getElementById('color_and_font_guide_div').style.visibility == "hidden") {
		document.getElementById('color_and_font_guide_div').style.visibility = "visible";
		document.getElementById('color_and_font_guide_div').style.display = "block";	
		document.getElementById(id).innerHTML = "Close Reference";
	}
	else {
		document.getElementById('color_and_font_guide_div').style.visibility = "hidden";
		document.getElementById('color_and_font_guide_div').style.display = "none";
		document.getElementById(id).innerHTML = "View Reference";
	}
}
function close_privacy_popup() {
	document.getElementById('privacy_popup_div').style.visibility = "hidden";
	document.getElementById('privacy_popup_div').style.display = "none";
	document.getElementById('privacy_popup_div_outer').style.visiblility = "hidden";
}
function get_privacy_popup() {
	if(document.getElementById('privacy_popup_div').style.visibility == "hidden") {
		document.getElementById('privacy_popup_div_outer').style.visiblility = "visible";
		document.getElementById('privacy_popup_div').style.height = 400;
	        document.getElementById('privacy_popup_div').style.width = 640;
        	document.getElementById('privacy_popup_div').style.left = "39%";
        	document.getElementById('privacy_popup_div').style.top = "25%";
        	document.getElementById('privacy_popup_div').style.marginTop = (get_scroll_index() - 20);
        	document.getElementById('privacy_popup_div').style.marginLeft = -180;				
		document.getElementById('privacy_popup_div').style.visibility = "visible";
		document.getElementById('privacy_popup_div').style.display = "block";	
		document.getElementById("privacy_popup_div").innerHTML = "Loading ....";		
 		var request = false;
   		var self = this;
   		if(window.XMLHttpRequest) {
   			self.request = new XMLHttpRequest();
   		}
		else if(window.ActiveXObject) {
			self.request = new ActiveXObject("Microsoft.XMLHTTP");  
		} 		
   		self.request.open('GET', '/templates/privacy_policy.php', true);
   		self.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');    
   		self.request.onreadystatechange = function() {    	
   			if(self.request.readyState == 4) {       	    					  			     	        	        	
       			document.getElementById("privacy_popup_div").innerHTML = self.request.responseText;
   			}
  		}
   		self.request.send('');						
	}
}
function get_email_cart_prompt(top_nav_flag) {
	document.getElementById('email_cart_prompt').style.height = 25;
	document.getElementById('email_cart_prompt').style.width = 300;
	if(top_nav_flag) {	
		document.getElementById('email_cart_prompt').style.left = "75%";
		document.getElementById('email_cart_prompt').style.top = "10%";
	}
	else {	
		document.getElementById('email_cart_prompt').style.left = "50%";
		document.getElementById('email_cart_prompt').style.top = "25%";
	}
	document.getElementById('email_cart_prompt').style.marginTop = (get_scroll_index() - 20);
    	document.getElementById('email_cart_prompt').style.marginLeft = -180;				
	document.getElementById('email_cart_prompt').style.visibility = "visible";
	document.getElementById('email_cart_prompt').style.display = "block";		
}
function get_scroll_index() {
    var scroll_index = 50;
    if(navigator.appName == "Microsoft Internet Explorer") {
		scroll_index = document.body.scrollTop;
    }
    else {
		scroll_index = window.pageYOffset;
    }
    return scroll_index;
}
function close_submission_popup() {
	document.getElementById('submission_popup_div').style.visibility = "hidden";
	document.getElementById('submission_popup_div').style.display = "none";
	document.getElementById('submission_popup_div_outer').style.visiblility = "hidden";
}
function get_submission_popup() {
	if(document.getElementById('submission_popup_div').style.visibility == "hidden") {
		document.getElementById('submission_popup_div_outer').style.visiblility = "visible";
		document.getElementById('submission_popup_div').style.height = 380;
        	document.getElementById('submission_popup_div').style.width = 340;
        	document.getElementById('submission_popup_div').style.left = "75%";
        	document.getElementById('submission_popup_div').style.top = "25%";
        	document.getElementById('submission_popup_div').style.marginTop = (get_scroll_index() - 20);
        	document.getElementById('submission_popup_div').style.marginLeft = -180;				
		document.getElementById('submission_popup_div').style.visibility = "visible";
		document.getElementById('submission_popup_div').style.display = "block";	
		document.getElementById("submission_popup_div").innerHTML = "Loading ....";		
 		var request = false;
   		var self = this;
   		if(window.XMLHttpRequest) {
   			self.request = new XMLHttpRequest();
   		}
		else if(window.ActiveXObject) {
			self.request = new ActiveXObject("Microsoft.XMLHTTP");  
		} 		
   		self.request.open('GET', '/templates/submission_requirements.php', true);
   		self.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');    
   		self.request.onreadystatechange = function() {    	
   			if(self.request.readyState == 4) {       	    					  			     	        	        	
       			document.getElementById("submission_popup_div").innerHTML = self.request.responseText;
   			}
  		}
   		self.request.send('');						
	}
}

