//  site specific JavaScript for the Post-it Digital EWCD site.



function disableEnterKey() { 
	if (window.event.keyCode == 13) {
	 window.event.keyCode = 0; 
	 }
} 


// Used to check for blank input fields
function isblank(s) {
	if ((s == null) || (s == "")) return true;
	for(var i = 0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}


/* Script to check the email - this utilizes the functions below it 
 * emailID is the e-mail input name (F*)
 */
function checkOnSubmit(emailID) {
	// Remove white space from the e-mail F input
	emailID.value = removeSpace(emailID.value);
	
	// Set input email to the F value
	document.contact.email.value = emailID.value;
	
	// Checks the E-mail field for Invalid Characters & Length
	if(isEmailOkay(emailID.value) == false){	
		emailID.focus();
		return false; 
	 }
	 
	// ****************************************************
	// CustomValidateFunction call added 12/30/04 by SM. 
	// To use: include lines like these in the PAGE_MSG.entry.header (enclosed in script tags):
	//	function myCustomValidate() {
	//		if(document.qform.F5.value == '') { 
	//			alert("Please enter a product type.");
	//			return false;
	//		}
	//	}	
	//	var customValidateFunction = "myCustomValidate()";
	// ****************************************************
	if(window.customValidateFunction) {
		customValidation = eval(customValidateFunction);
	}
	return customValidation;
	
	return true;
}


/* Script to remove the spaces in the string 
 * @param src ---string in which the spaces are to be removed
 */
function removeSpace(src) {
	var result="";
	var inPtr=0;
	// Loop to check the white spaces
	for(inPtr=0; inPtr < src.length; inPtr++) {
		if(src.charAt(inPtr) != ' ') {//check if the character is white space
			result+=src.charAt(inPtr);
		} // end of check for the character is white space
	} // End of loop
	return result;
}


/* Script to check the bad characters in the mail
 * @param string ----contains the mail string in which bad charaters 
                     are to be checked */  
function emailBadChars(string) {
	if (!string) return false;
	var iChars = "*|,\":<>[]{}`\';()&$#%";
	// Loop to check the string
	for (var i = 0; i < string.length; i++) {
		if (iChars.indexOf(string.charAt(i)) != -1) { //condition to check for bad chars
			return true;
		} // End of condition
	} // End of loop
	return false;
} // End of emailBadChars()                 



// Script to check whether the the email format is ok
function isEmailOkay(valueCheck) {
	var result = true;
	if (emailBadChars(valueCheck) == true) {	//Check for badcharacters
		   alert("We're sorry, but the email address you entered contains invalid characters.\r\n"+
			"Please re-enter your email address.");
		result = false;
	}	// End of check for bad characters
	else {	// Else for not having bad characeters
		if(valueCheck.length < 7) {				//check length of email
				alert("We're sorry, but the email address you entered does not contain enough characters to be valid.\r\n"+
				"Please re-enter your email address.");
				result = false;
		} // End of check length
		else {
		  if(valueCheck.indexOf('@') < 1
				|| valueCheck.lastIndexOf('.') < valueCheck.indexOf('@')+2
				|| valueCheck.lastIndexOf('.') == valueCheck.length - 1
				|| valueCheck.lastIndexOf('@') == valueCheck.length - 1)  {	 	//Check for  @, . in the email
			alert("We're sorry, but the email address you entered does not follow the pattern x@x.x\r\n"+
			"Please re-enter your email address.");
			result = false;
		  }// End of check for @ . in email
		}
	} // End of else for not having bad characters
	return result;
} // End of isEmailOkay()


// Rollovers
function mainRollovers(status,nav_item) {
	if (status) {
		document.images[nav_item].src = "images/"+nav_item+"1.jpg";
	} else {
		document.images[nav_item].src = "images/"+nav_item+"0.jpg";
	}
}


// Used for File popups on the site WITHOUT SCROLLBARS
/* Example on usage:
 * Format:  <a href='javascript:popupFile("URL",width,height);'>LinkText</a>
 * Example: <a href='javascript:popupFile("http://www.3m.com/us/office/meetings/vo/vo.html",720,500);'>LinkText</a>
 */
 
var popupwin = null;
var response = null;

function popupFile(fileURL,fileWidth,fileHeight) {
	window.setTimeout("checkPopup()",3000);
	// Width & Height of your Flash Document
	var sx = fileWidth;
	var sy = fileHeight;
	// Position the window in the Middle of the Screen
	var winl = (screen.width-sx)/2;
	var wint = (screen.height-sy)/2;
	// The following two lines prevents an IE error.
	popupwin=window.open("","NewWindow","top=50,left=50,width=200,height=200");
	popupwin.window.close();
	// Popup Code
	popupwin=window.open(fileURL,"NewWindow","toolbar=no,location=no,scrollbars=no,directories=no,status=no,menubar=no,top="+wint+",left="+winl+",width="+sx+",height="+sy+"");
	popupwin.window.focus();
}

function popupFileManually(fileURL,fileWidth,fileHeight) {
	
	window.setTimeout("checkPopup()",3000);
	// Width & Height of your Flash Document
	var sx = fileWidth;
	var sy = fileHeight;
	// Position the window in the Middle of the Screen
	var winl = (screen.width-sx)/2;
	var wint = (screen.height-sy)/2;
	// Popup Code
	popupwin=window.open(fileURL,"NewWindow","toolbar=no,location=no,scrollbars=no,directories=no,status=no,menubar=no,top="+wint+",left="+winl+",width="+sx+",height="+sy+"");
	popupwin.window.focus();
}


function checkPopup() {
	if (!response) {
		document.getElementById("popupError").style.display = "block";
		document.getElementById("popupError").innerHTML = "<p style='color:#f00;'><b>We detected a popup blocker that stopped the new window from opening.  Please <a href=\"#\" onClick=\"popupFileManually('picture_paper_survey.html',320,620); return false; \">click here</a> to open the window manually.</b></p>";
	} else {
		document.getElementById("popupError").style.display = "none";
	}
	response = null;
}