// JavaScript Document
// nav scripts
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
// preload images
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// popup window
function openWin(url,w,h,s,r) {
    var scrl; 
    var resze;
    
    if (s) { scrl="scrollbars=yes,"; w = w+16;} 
    else { scrl="scrollbars=no,"; }
    
    if (r) { resze = "resizable=yes,"; }
    else { resze="resizable=no,"; }
    
    if (!w) w = 350;
    if (!h) h = 270;
    stock = window.open(url,"_blank",scrl+resze+"width="+w+",height="+h+",screenX=200,screenY=50");
    stock.focus();
}

//function openWin(pg,h,w) {
//	popWindow = window.open(pg,'popWin','height=h,width=w,toolbar=no,scrollbars=no');
//	popWindow.focus();
//}
//function openParent(pg) {
//	window.opener.location = pg;
//	window.opener.focus();
//}

// Validation functions ******************
function radioCheck(obj) {
	for(i=0;i<obj.length;i++) {
		if(obj[i].checked)
			return true;
	}
	return false;
}
function trimAll( strValue ) {
if(strValue=="") {return strValue;}
 var objRegExp = /\s/g;

    //check for all spaces
    if(objRegExp.test(strValue)) {
	
	while(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
	  }
    	if(!strValue.length == 0)
			return strValue;
    }
	
	//check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function isEmpty( strValue ) {
	if(strValue==""){return true;}
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return false;
   }  
   return true;
}
function validateUSZip( strValue ) {
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
  return objRegExp.test(strValue);
}
function validateAlpha( strValue,min ) {
	var objRegExp  = new RegExp("^[a-zA-Z]{"+min+",}$");
	return objRegExp.test(strValue);
}

function validateEmail( strValue) {
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	return objRegExp.test(strValue);
}

// Check that a Canadian postal code is valid
function isValidCanadianPostalcode(postalcode) {
if (!isEmpty(postalcode)) {
	postalcode = postalcode.replace(/ /g, "");
	if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
	else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1) return true;
	else return false;
}
return true;
}

function isUnderLimit(m,d,y) {
	with(document.forms[0]) {
		var ageLimit = 13;
		var year = parseInt(y)+ageLimit
		var bdate = m + "/" + d + "/" + year;
		var bdateObj = new Date(bdate);
		var bdateM = bdateObj.getTime();
		var today = new Date();
		var todayM = today.getTime();
		}	//	end with
		
	if((bdateM) > todayM)
		return true;
	return false;
}

function getNote(n) {
	var url = "sidenote.jsp?n=" + n;
	var noteWin = openwin(url,400,200);
}


//	Testimonials
var testify = new Array();
testify[0] = 'I simply have become a NIGHT &amp; DAY contact lens evangelist...';
testify[1] = 'These are the best contact lenses in the WORLD!';
testify[2] = 'I will never consider eye laser surgery for as long as I have these extraordinary contacts.';
testify[3] = 'I can see! I can see! No really, I can see everything, all the time...';
testify[4] = 'I\'m more impressed every day by the comfort and convenience of NIGHT &amp; DAY lenses...';

//	create random generator
var rdm = Math.round(Math.random()*(testify.length-1));
	
function getTestify() {
	//	write it out
	document.write(testify[rdm]);
}
function jumpToTestify() {
	location.href="/html/testimonials.shtml#t"+rdm
}



//	Set path to jsp pages
jspPath = 'o2optix/';

<!-- Method to jump to Free Trial Page -->
var freeTrialParam = "";
function jumpToFreeTrial(){  
  //document.URL = jspPath + "freeTrial.jsp";
  document.location = jspPath + "freeTrial.jsp";
}

<!-- Method to go to Home Page -->
function jumpToHome(){
  var contactUsPage = "index.shtml";
  document.location=contactUsPage;
}

<!-- Method to go to About Pages -->
function jumpToAbout(flag){
  if (flag == 'mo') { cuPage = "5xMoreO2.shtml"; }
  else if(flag == 'eh') { cuPage = "eyeHealth.shtml"; }
  else if(flag == 'co') { cuPage = "cornealO2Def.shtml"; }
  else { cuPage = "about.shtml"; }
  document.location=cuPage;
}

<!-- Method to go to Lens Care  Pages -->
function jumpToLensCare(flag){
  if (flag == 'am') { lcPage = "aquifyMPS.shtml"; }
  else if(flag == 'ad') { lcPage = "aquifyDrops.shtml"; }
  else if(flag == 'cc') { lcPage = "clearCare.shtml"; }
  else { lcPage = "lensCare.shtml"; }
  document.location=lcPage;
}

<!-- Method to go to Contact Us Page -->
function jumpToContactUs(){
  var contactUsPage = jspPath + "contactus.jsp";
  document.location=contactUsPage;
}

<!-- Method to go to Opt Out Page -->
function jumpToOptOut(){ 
  document.location = jspPath + "opt_out.jsp"; 
}

<!-- Method to go to Tell Us Your Story Page -->
function jumpToTellUs(){
  var tellUsPage = jspPath + "tellUs.jsp";
  document.location=tellUsPage;
}

<!-- Method to go to Tell Us Your Story Page -->
<!-- Note, this is initially set to the Tell us your story page until testimonials are collected for real users -->
function jumpToTestimonials(){
  var testimonialsPage = jspPath + "tellUs.jsp";
  document.location=testimonialsPage;
}

<!-- Method to go to Share With a Friend Page -->
function jumpToShare(){
  var sharePage = jspPath + "tellafriend.jsp";
  document.location=sharePage;
}

<!-- Method to go to one of InnerCircle Pages -->
function jumpToInnerCircle(flag){
  var icPage = ""
  if(flag == 'sweep'){
  	icPage = jspPath + "innercircle/sweep.jsp";
  }else if(flag == 'register'){
  	icPage = jspPath + "innercircle/register.jsp";
  }else if(flag == 'benefits'){
  	icPage = "/innercircle/benefits.shtml";
  }else if(flag == 'sweeps'){
  	icPage = jspPath + "innercircle/sweep.jsp";
  }else if(flag == 'profile'){
  	icPage = jspPath + "innercircle/update_profile.jsp";
  }else if(flag == 'login'){
  	icPage = jspPath + "innercircle/login.jsp";
  }else{
  	icPage = "/innercircle/";
  }
  document.location=icPage;
}

<!-- Method to go to Doc Locator Page -->
var prodName = "O2 Optix";
function jumpToDocLocator(){
  var docLocatorPage = "http://www.cibavision.com.au/product/main.asp?productid=32";
  var docWin = window.open(docLocatorPage,'O2Optix');
  docWin.focus();
  var docLocatorPage = "#";
  document.location=docLocatorPage;
}


<!-- To read cookie -->
function getCookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return "";
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

<!-- Determine InnerCircle Login State -->
function checkLogin() {
	if(getCookie('full_name')) {
		return "1";
	} else {
		return "0";
	}
}

// Global var to track Vicinity pop up windiw
var vicinityPopUp = null;

//-->
