//This file contains miscellaneous javascript functions that are used everywhere.

function addfavorite() {
    favoriteurl="http://www.weddingguidechicago.com/"
    favoritetitle="Chicago Brides' Wedding Source"
    if (document.all) {
        window.external.AddFavorite(favoriteurl,favoritetitle)
    } else {
        alert("Sorry. Netscape/Mozilla users must bookmark the pages manually by hitting <Ctrl-D>.")
    } 
} 

// Function to change action of form based on the value of a radio button.
// Need to conditionally include this.  It only applies when op = preview in emailadmin
// The default action already specified as admin.php in the form definition.

function send_form(val){

    if(val == '1'){
        document.ps.action='progressbar.php';
    }

    if(val == '2'){
        document.ps.action='admin.php';
    }
    return true;

}

// Function to handle popup window.

function popup(mylink, windowname, width, height){
    var hrefs;
    if (typeof(mylink) == 'string')
        hrefs=mylink;
    else
        hrefs=mylink.href;
    newwindow = window.open(mylink, 'windowname', 'width='+width+',height='+height+',scrollbars=no,titlebar=no,top=100,left=100');
    if (window.focus) {newwindow.focus()}
        return true;
    }

// Function to play sound.

function playsound(soundfile){
   document.getElementById("soundeffect").src=soundfile;
}

// Cookie handling functions (wash your hands first!!)

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,expiredays)
{var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie()
{
username=getCookie('username');
if (username!=null && username!="")
  {
  alert('Welcome again '+username+'!');
  }
  else 
  {
  username=prompt('Please enter your name:',"");
  if (username!=null && username!="")
    {
    setCookie('username',username,365);
    }
  }
}

// email address verification

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail ID")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail ID")
            return false
         }
        
         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID")
            return false
         }

          return true                    
    }

function ValidateEmail(){
    var emailID=document.subscribe.email
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }
    if (echeck(emailID.value)==false){
        //emailID.value=""
        emailID.focus()
        return false
    }
    return true
 }
