// dysplays on/off if a checkbox is checked/unchecked 
// the id of the <tr>(or other things) has to have the same name as checbox name+"_td"
function display_tr(check)
{
	if (check.checked){
		document.getElementById(check.name+'_td').style.display='';
	}else document.getElementById(check.name+'_td').style.display='none';
}

// dysplays on/off if a radio is checked/unchecked 
// the id of the <tr>(or other things) has to have the same name as checbox name+"_td"
function display_tr_radio(checkName,check)
{
	for (i=0;i<check.length;i++){
		
		if (check[i].checked==true){
			document.getElementById(checkName.name+'_'+i+'_td').style.display='';
		}else{ 
			document.getElementById(checkName.name+'_'+i+'_td').style.display='none';
		}
	}
}

//to check all checkboxes in a form
//parameters are the checked checkbox(or true/false) and form name (the form MUST HAVE AN ID BESIDES NAME)
function checkedAll (checked,form_name) {
	var el = document.getElementById(form_name);
		
	
	for (var i = 0; i < el.elements.length; i++) {
	  	el.elements[i].checked = checked;
	}
}
//email format checking
function emailCheck(who){
	var email=/^[A-Za-z0-9][\w-.]*[A-Za-z0-9]*@[A-Za-z0-9]*([\w-.]*[A-Za-z0-9]\.)+([A-Za-z]){2,4}$/i;
	return(email.test(who));
}

function copy_fields(){
	el_1 = document.form1;
	el_2 = document.form2;
	
	for (var i = 0; i < el_2.elements.length; i++){
//		document.write(document.form2.elements[i].name+"||"+document.form1.elements[i].value+"<br>");
//
//		document.write(document.form1.elements[i].name+"||"+document.form1.elements[i].value+"<br>");
//		document.write("<hr>");		
		document.form2.elements[i].value = document.form1.elements[i].value;
	}
}

function makeRequest_get(url,code) {

	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	if (code == 1){
		http_request.onreadystatechange = function() { showContents(http_request); };
	}
	//http_request.onreadystatechange = function() { showContents_email(http_request); };
	http_request.open('GET', url, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(null);

}
// displays the inner html recieved after request
function showContents(http_request) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		   str = http_request.responseText;
		   if (str.search(/.*code=ok.*/) == -1){alert('The promo code is not valid');return false}
		} else {
			alert('There was a problem with the request.');
		}
	}

}
function showContents_email(http_request) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		   str = http_request.responseText;
		   if (str.search(/.*double_email=ok*/) == -1){
		   	  alert('The email already exists in our database');
		   	  document.body.innerHTML = http_request.responseText;
		   	  return false;
		   }else{
			   //setTimeout('document.form1.submit()',10000);
		   }
		} else {
			alert('There was a problem with the request.');
		}
	}

}




 //ajax functions remote http request ...

    

    function makeRequest(url) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { alertContents(http_request); };
        http_request.open('GET', url, true);
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http_request.send(null);

    }

    function alertContents(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			  document.body.innerHTML = http_request.responseText;
            } else {
                alert('There was a problem with the request.');
            }
        }

    }

var cookieEnabled=(navigator.cookieEnabled)? true : false
if (!cookieEnabled) alert ('You must have cookies enabled');