function SwitchClass(sElementID,sClassName) {
   var sElement = document.getElementById(sElementID);  
   if (sElement.className != sClassName) sElement.className = sClassName;
}

/* Show/Hide divs onClick */
function ExpandCollapse(vPostid) { 
   var vWhichpost = document.getElementById(vPostid);  
   if (vWhichpost.className=="postshown") { 
      vWhichpost.className="posthidden"; 
   } 
   else { 
      vWhichpost.className="postshown"; 
   } 
}

function ShowHideBlock(sBlockId,sBlockLink,sShowText,sHideText) {
	var sWhichLink = document.getElementById(sBlockLink);
	var sWhichBlock = document.getElementById(sBlockId);  
	if (sWhichBlock.className == "block") { 
		sWhichBlock.className = "none";
		(sShowText) ? sWhichLink.innerHTML = sShowText : sWhichLink.innerHTML = "Show";
	} 
	else { 
		sWhichBlock.className = "block";
		(sHideText) ? sWhichLink.innerHTML  = sHideText : sWhichLink.innerHTML  = "Hide";
   } 
}

/* Toggle div Visibility */
function toggleDiv(divid){
	var div = document.getElementById(divid);
	div.style.display = div.style.display == 'block' ? 'none' : 'block';
}

/* Load Link in Parent */
function loadinparent(url, closeSelf){
	self.opener.exit=false;
	self.opener.location = url;
	if(closeSelf) self.close();
}

/* PopUp */
function Popup(page,width,height,scroll,location,statusbar,menubar,resizable) {
	var now = new Date();
	var hour        = now.getHours();
	var minute      = now.getMinutes();
	var second      = now.getSeconds();
	
	if (!scroll) { scroll = 'no'; }
	if (!location) { location = 'no'; }
	if (!statusbar) { statusbar = 'no'; }
	if (!menubar) { menubar = 'no'; }
	if (!resizable) { resizable = 'no'; }
	var name = "popup";
	/*var name = hour +''+ minute +''+ second;*/
	window.open(''+ page +'',name,'toolbar=0,scrollbars='+ scroll +',location='+ location +',statusbar='+ statusbar +',menubar='+ menubar +',resizable='+ resizable +',width='+ width +',height='+ height);
}

/* Legacy PopUp */
var newwin;

function launchwin(winurl,winname,winfeatures) {
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	newwin = window.open(winurl,winname,winfeatures);
	if(javascript_version > 1.0)
	{
		//delay a bit here because IE4 encounters errors
		//when trying to focus a recently opened window
 		setTimeout('newwin.focus();',250);
	}
}

/* Another Legacy PopUp */
function parseNavigation(ob) { // created by joe crawford october 2002
	toBeBrokenDown = ob.options[ob.selectedIndex].value.split("|");

	targetWindow = toBeBrokenDown[0];
	targetURL    = toBeBrokenDown[1];

    if (targetWindow!=='') {
    // if a new Window name is specified, then it will
    // open in a new Window.
    window.open(targetURL,targetWindow,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=425,height=500');
    // if we open a new window, then we have to re-set
    // the select box to the first option
    // which should have no value
    ob.selectedIndex = 0;
        } else {
    // or else it will open in the current window        
    window.open(targetURL,'_top')
    }
}

/* Another Legacy Popup, go figure...*/
var windowHandle = '';

function go(what) {
    windowHandle = window.open(what[what.selectedIndex].value,'windowName','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=640,height=480');
}

/* PopUp Audio Player */
// Pop-Up Embedder Script by David Battino, www.batmosphere.com
// Version 2006-05-31  
// OK to use if this notice is included
function BatmoAudioPop(filedesc,filepath,WindowNumber) {

	// Get Operating System 
	var isWin = navigator.userAgent.toLowerCase().indexOf("windows") != -1
	if (isWin) {
	    // Use MIME type = "application/x-mplayer2";
		visitorOS="Windows";
	} else {
	    // Use MIME type = "audio/mpeg"; // or audio/x-wav or audio/x-ms-wma, etc.
		visitorOS="Other";
	}

	// Get the MIME type of the audio file from its extension (for non-Windows browsers)
	var mimeType = "audio/mpeg"; // assume MP3/M3U
	var objTypeTag = "application/x-mplayer2"; // The Windows MIME type to load the WMP plug-in in Firefox, etc.

	var theExtension = filepath.substr(filepath.lastIndexOf('.')+1, 3); // truncates .aiff to aif
	if (theExtension.toLowerCase() == "wav") { mimeType = "audio/x-wav"};
	if (theExtension.toLowerCase() == "aif") { mimeType = "audio/x-aiff"}; 
	if (theExtension.toLowerCase() == "wma") { mimeType = "audio/x-ms-wma"};
	if (theExtension.toLowerCase() == "mid") { mimeType = "audio/mid"};
	// Add additional MIME types as desired
	if (visitorOS != "Windows") { 
		objTypeTag = mimeType; // audio/mpeg, audio/x-wav, audio/x-ms-wma, etc.
	};

    PlayerWin = window.open('',WindowNumber,'width=300,height=178,top=0,left=0,screenX=0,screenY=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0');
    PlayerWin.focus();
    PlayerWin.document.writeln("<html><head><title>" + filedesc + "</title></head>");
    PlayerWin.document.writeln("<body style='background:#e5dac1'>"); // specify background img if desired
    PlayerWin.document.writeln("<div align='center'>");
    PlayerWin.document.writeln("<h2 style='padding:0 0 10px 0; margin:0; font:bold 18px/22px Times New Roman,Serif; color:#01515d; text-transform:capitalize; text-align:left;'>Radio</h2>");
    PlayerWin.document.writeln("<object width='280' height='69'>");
    PlayerWin.document.writeln("<param name='src' value='" +  filepath + "'>");
    PlayerWin.document.writeln("<param name='type' value='" + objTypeTag + "'>");
    PlayerWin.document.writeln("<param name='autostart' value='1'>");
    PlayerWin.document.writeln("<param name='showcontrols' value='1'>"); 
    PlayerWin.document.writeln("<param name='showstatusbar' value='1'>");
    PlayerWin.document.writeln("<embed src ='" + filepath + "' type='" + objTypeTag + "' autoplay='true' width='280' height='69' controller='1' showstatusbar='1' bgcolor='#e5dac1' kioskmode='true'>");
    PlayerWin.document.writeln("</embed></object></div>");
    PlayerWin.document.writeln("<p style='padding:0; margin:10px 0; font:normal 12px/16px Arial,Verdana,Sans-Serif; color:#5c503a;'><a href='" + filepath +"' style='color:#06515b;'>Download this file</a> (right-click or Control-click).</p>");
    PlayerWin.document.writeln("<p style='padding:0; margin:0; font:normal 12px/16px Arial,Verdana,Sans-Serif; color:#293859; text-align:center;'><a href='javascript:window.close();' style='color:#06515b;'>Close This Window</a></p>");
    PlayerWin.document.writeln("</body></html>");

    PlayerWin.document.close(); // "Finalizes" new window
}

/* Legacy Referrer */
function referer() {
        window.open("customer/referer_mail.php", "referer", "width=500,height=450,toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,location=no,direction=no");
}

// Set by onClick for each radio button - stores URL
var new_url="";
// Called by Add to cart button - loads selected page.
function leapTo()
{
if ( (new_url != "") && (new_url != null) )
window.location=new_url;
else
alert("\nPlease select your shade.");
}

/*
  -------------------------------------------------------------------------
	                    JavaScript Form Validator 
                                Version 2.0.2
	Copyright 2003 JavaScript-coder.com. All rights reserved.
	You use this script in your Web pages, provided these opening credit
    lines are kept intact.
	The Form validation script is distributed free from JavaScript-Coder.com

	You may please add a link to JavaScript-Coder.com, 
	making it easy for others to find this script.
	Checkout the Give a link and Get a link page:
	http://www.javascript-coder.com/links/how-to-link.php

    You may not reprint or redistribute this code without permission from 
    JavaScript-Coder.com.
	
	JavaScript Coder
	It precisely codes what you imagine!
	Grab your copy here:
		http://www.javascript-coder.com/
    -------------------------------------------------------------------------  
*/
function Validator(frmname)
{
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}

function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}

function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}

function form_submit_handler()
{
	for(var itr=0;itr < this.elements.length;itr++)
	{
		if(this.elements[itr].validationset &&
	   !this.elements[itr].validationset.validate())
		{
		  return false;
		}
	}
	if(this.addnlvalidation)
	{
	  str =" var ret = "+this.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
}

function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
	{
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
  if(!itemobj)
	{
	  alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}

function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}

function vdesc_validate()
{
 if(!V2validateData(this.desc,this.itemobj,this.error))
 {
    this.itemobj.focus();
		return false;
 }
 return true;
}

function ValidationSet(inputitem)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}

function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]= 
	  new ValidationDesc(this.itemobj,desc,error);
}

function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}

function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function V2validateData(strValidateStr,objValue,strError) 
{ 
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
    switch(command) 
    { 
        case "req": 
        case "required": 
         { 
           if(eval(objValue.value.length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              alert(strError); 
              return false; 
           }//if 
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
             }//if 
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break;               
           }//numeric 
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alphabetic characters allowed "; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//alpha 
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
			break;
			}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid Email address "; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
		 	if(objValue.value.length > 0)
			{
	            if(!objValue.value.match(cmdvalue)) 
	            { 
	              if(!strError || strError.length ==0) 
	              { 
	                strError = objValue.name+": Invalid characters found "; 
	              }//if                                                               
	              alert(strError); 
	              return false;                   
	            }//if 
			}
           break; 
         }//case regexp 
        case "dontselect": 
         { 
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 
            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
              strError = objValue.name+": Please Select one option "; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case dontselect 
    }//switch 
    return true; 
}
/*
	Copyright 2003 JavaScript-coder.com. All rights reserved.
*/

function DoSubmit()
{
  var strErrorMessage = "*** ERRORS ***\n\n";
  var bValidValues = true;
  var oForm = document.forms['frmData'];
  if ( Trim( oForm.elements['txtFullName'].value ) == "" )
  {
    strErrorMessage += "* Field Full Name cannot be empty.\n";
    bValidValues = false;
  }
  if ( Trim( oForm.elements['txtEmail'].value ) == "" ){
    strErrorMessage += "* Field Email cannot be empty.\n";
    bValidValues = false;
  } else {
    if ( !isEmail( Trim( oForm.elements['txtEmail'].value ) ) )
    {
      strErrorMessage += "* Field Email is mandatory and must be valid.\n";
      bValidValues = false;
    }
  }
  if ( Trim( oForm.elements['txtZip'].value ) == "" )
  {
    strErrorMessage += "* Field Zip code cannot be empty.\n";
    bValidValues = false;
  } else {
    strZip = Trim ( oForm.elements['txtZip'].value )
    if ( !IsAlphaNumeric( strZip ) || strZip.length < 5 || strZip.length > 6 )
    {
      strErrorMessage += "* Field Zip code has to be from 5 (for USA) or 6 (CAN) chars.\n";
      bValidValues = false;
    }
  }
  if ( bValidValues )
  {
    oForm.elements['hidOpType'].value = "save";
    oForm.submit();
  }
  else
  {
    alert( strErrorMessage );
  }  
}

function popNews()
{
	var winl = 320;
	var wint = 310;
	var centerX=(screen.width-winl)/2;  
	var centerY=(screen.height-wint)/2; 
	var wndPopup=  window.open("news_pop_10x.asp", "Newsletter", "toolbar=no,menubar=no,location=no,resizable=yes,status=no,scrollbars=no,width=" + winl+ ",height=" +wint +"top="+centerY+",screenY="+centerY+",left="+centerX+",screenX="+centerX);
	wndPopup.focus();
}

function tell_friend2( sURL, sUID ){
	var path_to_cgi="http://www.tell-a-friend-wizard.com/cgi-bin/tell_opt_new2.cgi?uid=" + sUID + "&url=";
	path_to_cgi += '&reffer='+ sURL;// + escape('<%=GetScriptName()%>');
	window.open(path_to_cgi,"FRIENDS01","STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=YES,TOP=40,LEFT=20,WIDTH=325,HEIGHT=460");
}
