﻿//<!-----------Start of Browser independent Popup Script-------------->

var hWnd
function PopupWindow( passurl , height, width) {
        
		var x = screen.availWidth/2 - 200;
		var y = 150;
		
		
        enterCalled = true
        window.name = "parent"
        var url = passurl
        if( !hWnd ) {
        //if no help window is open then open a new help window and give it focus
        hWnd = window.open(url,"popup","width=" + width + ",height=" + height +", left=" + x + ", top=" + y + ", resizable=yes,scrollbars=yes")
        hWnd.focus()
        } else if ( hWnd.closed ) {
        //if no help window is open then open a new help window and give it focus
        hWnd = window.open(url,"popup","width=" + width + ",height=" + height +", left=" + x + ", top=" + y + ", resizable=yes,scrollbars=yes")
        hWnd.focus()
        } else {
        //if the help window is already open then update it and give it focus
        hWnd.location=url
        hWnd.focus()
        }
        // handle Navigator 2, which doesn't have an opener property
        if (!hWnd.opener) { hWnd.opener = window}
}

//<!-----------End of Browser independent Popup Script-------------->

//NEWSLETTER
function submitForm() {
    //alert('sadf');
    var email = document.forms.namedItem("subscribe");

    if (!this.EmailCheck(email)) {
        return false;
    }
    url = "http://www.americheer.com/user/subscription1.php?newsemail=" + email.value + "";
    //window.alert('1');
    PopupWindow(url, 100, 320);
    //window.alert('2');
    email.value = "Enter Email Here";
    return false;
}


function EmailCheck(email) {

    if (email.value == '' || email.value == 'Enter Email') {
        alert("Enter Email Address");
        email.focus();
        return false;
    }

    if (!isValidEmail(email.value)) {
        alert('Enter valid Email Address');
        email.focus();
        return false;
    }

    return true;
}



function isValidEmail(strEmail) {
    var atIndex = strEmail.indexOf('@');
    var dotIndex = strEmail.lastIndexOf('.');
    if (atIndex == -1 || dotIndex == -1 || atIndex > dotIndex)
        return false;

    var str1 = strEmail.substr(0, atIndex);
    var str2 = strEmail.substring(atIndex + 1, dotIndex);
    var str3 = strEmail.substr(dotIndex + 1);

    if (!isValidEmail1(str1))
        return false;

    if (!isValidEmail1(str2))
        return false;

    if (!isValidEmail1(str3))
        return false;

    return true;
}

function isValidEmail1(str) {
    if (str == '')
        return false;
    var dotIndex = str.lastIndexOf('.')
    if (dotIndex != -1) {
        var str1 = str.substr(0, dotIndex);
        var str2 = str.substr(dotIndex + 1);

        if (!isValidEmail1(str1))
            return false;

        if (!isValidEmail1(str2))
            return false;
    }
    else {
        var strValidCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-';
        for (var a = 0; a < str.length; a++)
            if (strValidCharacters.indexOf(str.charAt(a)) == -1)
            return false;
    }
    return true;
}

function isCharsInBag(s, bag) {
    var i;
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++) {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return (false);
    }
    return true;
}



//<!------------- Starts of Favourites Script ------>
function addFavour()
{
//alert(top.location.href);
//return;

if( window.sidebar && window.sidebar.addPanel ) {
    //Gecko (Netscape 6 etc.) - add to Sidebar
	window.sidebar.addPanel( top.document.title,top.location.href, '' );
} else if( window.external && ( navigator.platform == 'Win32' ||
      ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
    window.external.AddFavorite( top.location.href,top.document.title);
} else if( window.opera && window.print ) {
    return true;
} else if( document.layers ) {
    window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
} else {
    window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
}
return false;

}

function addBookmark()
{
	var sTitle = top.document.title;
	var sURL = top.location.href;
	
	if (window.sidebar)
	{ 
		window.sidebar.addPanel(sTitle, sURL, ""); 
	}
	else if( document.all )
	{
		window.external.AddFavorite(sURL, sTitle);
	}
	else if( window.opera && window.print )
	{
		return true;
	}
}

//<!------------- Ends of Favourites Script ------>
