function contributor_popup(scope, item) {
    var url = "/contributor/" + scope + "/" + item + ".html";
    contributor = window.open(url, "contributor", "scrollbars=1,resizable=1,width=600,height=700");
    contributor.focus();
    return (false);
}



// This script builds email addresses

var user;
var domain;
var suffix;
var displayname;

function putaddr(user, domain, suffix, displayname){
var txt_1 = 'mai';
var txt_2 = 'lto:';
var txt_3 = '@';
document.write('<a href="' + txt_1 + txt_2 + user + txt_3 + domain + '.' + suffix + '">' 
+ displayname + '</a>');
}



// This script validates and makes required the fields in the Media Kits access form

function Form_Validator(MediaKitForm)
{
  //First Name
  if (MediaKitForm.q4.value == "")
  {
    alert("Please enter your first name.");
    MediaKitForm.q4.focus();
	return (false);
  }
  
  //Last Name
  if (MediaKitForm.q5.value == "")
  {
    alert("Please enter your last name.");
    MediaKitForm.q5.focus();
    return (false);
  }
  
  //Validate Company
  if (MediaKitForm.q7.value == "")
  {
    alert("Please enter the name of your company.");
    MediaKitForm.q7.focus();
    return (false);
  }
  
  //Validate Email
  if (MediaKitForm.q8.value.length > 0)
  {
    var q8 = MediaKitForm.q8.value;
    var i=q8.indexOf("@");	//see if there"s an @ sign
    var x=q8.indexOf("@",i+1); //make sure there"s not more @ signs
    var p=q8.indexOf(".",i);  //there must be a period 
 
    if ( (i==-1) || (p<(i+2)) || (x>i) || (p >=(q8.length - 2)))
    {
      alert("Please enter a valid Email Address.");
      MediaKitForm.q8.focus();
      return (false);
    }
  }

  if (MediaKitForm.q8.value == "")
  {
    alert("Please enter your email address.");
    MediaKitForm.q8.focus();
    return (false);
  }
  
  //Validate Phone
  if (MediaKitForm.q9.value == "")
  {
    alert("Please enter your phone number.");
    MediaKitForm.q9.focus();
    return (false);
  }
  
  //Validate Address


  if (MediaKitForm.q10.value == "")
  {
    alert("Please enter your address.");
    MediaKitForm.q10.focus();
    return (false);
  }
  
  //Validate City
  if (MediaKitForm.q11.value == "")
  {
    alert("Please enter your city.");
    MediaKitForm.q11.focus();
    return (false);
  }
  
  //Validate State
  if (MediaKitForm.q12.value == "")
  {
    alert("Please enter your state.");
    MediaKitForm.q12.focus();
    return (false);
  }
  
  // Validate Zip Code
  if (MediaKitForm.q13.value == "")
  {
    alert("Please enter your zip code.");
    MediaKitForm.q13.focus();
    return (false);
  }

  if (MediaKitForm.q13.value.length != 5)
  {
    alert("Please enter 5 characters only in the \"Zip Code\" field.");
    MediaKitForm.q13.focus();
    return (false);
  }

    var checkOK = "0123456789";
    var checkStr = MediaKitForm.q13.value;
    var allValid = true;
    var validGroups = true;
    var decPoints = 0;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
        if (j == checkOK.length)
      {
        allValid = false;

        break;
      }
      allNum += ch;
    }
    if (!allValid)
    {
      alert("Please enter only digit characters in the \"Zip Code\" field.");
      MediaKitForm.q13.focus();
      return (false);
    }
	
	//Country
	if (MediaKitForm.q48.value == "")
	{
      alert("Please enter your Country.");
      MediaKitForm.q48.focus();
      return (false);
	}
  
  return (true);
}



//This script creates a cookie for store MediaKitForm information

var expDays = 100;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));

}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function MediaKitForm() {  
	var mode = MediaKitForm.arguments[0];

	for(f=1; f<MediaKitForm.arguments.length; f++) {
		formName = MediaKitForm.arguments[f];
		if(mode == 'open') {	
			cookieValue = GetCookie('saved_'+formName);
			if(cookieValue != null) {
				var cookieArray = cookieValue.split('#cf#');

				if(cookieArray.length == document[formName].elements.length) {
					for(i=0; i<document[formName].elements.length; i++) {

						if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }
						else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }
						else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }
						else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
					}
				}
			}
		}

		if(mode == 'save') {	
			cookieValue = '';
			for(i=0; i<document[formName].elements.length; i++) {
				fieldType = document[formName].elements[i].type;

				if(fieldType == 'password') { passValue = ''; }
				else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }
				else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }
				else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }
				else { passValue = document[formName].elements[i].value; }

				cookieValue = cookieValue + passValue + '#cf#';
			}
			cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
			
			SetCookie('saved_'+formName, cookieValue, exp);		
		}	
	}
}
