var popUpWin=0;

function insertMovie(filestr, movieID , h, w , isPlayer) {
	if (isPlayer){
		var so = new SWFObject("flv_player01.swf?media=" + filestr + "&autoplay=true&controls=auto", "flash01", h , w,  "7", "#ccc");
	} else {
		var so = new SWFObject("" + filestr, "flash02", h , w,  "7", "#ccc");	
	}
	so.addParam("AllowScriptAccess","sameDomain");
	so.write(movieID);
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

function mailTo(type){
	switch (type) {
		case 'friend' :
			form = document.tellAFriend;
			senderName = form.senderName.value;
			senderEmail = form.senderEmail.value;
			recipient = form.recipient;
			recipientList = "";
			recipientList = new Array();
			recipientErrorList = "";
			senderErrorList = "";
			
			// check if sender email is valid
			if(senderName == ""){
				senderErrorList += "Please enter a valid name for sender<br/>";
			}
			
			if(!validateEmail(senderEmail)){
				senderErrorList += "Please enter a valid email address for the sender<br/><br/>";
			}
			
			
			for(var i = 0;i<recipient.length;i++){
				thisRecipient = recipient[i].value;
				// check if recipeint values are null then add to array if email addresses are valid, else add to error list
				if (thisRecipient != ""){
					if(validateEmail(thisRecipient)){
						recipientList.push(thisRecipient)
					} else  {
						recipientErrorList += "Friend's E-mail #  " + (i + 1) + "  address is invalid<br/>";
					}
				}
			}

			if(recipientList.length == 0)
				recipientErrorList += "Please enter at least one valid recipient email address<br/>";
			
			outputErrors ("senderError", senderErrorList);
			outputErrors ("recipientError", recipientErrorList);
			if(recipientErrorList == "" && senderErrorList ==""){return true;}
			else{return false;}
			break;	
		default :
			break;
	}
}

// ** outputs errors for recipient and sender
function outputErrors (node, errorList) {
	thisError = document.getElementById(node);
	thisError.innerHTML = errorList;
	thisError.style.display="block";
}	

function validateEmail(email){
	if(email != "" && email.match(/@.*\./))
		return true;
	else
		return false;
}

function popUpWindow(URLStr, left, top, width, height, scrolling) {
	closepopUpWindow()
	scrollbar = (scrolling) ? "yes" : "no";
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+ scrollbar +',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

// go to the jcpenney store and close the popup window that the call originated from
function gotoJcpenney(){
	window.open('http://www3.jcpenney.com/jcp/StoreLocatorMenu.aspx?cmResetCat=true&CmCatId=HomePage')
	closepopUpWindow()
}

// close the popup window 
function closepopUpWindow(){
  if(popUpWin && !popUpWin.closed)
	  popUpWin.close();
}
