function onImgError(source, default_img) {
	source.src = default_img; 
	// disable onerror to prevent endless loop
	source.onerror = "";
	return true;
}
	
	function addFavorites(){
	if (document.all) {
		window.external.AddFavorite( location.href, document.title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(document.title, location.href, "")
	}
}

function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(location.href);
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
		 {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         }  
         catch(e)  
         {  
			alert("this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");  
         }
    } 
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',location.href);
 }
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function isArray(obj) {
	if (obj == null) return false;
	return obj.constructor == Array;
}

function FBLogin(message, title, description, images, link, usermessageprompt) {
	FB.login(function(response) {
		if (response.session) {
			// user successfully logged in
			shareonFacebook(message, title, description, images, link, usermessageprompt);
		} else {
			// user cancelled login
		}
	});
	
}	
	
function shareonFacebook(message, title, description, images, link, usermessageprompt) {
	var ls_media = new Array();
	if (isArray(images)) {
		for (i=0; i<images.length; i++) ls_media[i] = {type: 'image', src: images[i], href: link};
	} else	
		ls_media[0] = {type: 'image', src: images, href: link};
	
	//alert(FB.getLoginStatus()); // + " - " + FB.getSession() );
	if (!FB.getLoginStatus() && navigator.appName.indexOf("Internet Explorer") >= 0 && false) {
		FBLogin(message, title, description, images, link, usermessageprompt);
	} else {
	FB.ui(
   {
     method: 'stream.publish',
	 display: 'popup', //'iframe', //
     message: message,
     attachment: {
       name: title,
       description: description,
       media: ls_media,
       href: link
     },
     action_links: [
	   { text: 'Get our app!', href: 'http://apps.facebook.com/horoscope-com/'}
     ],
     user_message_prompt: usermessageprompt
   }/*,
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.' + response);
     }
   }*/

 );
 }
}

function showFBbutton() {
	if (document.getElementById("fb-root") &&
		document.getElementById("facebook") && 
		document.getElementById("fb-root").innerHTML != "") document.getElementById("facebook").style.display = "inline";
}

function tweet(tweeturl, text) {
    url = "http://twitter.com/share?url=" + tweeturl + "&text=" + text;
    window.open(url,"socialBookmark",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=1,width=500,height=300');
}

function getDocHeight() {
	var D = document;
	return Math.max(
		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
		Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
		Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}
	
function getDocWidth() {
	var D = document;
	return Math.max(
		Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
		Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
		Math.max(D.body.clientWidth, D.documentElement.clientWidth)
	);
}

function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function displayGAMAd(aSlotID) {
    aDivName = "ActualAd_" + aSlotID;
    aSlotName = "AdSlot_" + aSlotID;
	if (document.getElementById(aSlotName)) {	
		document.getElementById(aDivName).style.display = "block";
		document.getElementById(aSlotName).style.height = document.getElementById(aDivName).offsetHeight;
	}
}

function positionGAMAd(aSlotID) {
    aDivName = "ActualAd_" + aSlotID;
    aSlotName = "AdSlot_" + aSlotID;
	if (document.getElementById(aSlotName)) {	
		document.getElementById(aDivName).style.top = 0 - getY(document.getElementById(aDivName)) + getY(document.getElementById(aSlotName));
		document.getElementById(aDivName).style.left = 0 - getX(document.getElementById(aDivName)) + getX(document.getElementById(aSlotName));
	}
}

function repositionGAMAd(aSlotID) {
    aDivName = "ActualAd_" + aSlotID;
    aSlotName = "AdSlot_" + aSlotID;
	if (document.getElementById(aDivName).style.display == "block") { 
		if ( navigator.appName.indexOf("Internet Explorer") >= 0) 
		 	document.getElementById(aDivName).style.left = (0 - document.body.clientWidth/2) + (document.getElementById(aSlotName).offsetWidth /2) + getX(document.getElementById(aSlotName));
		else
			document.getElementById(aDivName).style.left = getX(document.getElementById(aSlotName));
		
	}
}

function callGAMScript(aSlotName) {
    if (document.getElementById("AdSlot_" + aSlotName)) window["callGAMscript_" + aSlotName]();
}

function EcrireCookieLanguage(nom, valeur) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+10000);
  var aDomain = document.domain;
  var mySplitResult = aDomain.split(".");
  aDomain = "." + mySplitResult[mySplitResult.length -2] + "." + mySplitResult[mySplitResult.length -1];
  var path = "/";
  document.cookie = nom + "=" + escape(valeur) + "; expires=" + exdate.toGMTString() + "; path=" + path + "; domain=" + aDomain;
}

function DrapeauClick() {
  aCookieVal = 1;
  if (aSiteLanguage == 0) aCookieVal = 1;
  if (aSiteLanguage == 1) aCookieVal = 0;
  EcrireCookieLanguage(aCookieName, aCookieVal);
  return true;
}

function roll_over(img_name, img_src)
   {
   document[img_name].src = img_src;
   }
   
 function Meebo_addButtons() {
	Meebo("addButton", {
		id: "button_subscribe",
		label: "Horoscope by E-mail",
		type: "widget",
		icon: "http://horoscope.com/favicon.ico",
		width: 765,
		height: 550,
		iframe: "/horoscope/SubscriptionForm-meebo.aspx"
	});

	Meebo('addButton', {
		id: "button_8ball", 
		type: "action", 
		icon: "http://horoscope.com/favicon.ico",
		label: "Ask the Magic Ball", 
		onClick: function(){ document.location = "http://www.horoscope.com/horoscope/genie/magic8ball.aspx"; } 
	});

	Meebo('addButton', {
		id: "button_love", 
		type: "action", 
		icon: "http://horoscope.com/favicon.ico",
		label: "Love Horoscope", 
		onClick: function(){ document.location = "http://love.horoscope.com"; } 
	});

	Meebo('addButton', {
		id: "button_tarot", 
		type: "action", 
		icon: "http://horoscope.com/favicon.ico",
		label: "Free Tarot Reading", 
		onClick: function(){ document.location = "http://tarot.horoscope.com/free-daily-tarot-reading.html"; } 
	});
}

//By Sandeep Gangadharan (http://web1.mtnl.net.in/~sivam/jspage.html)
//Modified by Andy Koswara (Horoscope.com, Inc.)
//For this script and more, visit http://javascriptkit.com
function sunsignFinder(aMonth, aDay) {
	aReturnValue = "invalid birthday";
	
	if (aDay > 31 || aDay < 1) return aReturnValue;
	if (aMonth == 2 && aDay > 29) return aReturnValue;
    if (aMonth == 4 && aDay > 30) return aReturnValue;
    if (aMonth == 6 && aDay > 30) return aReturnValue;
    if (aMonth == 9 && aDay > 30) return aReturnValue;
    if (aMonth == 11 && aDay > 30)return aReturnValue;
	
	if (aMonth == 1 && aDay <=19) {aReturnValue = "CAPRICORN";}
	if (aMonth == 1 && aDay >=20) {aReturnValue = "AQUARIUS";}
	if (aMonth == 2 && aDay <=18) {aReturnValue = "AQUARIUS";}
	if (aMonth == 2 && aDay >=19) {aReturnValue = "PISCES";}
	if (aMonth == 3 && aDay <=20) {aReturnValue = "PISCES";}
	if (aMonth == 3 && aDay >=21) {aReturnValue = "ARIES";}
	if (aMonth == 4 && aDay <=19) {aReturnValue = "ARIES";}
	if (aMonth == 4 && aDay >=20) {aReturnValue = "TAURUS";}
	if (aMonth == 5 && aDay <=20) {aReturnValue = "TAURUS";}
	if (aMonth == 5 && aDay >=21) {aReturnValue = "GEMINI";}
	if (aMonth == 6 && aDay <=22) {aReturnValue = "GEMINI";}
	if (aMonth == 6 && aDay >=21) {aReturnValue = "CANCER";}
	if (aMonth == 7 && aDay <=22) {aReturnValue = "CANCER";}
	if (aMonth == 7 && aDay >=23) {aReturnValue = "LEO";}
	if (aMonth == 8 && aDay <=22) {aReturnValue = "LEO";}
	if (aMonth == 8 && aDay >=23) {aReturnValue = "VIRGO";}
	if (aMonth == 9 && aDay <=22) {aReturnValue = "VIRGO";}
	if (aMonth == 9 && aDay >=23) {aReturnValue = "LIBRA";}
	if (aMonth == 10 && aDay <=22) {aReturnValue = "LIBRA";}
	if (aMonth == 10 && aDay >=23) {aReturnValue = "SCORPIO";}
	if (aMonth == 11 && aDay <=21) {aReturnValue = "SCORPIO";}
	if (aMonth == 11 && aDay >=22) {aReturnValue = "SAGITTARIUS";}
	if (aMonth == 12 && aDay <=21) {aReturnValue = "SAGITTARIUS";}
	if (aMonth == 12 && aDay >=22) {aReturnValue = "CAPRICORN";}

	return aReturnValue;
}

function EmailIsValid(emailValue) {
	//var emailAdressRegExp =  /^[a-z0-9_\.\-]+\@(?:[0-9a-z][a-z0-9\-]+\.)+[a-z]{2,4}$/i; //stricter version
	var emailAdressRegExp = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

	if(!emailAdressRegExp.test(emailValue))
		return false;
	else 
		return true;
}

function submitQuiz(theform, numberOfQuestions, questionID) {
    var answerComplete = true;
    var singleAnswerComplete = false;
    var radioButtonForm;
    var totalvalue = 0;

    for (i = 1; i <= numberOfQuestions; i++) {
        radioButtonForm = eval(questionID + i);
        singleAnswerComplete = false;
        for (j = 0; j < radioButtonForm.length; j++) {
            if (radioButtonForm[j].checked) {
                //alert(radioButtonForm[j].value);
                totalvalue = totalvalue + parseInt(radioButtonForm[j].value);
                singleAnswerComplete = true;
                j = radioButtonForm.length;
            }
        }

        if (!singleAnswerComplete) {
            alert("Please answer all questions");
            answerComplete = false;
            i = numberOfQuestions + 1;
        }
    }

    if (answerComplete) {
        //alert(totalvalue);
        theform.val.value = totalvalue;
        theform.submit();
    }
}

function IsNumeric(input) {
    return (input - 0) == input && input.length > 0;
}

/*  MOD  --  Modulus function which works for non-integers.  */
function mod(a, b) {
    return a - (b * Math.floor(a / b));
}

//  AMOD  --  Modulus function which returns numerator if modulus is zero
function amod(a, b) {
    return mod(a - 1, b) + 1;
}
