﻿var req;

function getXMLHttpRequest() 
{
    if (window.XMLHttpRequest)     // Standard object
    { 
        req = new XMLHttpRequest();     // Firefox, Safari, ...
    } 
    else if (window.ActiveXObject)   // Internet Explorer 
    {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    } 
}

function sendRequest(url) {
	getXMLHttpRequest();
 
	req.open('GET', url , false);
	req.send();
	

}

function MaleMorphChange()
{
    var MorphID;
    
    MorphID = document.getElementById('malemorph').value;
     
    sendRequest('./MorphCalcAjax/Default.aspx?ID=' + MorphID);
    
    xmlDoc=req.responseText; 
    
   
    document.getElementById('maleoptions').innerHTML = xmlDoc;
}

 
function FemaleMorphChange()
{
    var MorphID;
    
    MorphID = document.getElementById('femalemorph').value;
     
    sendRequest('./MorphCalcAjax/Default.aspx?F=t&ID=' + MorphID);
    
    xmlDoc=req.responseText; 
    
 
    document.getElementById('femaleoptions').innerHTML = xmlDoc;
}

function MorphMe()
{
    var MyStr = 'a=a';
    
    for(i=0;i<document.forms[0].length;i++)
    {
        if(document.forms[0].elements[i].type == 'checkbox')
        {
            if(document.forms[0].elements[i].checked == true)
            {
                MyStr = MyStr + '&' + document.forms[0].elements[i].value + '=1';
            }
        }
        else if(document.forms[0].elements[i].type == 'select-one')
        {
            MyStr = MyStr + '&' + document.forms[0].elements[i].name + '=' + document.forms[0].elements[i].value;
        }
    }
     
    
    sendRequest('./MorphCalcAjax/MorphMe.aspx?' + MyStr);
    
    xmlDoc=req.responseText; 
    
 
    document.getElementById('results').innerHTML = xmlDoc;
}


function PostToProfileWhatMorph(PostIt, GeckoID)
{
if(PostIt == true)
{
    FB.ui(
   {
     method: 'feed',
     message: 'has helped someone try and decide what morph their Leopard Gecko is with the Leopard Gecko Morph Calculator.',
     name: 'The Leopard Gecko Morph Calculator',
     link: 'http://apps.facebook.com/leogeckomorphcalc/WhatMorph.aspx?ID=' + GeckoID,
     picture: 'http://www.leopardgeckomorphcalculator.co.uk/images/fbl.jpg',
     caption: 'What Morph Are These Leopard Geckos?',
     description: 'The "What Morph" League - A friendly and helpful competition to help other leopard gecko owners?'
   },
   function(response) {
     if (response && response.post_id) {
        
     } else {
        
     }
   }
 );

}
 

};
