
function sendAjaxRequest(url, asynchronous, handler) {
    try {
        var request = getNewXMLHttpRequest();
        request.open("GET", url, asynchronous);
        if (handler != null) {
            request.onreadystatechange = handler;
        }
        request.send();
    } catch (err) {
        addMessage('<span class="error">'
                        + err.description + '</span><br/>');
        alert(err);
    }
}

function getNewXMLHttpRequest() {
   var obj;
    if (window.XMLHttpRequest) {
        // Most modern browsers, include IE7
        obj = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // MS 5 and 6
        obj = new ActiveXObject('Microsoft.XMLHTTP');
    } else {
        // Browser supports Javascript but not XMLHttpRequest.
        obj = null;
    }

    return obj;
}
/**
 * Checks for IE browsers and load a CSS for IE fixes
 * fixes IE 6 related background image flashing
 */
function addIEStyleSheet() {
    if(navigator.appName == "Microsoft Internet Explorer") {
        document.write('<link rel="stylesheet" type="text/css" ');
        document.write('href="css/ie-style.css" />');
        try {
        	// fixes background flash on IE reload
            document.execCommand("BackgroundImageCache", false, true);
        } catch(err) {
        }
    } 
}


function setRadio() {
 //alert(getCookie("gender"));
 	if (getCookie("mysheet") == "gender-girl") {
    	//female
 		document.getElementById('female').checked = true;
 	}
}



function setLabelColor(labelColor) {
	if (document.getElementsByTagName) {
		var labels = document.getElementsByTagName('label');
		if (labels) {
			for (var i = 0; i < labels.length; i++) {
				if (labels[i] && labels[i].style) {
					labels[i].style.color = labelColor;
				}
			}
		}
	}
}

/**
 * changes the button graphics
 */
function overButton(field, image){
   field.style.backgroundImage="url(images/" + image + ")";
}

/**
 * changes the button graphic
 */
function outButton(field, image){
   field.style.backgroundImage="url(images/" + image + ")";
}

/**
 * set the focus on the particular field
 */
function setFocus(field) {
    field.focus();
}

/**
 * sets the page footer
 */
function setToolbar() {
	if(navigator.appName == "Microsoft Internet Explorer") {
		if (document.getElementById) {
			var windowHeight = getWindowHeight();
			if (windowHeight > 0) {
				var contentHeight = windowHeight-25;
				var footerElement = document.getElementById('notification');
				var footerHeight  = footerElement.offsetHeight;
				if (windowHeight - (contentHeight + footerHeight) >= 0) {
					footerElement.style.position = 'absolute';
					footerElement.style.top = (windowHeight - footerHeight) + 'px';
				}
				else {
					footerElement.style.position = 'static';
				}
			}
		} 
	}
}

/**
 * gets the browser windows height
 */
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight + document.body.scrollTop;
}

/**
 * gets the browser windows width
 */
function getWindowWidth() {
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
      //Non-IE
      myWidth = window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      myWidth = document.body.clientWidth;

    }
    return myWidth;
}


/**
 * gets browser cookie value
 */
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 "";
}

/**
 * sets a browser cookie
 */
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+";path=/"+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

/**
 * 
 * sets the browser cookie and lets you specify the path
 */
function setCookie2(c_name,value,path,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+";path="+ path +
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

/**
 * opens send div
 */
function sendReplyOpen(reply, replylink){

	document.getElementById(reply).style.display = 'block';
	document.getElementById(replylink).style.display = 'none';
}
/**
 * closes send div
 */
function sendReplyClose(reply, replylink){

	document.getElementById(reply).style.display = 'none';
	document.getElementById(replylink).style.display = 'block';
}

/**
 * hides girl2girl link
 */
function hideG2G(link){
	document.getElementById(link).style.display = 'none';
}

/**
 * shows girl2girl link
 */
function showG2G(link){
	document.getElementById(link).style.display = 'block';
}

/**
 * feedback
 */
function starfeedback(myrating){
	//alert(myrating);
	document.getElementById('myrating').style.width=22*myrating + "px";
    var rating = document.getElementById('rating');

    if (rating != null) {
        rating.value = myrating;
    }
}

/**
 * checks/uncheck all checkboxes 
 */
function toggleCheckboxes(list, value) {
    for (i = 0; i < list.length; i++) {
        list[i].checked = value;
    }
}

/**
 * make sure a checkbox is selected
 */
function validateCheckboxes(list, type) {
    for (i = 0; i < list.length; i++) {
        if (list[i].checked == true) {
            return true;
        }
    }
    alert("Please select a " + type);
    return false;
}



/**
 * price function for boysmyaccount page
 */
function price(i) {
	document.getElementById('price').value=i;
}

/**
 * form validation for leavefeedback pages
 */
function check() {
	if (document.feedbackForm.rating.value == "0") {
		alert("Rating cannot be 0");
		return false;
	}
	return true;
}

/**
 * opens search div
 */
function openSearchBox(){

	document.getElementById('searchbox').style.display = 'block';
}

/**
 * opens advanced search div
 */
function openAdvSearchBox(){

	document.getElementById('advsearchbox').style.display = 'block';
}

/**
 * validates registration screen
 */

function validateRegistration() {
	alert('hi');
	return false;
}

function validateReg() {
	alert('hi');
	if (getCookie('MGF')) {
		//alert("You already have an account on mygirlfund");
		//return false;
	}
	var _error = 0;
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/; 
	var month = document.getElementById("month").value;
	var day =  document.getElementById("day").value;
	var year = document.getElementById("year").value;
	switch(month.substring(0,3))
	{
		case "JAN": month = "1"; break;
		case "FEB": month = "2"; break;
		case "MAR": month = "3"; break;
		case "APR": month = "4"; break;
		case "MAY": month = "5"; break;
		case "JUN": month = "6"; break;
		case "JUL": month = "7"; break;
		case "AUG": month = "8"; break;
		case "SEP": month = "9"; break;
		case "OCT": month = "10"; break;
		case "NOV": month = "11"; break;
		case "DEC": month = "12"; break;
	}
	var dob = month + "/" + day + "/" + year;
	var birthday = new Date(dob);

	//email
	var email = document.getElementById("email").value;
	if (!pattern.test(email)){
		error('error-email');
		_error = 1;
	} else {
		ok('error-email');
	}
	//confirm email
	var confirmEmail = document.getElementById("confirmEmail").value;
	if (confirmEmail != email) {
            error('error-confirmEmail');
            _error = 1;
	} else {
            ok('error-confirmEmail');
	}

	//password
	var pw = document.getElementById("password").value
	if (pw.length < 6 ){
		error('error-pw');
		_error = 1;
	} else {
		ok('error-pw');
	}
	//confirm password
	if (document.getElementById("confirmPassword").value
            != document.getElementById("password").value) {
            error('error-pwc');
            _error = 1;
	} else {
            ok('error-pwc');
	}
	//country
	if (document.getElementById("country").value == ""){
		error('error-country');
		_error = 1;
	} else {
		ok('error-country');
	}
	//dob - need to verify the age > 18
	if (month == "" || checkAge(month, day, year) == false) {
		error('error-dob');
		_error = 1;
	} else {
		ok('error-dob');
	}
	//term of service
	if (document.getElementById("agreeTermsOfService").value != "on") {
		error('error-tos');
		_error = 1;
	} else {
		ok('error-tos');
	}
    // captcha
    if (document.getElementById("captcha").value == "") {
        error('error-captcha');
        _error = 1;
    } else {
        ok('error-captcha');
    }

	//return the error code
	if (_error == 1) {
		return false;
	}
	return true;
}
/**
 * validateReg() helper function
 */
function error(field) {
	  document.getElementById(field).style.display = 'block';
}
/**
 * validateReg() helper function
 */
function ok(field) {
	  document.getElementById(field).style.display = 'none';
}
/**
 * validateReg() helper function
 */
function checkAge(month, day, year) {
	var today = new Date();
	var check = new Date((parseInt(year) + 18), month-1, day);
	if ((today.getTime() - check.getTime()) < 0) {
		return false;
	}
	return true;
}

/**
 * dynamically updates the contribution message subject 
 */
function contributionAmount() {
	var x = document.getElementById('select');
	var amount = x.options[x.selectedIndex].text;
	var subject = "I just sent you a $" + amount + " contribution";
	document.getElementById('amount').value = subject;
}

/**
 * dynamically updates the contribution message subject 
 */
function contributionCreditAmount() {
    var x = document.getElementById('contribution');
    var amount = x.options[x.selectedIndex].text;
    var subject = "I just sent you a $" + amount + " contribution";
    document.getElementById('subject').value = subject;
    if (amount >= 25) {
    	document.getElementById('escrow').style.display = 'block';
    } else {
    	document.getElementById('escrow').style.display = 'none';
    }
}

/**
 * check the upload files extension
 */
function checkFile(file) {	
	var file = file.slice(file.indexOf("\\") + 1);
	var ext = file.slice(file.lastIndexOf(".")).toLowerCase();
	if (ext == ".jpg" || ext == ".jpeg" || ext == ".zip"){
	    loader();
		return true;
	} else {
		alert("only .jpg files can be uploaded." 
		    + "\nPlease select another file."); 
	}
	return false;
}

function loader() {    
    document.getElementById('loader').style.width = getWindowWidth() + "px";
    document.getElementById('loader').style.height = getWindowHeight() + "px";
    document.getElementById('loader').style.display = 'block';
    //center the text
    document.getElementById('loadertext').style.left = getWindowWidth()/2-33 + "px";
    document.getElementById('loadertext').style.top = getWindowHeight()/2-33 + "px";
    document.getElementById('loadertext').style.display = 'block';
}


function lessthan(a,b) {
	if (a < b ) {
		return true;
	}
	return false;
}


/**
 * change background skin color 
 */
function changeSkin() {
	var skin = getCookie("skin");
	if (skin == "black") {
		blackSkin();
		return;
	}
	if (skin == "blue") {
		blueSkin();
		return;
	}
	if (skin == "gray") {
		graySkin();
		return;
	}
	if (skin == "pink") {
		pinkSkin();
		return;
	}
	if (skin == "green") {
		greenSkin();
		return;
	}
	if (skin == "orange") {
		orangeSkin();
		return;
	}
	if (skin == "purple") {
		purpleSkin();
		return;
	}
	if (skin == "pinkheart") {
		pinkHeartSkin();
		return;
	}
	if (skin == "blueheart") {
		blueHeartSkin();
		return;
	}
	if (skin == "redstar") {
		redStarSkin();
		return;
	}
	if (skin == "paperheart") {
		paperHeartSkin();
		return;
	}
	if (skin == "graypaperheart") {
		grayPaperHeartSkin();
		return;
	}
}

/**
 * set the skin cookie for the login page
 */
function setSkinCookie() {
	var color = document.getElementById('skin').value;
	setCookie("skin",color, null);
}

/**
 * set the skin color
 */
function setSkin(color) {
	document.getElementById('skin').value=color;
	document.body.style.backgroundRepeat = "repeat-x";
	if (color =="black") {
		document.body.style.backgroundColor = "#000000";
		document.body.style.backgroundImage = "url(/images/blackwallpaper.jpg)";
		document.getElementById('heading').style.color = "red"; 
		document.getElementById('logoutlink').style.color = "#CCCCCC"; 
		return;
	}
	if (color =="blue") {
		document.body.style.backgroundColor = "#B4CEE5";
		document.body.style.backgroundImage = "url(/images/bluewallpaper.jpg)";
		document.getElementById('heading').style.color = "black"; 
		document.getElementById('logoutlink').style.color = "#B6D5F3"; 
		return;
	}
	if (color =="gray") {
		document.body.style.backgroundColor = "#474747";
		document.body.style.backgroundImage = "url(/images/graywallpaper.jpg)";
		document.getElementById('heading').style.color = "red"; 
		document.getElementById('logoutlink').style.color = "#CCCCCC"; 
		return;
	}
	if (color =="pink") {
		document.body.style.backgroundColor = "#EFBCCF";
		document.body.style.backgroundImage = "url(/images/pinkwallpaper.jpg)";
		document.getElementById('heading').style.color = "black"; 
		document.getElementById('logoutlink').style.color = "#FDD2CE"; 
		return;
	}
	if (color =="green") {
		document.body.style.backgroundColor = "#99CC99";
		document.body.style.backgroundImage = "url(/images/greenwallpaper.jpg)";
		document.getElementById('heading').style.color = "black"; 
		document.getElementById('logoutlink').style.color = "#99CC99"; 
		return;
	}
	if (color =="orange") {
		document.body.style.backgroundColor = "#DF7801";
		document.body.style.backgroundImage = "url(/images/orangewallpaper.jpg)";
		document.getElementById('heading').style.color = "black"; 
		document.getElementById('logoutlink').style.color = "#FFCC00"; 
		return;
	}
	if (color =="purple") {
		document.body.style.backgroundColor = "#581258";
		document.body.style.backgroundImage = "url(/images/purplewallpaper.jpg)";
		document.getElementById('heading').style.color = "red"; 
		document.getElementById('logoutlink').style.color = "#993399"; 
		return;
	}
	if (color =="pinkheart") {
		document.body.style.backgroundColor = "#660000";
		document.body.style.backgroundImage = "url(/images/pink_heart.jpg)";
		document.body.style.backgroundRepeat = "repeat";
		document.getElementById('heading').style.color = "yellow"; 
		document.getElementById('logoutlink').style.color = "#FDD2CE"; 
		return;
	}
	if (color =="blueheart") {
		document.body.style.backgroundColor = "#B4CEE5";
		document.body.style.backgroundImage = "url(/images/blue_heart.jpg)";
		document.body.style.backgroundRepeat = "repeat";
		document.getElementById('heading').style.color = "red"; 
		document.getElementById('logoutlink').style.color = "#B6D5F3"; 
		return;
	}
	if (color =="redstar") {
		document.body.style.backgroundColor = "#660000";
		document.body.style.backgroundImage = "url(/images/redstar.jpg)";
		document.body.style.backgroundRepeat = "repeat";
		document.getElementById('heading').style.color = "yellow"; 
		document.getElementById('logoutlink').style.color = "#FDD2CE"; 
		return;
	}
	if (color =="paperheart") {
		document.body.style.backgroundColor = "#660000";
		document.body.style.backgroundImage = "url(/images/paperheart.jpg)";
		document.body.style.backgroundRepeat = "repeat";
		document.getElementById('heading').style.color = "yellow"; 
		document.getElementById('logoutlink').style.color = "#FDD2CE"; 
		return;
	}
	if (color =="graypaperheart") {
		document.body.style.backgroundColor = "#474747";
		document.body.style.backgroundImage = "url(/images/graypaperheart.jpg)";
		document.body.style.backgroundRepeat = "repeat";
		document.getElementById('heading').style.color = "red"; 
		document.getElementById('logoutlink').style.color = "#CCCCCC"; 
		return;
	}
}



function blackSkin() {
    document.body.style.backgroundColor = "#000000";
    document.body.style.backgroundImage = "url(/images/blackwallpaper.jpg)";
    document.write('<link href="/css/skin/black.css" rel="stylesheet" type="text/css"/>');
}

function blueSkin() {
    document.body.style.backgroundColor = "#B4CEE5";
    document.body.style.backgroundImage = "url(/images/bluewallpaper.jpg)";
    document.write('<link href="/css/skin/blue.css" rel="stylesheet" type="text/css"/>');
}

function graySkin() {
    document.body.style.backgroundColor = "#4C4C4C";
    document.body.style.backgroundImage = "url(/images/graywallpaper.jpg)";
    document.write('<link href="/css/skin/gray.css" rel="stylesheet" type="text/css"/>');
}

function pinkSkin() {
    document.body.style.backgroundColor = "#EFBCCF";
    document.body.style.backgroundImage = "url(/images/pinkwallpaper.jpg)";
    document.write('<link href="/css/skin/pink.css" rel="stylesheet" type="text/css"/>');
}

function greenSkin() {
    document.body.style.backgroundColor = "#99CC99";
    document.body.style.backgroundImage = "url(/images/greenwallpaper.jpg)";
    document.write('<link href="/css/skin/green.css" rel="stylesheet" type="text/css"/>');
}

function orangeSkin() {
    document.body.style.backgroundColor = "#DF7801";
    document.body.style.backgroundImage = "url(/images/orangewallpaper.jpg)";
    document.write('<link href="/css/skin/orange.css" rel="stylesheet" type="text/css"/>');
}

function purpleSkin() {
    document.body.style.backgroundColor = "#581258";
    document.body.style.backgroundImage = "url(/images/purplewallpaper.jpg)";
    document.write('<link href="/css/skin/purple.css" rel="stylesheet" type="text/css"/>');
}

function pinkHeartSkin() {
    document.body.style.backgroundColor = "#660000";
    document.body.style.backgroundImage = "url(/images/pink_heart.jpg)";
    document.write('<link href="/css/skin/pinkheart.css" rel="stylesheet" type="text/css"/>');
}

function blueHeartSkin() {
    document.body.style.backgroundColor = "#B4CEE5";
    document.body.style.backgroundImage = "url(/images/blue_heart.jpg)";
    document.write('<link href="/css/skin/blueheart.css" rel="stylesheet" type="text/css"/>');
}

function redStarSkin() {
    document.body.style.backgroundColor = "#660000";
    document.body.style.backgroundImage = "url(/images/redstar.jpg)";
    document.write('<link href="/css/skin/redstar.css" rel="stylesheet" type="text/css"/>');
}

function paperHeartSkin() {
    document.body.style.backgroundColor = "#660000";
    document.body.style.backgroundImage = "url(/images/paperheart.jpg)";
    document.write('<link href="/css/skin/paperheart.css" rel="stylesheet" type="text/css"/>');
}

function grayPaperHeartSkin() {
    document.body.style.backgroundColor = "#4C4C4C";
    document.body.style.backgroundImage = "url(/images/graypaperheart.jpg)";
    document.write('<link href="/css/skin/graypaperheart.css" rel="stylesheet" type="text/css"/>');
}

