// Checks to make sure that something has been entered
// in the search text box before it can be submitted to the search engine.
function checkrequired() {
if ((document.searchform.Terms.value=='')||(document.searchform.Terms.value=='Search zygo.com')) {
alert("Before starting the search,\nplease enter the words that you want to\nsearch for in the text box."); return false; }
else { return true; }
}

function startsearch() {
if ((document.searchform.Terms.value=='')||(document.searchform.Terms.value=='Search zygo.com')) {
alert("Before starting the search,\nplease enter the words that you want to\nsearch for in the text box."); }
else { document.searchform.submit(); }
}

function startsearchG() {
if ((document.searchform.q.value=='')||(document.searchform.q.value=='Search zygo.com')) {
alert("Before starting the search,\nplease enter the words that you want to\nsearch for in the text box."); }
else { document.searchform.submit(); }
}

function popup(mypage, myname, w, h, win_x, win_y, scroll, resize) {
	if (screen.width) {
	var win_x = (screen.width - w) / 2;
	var win_y = (screen.height - h) / 4;
	}
else { var win_x = "200"; var win_y = "100"; }
winprops = 'height='+h+',width='+w+',top='+win_y+',left='+win_x+',scrollbars='+scroll+',resizable='+resize;
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function laime(user,domain,link) {
var default_domain = "zygo.com";								// defines default domain for email addresses
// document.write('user='+user + ', domain=' + domain + '<br>')	// for troubleshooting
if (!domain) { domain = default_domain }						// inserts default domain if omitted
domain	= domain.replace( /[\s,]+/g, "." );						// convert space or , to .
user	= user.replace( /\s/g, "" );							// remove spaces in user name
if (!/\.\w{2,3}$/.test(domain)) { domain = domain + '.com' }	// appends .com if omitted
var fulladdr = user + "@" + domain;
if (!link) { link = fulladdr }									// if no link name specified, use address

document.write('<a class="txtlink" href="mailto:' + fulladdr + '?bcc=webmaster@zygo.com" onClick="javascript:urchinTracker(\'/ClickedEmail:' + fulladdr + '\');">' + link + '</a>')
};

function laimetrap(user,domain,link) {
var default_domain = "zygo.com";								// defines default domain for email addresses
// document.write('user='+user + ', domain=' + domain + '<br>')	// for troubleshooting
if (!domain) { domain = default_domain }						// inserts default domain if omitted
domain	= domain.replace( /[\s,]+/g, "." );						// convert space or , to .
user	= user.replace( /\s/g, "" );							// remove spaces in user name
if (!/\.\w{2,3}$/.test(domain)) { domain = domain + '.com' }	// appends .com if omitted
var fulladdr = user + "@" + domain;
if (!link) { link = fulladdr }									// if no link name specified, use address
document.write(fulladdr)
};


function showStatus(msg) {
window.status=msg;
}

function popup(mypage, myname, w, h, scroll, win_x, win_y) {

if (!win_x) { win_x = (screen.width - w) / 2 };
if (!win_y) { win_y = (screen.height - h) / 4 };
// if (screen.width) {
// if (!win_x) { win_x = (screen.width - w) / 2 };
// if (!win_y) { win_y = (screen.height - h) / 4 };
// }
// else { var win_x = "200"; var win_y = "100"; }
winprops = 'height='+h+',width='+w+',top='+win_y+',left='+win_x+',scrollbars='+scroll+',resizable';
win = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}




function validate() {

if (document.hottip_form.ques_info != null) {			// see if comments box has content
var maxchar		= 500;
var sumval		= document.hottip_form.ques_info.value; sumval = strip(sumval);
var sumlength	= sumval.length;
var comment		= document.hottip_form.ques_info;
var diff		= sumlength - maxchar;

if (diff > 1) { var chars = " characters." } else { var chars = " character." }

if (sumlength > maxchar && comment != '') {
alert("The \"Question or Additional Info\" entry contains "+sumlength+" characters.\n\
The limit is "+maxchar+" characters.\nPlease shorten it by "+diff+chars); return false;}

}	// end spie summary checking

return true;

}	// end validate function




function strip( s ) {
	s = s.replace( /^\s+/, "" );   // remove leading whitespace
	s = s.replace( /\s+$/, "" );  // remove trailing whitespace
	return s;
}



function validate( aForm )
{

/* 
if	(aForm.elements.Dates2) {
	var value = aForm.elements.Dates2.value; value = strip( value );
	if ( value == '0' ) { alert( "You must enter a Second Choice for the Class Dates" ); return false; }
}
*/

  var value = aForm.elements.Name.value;
  value = strip( value );
  if ( value == '' )
    {
    alert( "You must enter a Name" );
    return false;
    }

  value = aForm.elements.MailingAddress.value;
  value = strip( value );
  if ( value == '' )
    {
    alert( "You must enter a Mailing Address" );
    return false;
    }

  value = aForm.elements.PhoneNumber.value;
  value = strip( value );
  if ( value == '' )
    {
    alert( "You must enter a Phone Number" );
    return false;
    }

  value = aForm.elements.HowLearnedOf.value;
  value = strip( value );
  if ( value == '' )
    {
    alert( "Please tell us how you found out about ZYGO Training Courses." );
    return false;
    }
    
   value = aForm.elements.EMailAddress.value; value = strip( value );
   if ( value == '' )  { alert( "You must enter an EMail Address" ); return false; }


var postring = '';
if (aForm.elements.PONumber) { value = aForm.elements.PONumber.value; postring = ' or a PO Number'; } else { value = '' }
value = strip( value );
if ( value == '' )
{

    var value2 = aForm.elements.NameOnCard.value; value2 = strip( value2 );
    if ( value2 == '' ) { alert( "You must enter Credit Card Info" + postring ); return false; }

    value = aForm.elements.CardNumber.value; value = strip( value );
    if ( value == '' ) { alert( "You must enter a Credit Card Number" + postring ); return false; }

    value = aForm.elements.ExpirationDate.value; value = strip( value );
    if ( value == '' )  { alert( "You must enter an Expiration Date" ); return false; }

    value = aForm.elements.CardIssuer.value; value = strip( value );
    if ( value == '' )  { alert( "You must select a Credit Card Issuer\nfrom the drop-down menu" ); return false; }

}
else {
	value = aForm.elements.CardNumber.value; value = strip( value );
	if ( value != '' ) {
	alert( "You have entered both Credit Card Information\nand a PO Number. Please use one or the other." );
	return false;
	}
}

return true;

}


// The following was borrowed from CCBN to make the Help popup windows work on the Investor pages.

function openCapsule(url, name, prop)
{
sizedWindow = window.open(url, name, prop); { setTimeout('sizedWindow.focus();', 250); }
}


// The following was for testing Urchin Tracking Module

// function urchinTracker (URL) { alert(URL) }
// function urchinTracker (URL) { return }


function PopupWarn()
{
var popupmsg='To access the webcast, please make sure you disable any \
popup-blocking software, or configure it to allow popups from this web site.\n\n\
This step is necessary to access the webcast.\n\nFor further instructions, click the link \
in the Note near the top of the page.';
if (confirm(popupmsg)==true) {return true;} else {return false;}
// alert(popupmsg);
}



// This function is used when items 2 and 3 are display:inline
function Toggle(item1,item2,item3) {
obj1=document.getElementById(item1);
if (obj1.style.display=="block")	{ obj1.style.display="none";  }
else								{ obj1.style.display="block"; }

if (item2) {
obj2=document.getElementById(item2);
if (obj2.style.display=="inline")	{ obj2.style.display="none";   }
else								{ obj2.style.display="inline"; }
}

if (item3) {
obj3=document.getElementById(item3);
if (obj3.style.display=="inline")	{ obj3.style.display="none";   }
else								{ obj3.style.display="inline"; }
}
}

// This function is used when items 2 and 3 are display:block
function ToggleB(item1,item2,item3) {
obj1=document.getElementById(item1);
if (obj1.style.display=="block")	{ obj1.style.display="none";  }
else								{ obj1.style.display="block"; }

if (item2) {
obj2=document.getElementById(item2);
if (obj2.style.display=="block")	{ obj2.style.display="none";   }
else								{ obj2.style.display="block"; }
}

if (item3) {
obj3=document.getElementById(item3);
if (obj3.style.display=="block")	{ obj3.style.display="none";   }
else								{ obj3.style.display="block"; }
}
}


//  This set of functions is for reading, writing, and removing cookies
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";	// no value means expires when browser is closed
	document.cookie = name+"="+value+expires+"; path=/;";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) var final = c.substring(nameEQ.length,c.length);
	}
	return final;
}

function eraseCookie(name) { createCookie(name,"",-1) }

// Displays user's IP address in an Alert Box.
function getIP() { alert(ip); }


function ConfirmLeaving(lang) {
if		(lang == 'en')	{ var msg = 'You are now leaving this web site and will be redirected to Zygo Corporation\'s main web site. '; }
else if (lang == 'cn')	{ var msg = '您正在离开ZygoLAMDA网站，现在将被引导到Zygo公司的网站。';		 }
else if (lang == 'tw')	{ var msg = '您正要離開Zygo Taiwan 的網頁 現在將被引導到 ZYGO 公司(英文)網頁。';		 }
else if (lang == 'de')	{ var msg = 'Sie (verlassen diese Seite und ) werden auf die Zygo Corporation Hauptseite umgeleitet.'; }
else if (lang == 'nm')	{ var msg = 'You are now leaving ZYGO\'s web site and will be redirected to the Nanometrics web site.'; }
else if (lang == 'th')	{ var msg = 'You are now leaving ZYGO\'s web site and will be redirected to the Toho Technology web site.'; }
else if (lang == 'twt')	{ var msg = 'You are now leaving the ZYGO web site and will be transferred to the Twitter web site. Please sign up to follow ZYGO tweets!'; }
else					{ var msg = 'Sie (verlassen diese Seite und ) werden auf die Zygo Corporation Hauptseite umgeleitet.'; }

if (confirm(msg)) { return true; }
else { return false; }
}	// end function ConfirmLeaving
