//JavaScript Code produced by Arkeo, Inc. http://www.arkeo.com
//Copyright 2004, All Rights Reserved

//Pop-up Window Code (centered on screen)
function CenteredWindow(dest, windowName, w, h, scrollbars,resizable,toolbars,location) {
	var winl = ((screen.width - w) / 2) - 10;
	var wint = ((screen.height - h) / 2) - 25;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbars+',resizable='+resizable+',toolbars='+toolbars+',location='+location;
	theWindow = window.open(dest, windowName, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		theWindow.window.focus();
	}
}

//Stylesheet Switcher Code
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
    createCookie("style", title, 365);
}


function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
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 expires = "";
  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) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

window.onload = function(e) {
	if (document.getElementById) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
	}
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

// Patanol.com Form Validation
function validateForm(theForm)
{
    if (theForm.FirstName.value == "") 
		{
	    	alert("Please provide your first name.");
    		theForm.FirstName.focus();
        	return false; 
		} 
    if (theForm.LastName.value == "")  
		{
	    	alert("Please provide your last name.");
    		theForm.LastName.focus();
        	return false; 
		} 
    if (theForm.Address.value == "")  
		{
	    	alert("Please provide your address.");
    		theForm.Address.focus();
        	return false; 
		} 
    if (theForm.City.value == "")  
		{
	    	alert("Please provide your city.");
    		theForm.City.focus();
        	return false; 
		} 
    if (theForm.State.value == "")  
		{
	    	alert("Please select your State from the list.");
    		theForm.State.focus();
        	return false; 
		} 
	var InString = theForm.PostalCode.value
	if (InString.length==0) 
		{
	    	alert("Please provide your ZIP Code.");
    		theForm.PostalCode.focus();
			return (false);
		}
	if ((InString.length!=5) && (InString.length!=10))
		{
	    	alert("Please provide a valid ZIP Code.");
    		theForm.PostalCode.focus();
			return (false);
		}
	RefString="1234567890-";
	for (Count=0; Count < InString.length; Count++)  
		{
			TempChar= InString.substring (Count, Count+1);
			if (RefString.indexOf (TempChar, 0)==-1) 
				{
	    			alert("Please provide a valid ZIP Code.");
    				theForm.PostalCode.focus();
					return false; 
				}
		}
			
		if((theForm.patanolPhone != null && theForm.patanolPhone.checked == true) || theForm.phoneRequired != null)
			{	
				var strMessage = "";
				if (theForm.patanolPhone != null && theForm.patanolPhone.checked == true)  
					{
						strMessage = "Thank you for signing up to receive communications via phone.  ";
					}
				var AreaCodeString = theForm.AreaCode.value;
				if (AreaCodeString.length==0) 
					{
						strMessage += "Please enter your area code.";
						alert(strMessage);
						theForm.AreaCode.focus();
						return (false);
					}
				if (AreaCodeString.length<3)
					{
						strMessage += "Please provide a valid area code.";
						alert(strMessage);
						theForm.AreaCode.focus();
						return (false);
					}
				RefString="1234567890-";
				for (Count=0; Count < AreaCodeString.length; Count++)  
					{
						TempChar= AreaCodeString.substring (Count, Count+1);
						if (RefString.indexOf (TempChar, 0)==-1) 
							{
								strMessage += "Please provide a valid area code.";
								alert(strMessage);
								theForm.AreaCode.focus();
								return false; 
							}
					}
				var Phone1String = theForm.Phone1.value
				if (Phone1String.length==0) 
					{
						strMessage += "Please enter your phone number.";
						alert(strMessage);
						theForm.Phone1.focus();
						return (false);
					}
				if (Phone1String.length<3)
					{
						strMessage += "Please provide a valid phone number.";
						alert(strMessage);
						theForm.Phone1.focus();
						return (false);
					}
				RefString="1234567890-";
				for (Count=0; Count < Phone1String.length; Count++)  
					{
						TempChar= Phone1String.substring (Count, Count+1);
						if (RefString.indexOf (TempChar, 0)==-1) 
							{
								strMessage += "Please provide a valid phone number.";
								alert(strMessage);
								theForm.Phone1.focus();
								return false; 
							}
					}	
				var Phone2String = theForm.Phone2.value
				if (Phone2String.length==0) 
					{
						strMessage += "Please enter your phone number.";
						alert(strMessage);
						theForm.Phone2.focus();
						return (false);
					}
				if (Phone2String.length<4)
					{
						strMessage += "Please provide a valid phone number.";
						alert(strMessage);
						theForm.Phone2.focus();
						return (false);
					}
				RefString="1234567890-";
				for (Count=0; Count < Phone2String.length; Count++)  
					{
						TempChar= Phone2String.substring (Count, Count+1);
						if (RefString.indexOf (TempChar, 0)==-1) 
							{
								strMessage += "Please provide a valid phone number.";
								alert(strMessage);
								theForm.Phone2.focus();
								return false; 
							}
					}		
			}

		if (theForm.patanolEmail != null)
			{
				Ctrl = theForm.Email;
				if (theForm.patanolEmail != null && theForm.patanolEmail.checked == true) 
					{
						var strMessage = "Thank you for signing up to receive communications via email. ";
					}
				
				if (Ctrl.value == "" )
					{
						if (strMessage != null)
							{
								strMessage += "Please enter your email address.";
							}
						else
							{
								var strMessage = "Please enter your email address.";
							}
						alert(strMessage);
						Ctrl.focus();
						return false; 
					}
				
				// check validity of email
				var validEmail = checkEmail(Ctrl);
				
				if (!validEmail)
				{
					alert("Please enter a valid email address.");
					Ctrl.focus();
					return false;
				} 				
					
			}

				Ctrl = theForm.Email;				
				if (Ctrl.value == "" )
					{
						if (strMessage != null)
							{
								strMessage += "Please enter your email address.";
							}
						else
							{
								var strMessage = "Please enter your email address.";
							}
						alert(strMessage);
						Ctrl.focus();
						return false; 
					}
				
				// check validity of email
				var validEmail = checkEmail(Ctrl);
				
				if (!validEmail)
				{
					alert("Please enter a valid email address.");
					Ctrl.focus();
					return false;
				} 				
					



	if (theForm.genderRequired != null)
		{
			var genderChoice1 = eval("theForm.Gender[0].checked");
			var genderChoice2  = eval("theForm.Gender[1].checked");
			if (genderChoice1 == genderChoice2) 
				{
	    			alert("Please select the appropriate option to indicate your gender.");
		        	return false; 
				} 
		}

	if (theForm.ageRequired != null) 
		{
			if (theForm.Age.value == "")  
				{
					alert("Please select your age range from the list.");
					theForm.Age.focus();
					return false; 
				} 
		}
/*
	var Choice1 = eval("theForm.haveyou[0].checked");
	var Choice2  = eval("theForm.haveyou[1].checked");
	if (Choice1 == Choice2)
 	  	{
			alert("Please let us know if you have purchased PATANOL(R) in the past.");
	  		return (false);
  		}
	
	if (theForm.commentRequired != null)
		{
			if (theForm.message.value == "")  
				{
					alert("Please select type your question, comment or message.");
					theForm.message.focus();
					return false; 
				} 
		}

	if (theForm.visitorTypeRequired != null)
		{
			var visitorType1 = eval("theForm.occupation[0].checked");
			var visitorType2  = eval("theForm.occupation[1].checked");

			if (visitorType1 == visitorType2) 
				{
	    			alert("Please select the appropriate option to indicate whether you are a consumer or medical professional.");
				
		        	return false; 
				} 
		}
*/
    return true;
} 
function checkEmail(email)  		
			{
				var goodEmail = email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
				if (goodEmail)
			    {
					 return true;
				} 
				else
				{
					return false;
				}		
			}

//Coupon Popup Window
function couponPopup() {
	CenteredWindow('/about-patanol/rebate-coupon.asp', 'rebateCoupon', 610, 445, 'yes','yes','no','no');
}

function isBlank (Ctrl) {
	var InString = " ";
	if ((Ctrl.value == "undefined") || (Ctrl.value == "")) return (!false);
	InString = Ctrl.value;
	InString = spaceTrim(InString);
/*	if (InString==null) return (!false) */
		if (InString.length!=0) {
			return true;     }
		else {
			return false;
			 }
}

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
