var mailerror = true;
var passerror = true;

//this array is only for the demo, remove when live
var pages = new Array()
pages[0] = "index.cfm?fuseaction=register.step1";
pages[1] = "";
pages[2] = "http://www.thefetishparty.com/step3.html";
pages[3] = "http://www.thefetishparty.com/step3b.html";
pages[4] = "http://www.thefetishparty.com/step4.html";
pages[5] = "http://www.thefetishparty.com/step-done.html";



function submitform (step) {

    //SARAH: change this to post the webpage
    //$("frm").submit();

    //alert(step)

    // remove this crap below, its just to make the demo work
    if (step == "0"){
         document.location.href= pages[0];
    }
    if (step == "1"){
        //check to see if nothing is left empty

            if(passerror==true || mailerror==true){
				alert("You have not properly filled in the fields yet.")
                return false;
            }
            if (
            $("emailaddress").value == "" ||
            $("password").value == "" ||
            $("confirmpassword").value == ""
             ){

                alert("You have not properly filled in the fields yet.")
                return false;
            }
         //document.location.href= pages[1];
		 $("frm").submit();
    }
    if (step == "2"){
         if ($("firstname").value == ""){
                alert("Please enter your firstname.")
				$("firstname").focus();
                return false;
         }
		 if ($("lastname").value == ""){
                alert("Please enter your lastname.")
				$("lastname").focus();
                return false;
         }
		 if ($("nickname").value == ""){
                alert("Please enter your nickname.")
				$("nickname").focus();
                return false;
         }
		 if ($("address").value == ""){
                alert("Please enter your address.")
				$("address").focus();
                return false;
         }
		 if ($("city").value == ""){
                alert("Please enter your city.")
				$("city").focus();
                return false;
         }
		 if ($("zip").value == ""){
                alert("Please enter your zip.")
				$("zip").focus();
                return false;
         }
		 if ($("country").value == "US" && $("state").value == ""){
                alert("Please select your state.")
				$("state").focus();
                return false;
         }
		 if ($('birthmonth').options[0].selected==true && $('birthday').options[0].selected==true && $('birthyear').options[0].selected==true && $('nt_birthdate').checked==false){
                alert("Please either select your Birth Date from the drop down,\n\n                                   OR\n\nCHECK the \"Not Telling\" box to the right of Birth Date.");
				$("birthmonth").focus();
                return false;
         }
		 if ($('birthmonth').options[0].selected==true && $('nt_birthdate').checked==false){
                alert("Please either select your Birth Month from the drop down,\n\n                                   OR\n\nCHECK the \"Not Telling\" box to the right of Birth Date.");
				$("birthmonth").focus();
                return false;
         }
		 if ($('birthday').options[0].selected==true && $('nt_birthdate').checked==false){
                alert("Please either select your Birth Day from the drop down,\n\n                                   OR\n\nCHECK the \"Not Telling\" box to the right of Birth Date.");
				$("birthmonth").focus();
                return false;
         }
		 if ($('birthyear').options[0].selected==true && $('nt_birthdate').checked==false){
                alert("Please either select your Birth Year from the drop down,\n\n                                   OR\n\nCHECK the \"Not Telling\" box to the right of Birth Date.");
				$("birthmonth").focus();
                return false;
         }
		 /*
		 if ($('sex_male').checked==false && $('sex_female').checked==false && $('nt_sex').checked==false){
                alert("Please either select your Gender,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of Sex.");
				$("sex_male").focus();
                return false;
         }
		 */
		 if ($('sex_male').checked==false && $('sex_female').checked==false){
                alert("You MUST select your Gender!");
				$("sex_male").focus();
                return false;
         }
		 if ($('feet').options[0].selected==true && $('inches').options[0].selected==true && $('metric').value=="" && $('nt_height').checked==false){
		        alert("Please either enter your Height in Ft/In or cm,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of Height.");
				$("feet").focus();
                return false;
		 }
		 if ($('feet').options[0].selected==true && $('metric').value=="" && $('nt_height').checked==false){
		        alert("Please either enter your Height in Ft/In or cm,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of Height.");
				$("feet").focus();
                return false;
		 }
		 if ($('inches').options[0].selected==true && $('metric').value=="" && $('nt_height').checked==false){
		        alert("Please either enter your Height in Ft/In or cm,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of Height.");
				$("feet").focus();
                return false;
		 }
		 if ($('question_16_answer').options[0].selected==true && $('nt_question_16_answer').checked==false){
				alert("Please either select your Body Type option,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of Body Type.");
				$("question_16_answer").focus();
                return false;
		 }
		 /*
		 if ($('eyecolor').options[0].selected==true && $('haircolor').options[0].selected==true && $('nt_eyehair').checked==false){
		        alert("Please either select your Hair & Eye Color,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the options.");
				$("eyecolor").focus();
                return false;
		 }		 
		 if ($('eyecolor').options[0].selected==true && $('nt_eyehair').checked==false){
		        alert("Please either select your Eye Color,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the options.");
				$("eyecolor").focus();
                return false;
		 }
		 if ($('haircolor').options[0].selected==true && $('nt_eyehair').checked==false){
		        alert("Please either select your Hair Color,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the options.");
				$("eyecolor").focus();
                return false;
		 }
		 */
		 if ($('eyecolor').options[0].selected==true && $('haircolor').options[0].selected==true){
		        alert("You MUST select your Hair & Eye Color!");
				$("eyecolor").focus();
                return false;
		 }	
		 if ($('eyecolor').options[0].selected==true){
		        alert("You MUST select your Eye Color!");
				$("eyecolor").focus();
                return false;
		 }
		 if ($('haircolor').options[0].selected==true){
		        alert("You MUST select your Hair Color!");
				$("eyecolor").focus();
                return false;
		 }
		//document.location.href= pages[2];
		$("frm").submit();
    }
    if (step == "3b"){
		 //document.location.href= pages[3];
		 /*
		 if ($('shortbio').value=="" && $('nt_shortbio').checked==false){
		        alert("Please either enter a Short Bio about yourself,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the Bio.");
				$("shortbio").focus();
                return false;
		 }
		 if ($('sexpref').options[0].selected==true && $('nt_sexpref').checked==false){
		        alert("Please either select your Sexual Preference,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the options.");
				$("sexpref").focus();
                return false;
		 }
		 if ($('wild1').checked==false && $('wild2').checked==false && $('wild3').checked==false && $('wild4').checked==false && $('wild5').checked==false && $('nt_wildmild').checked==false){
		        alert("Please select a number for yourself on the Wild to Mild scale,\n\n                                      OR\n\nCHECK the \"Not Telling\" box to the right of the number scale.");
				$("wild5").focus();
                return false;
		 }
		 if ($('interests').options.selectedIndex=="-1" && $('nt_interests').checked==false){
		        alert("Please either select some Interests from the list\n\n                                      OR\n\nCHECK the \"Not Telling\" box to the right of the Interests list.");
				$("interests").focus();
                return false;
		 }
		 */
		 if ($('shortbio').value==""){
		        alert("You MUST enter a Short Bio about yourself!");
				$("shortbio").focus();
                return false;
		 }
		 if ($('sexpref').options[0].selected==true){
		        alert("You MUST select your Sexual Preference!");
				$("sexpref").focus();
                return false;
		 }
		 if ($('wild1').checked==false && $('wild2').checked==false && $('wild3').checked==false && $('wild4').checked==false && $('wild5').checked==false){
		        alert("You MUST select a number for yourself on the Wild to Mild scale!");
				$("wild5").focus();
                return false;
		 }
		 if ($('interests').options.selectedIndex=="-1"){
		        alert("You MUST select some Interests from the list!");
				$("interests").focus();
                return false;
		 }
		 if ($('nonlisted').value=="" && $('nt_nonlisted').checked==false){
		        alert("Please either enter any additional fetishes you have,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the box.");
				$("nonlisted").focus();
                return false;
		 }
		 $("frm").submit();
    }
    if (step == "4"){
         //document.location.href= pages[4];
		 for(i=1; i<=15; i++ ){
		 	if (i <= 5 || i >= 10 ){
				formfieldname = "question_"+i+"_answer";
				ntformfieldname = "nt_question_"+i+"_answer";
				if (i=="3"){
					// do multiple choices lists
					if ($(formfieldname).options.selectedIndex=="-1"){
					        alert("You MUST select who you are seeking from the list!");
							$(formfieldname).focus();
			                return false;
					 }
					 /*
					 if ($(formfieldname).options.selectedIndex=="-1" && $(ntformfieldname).checked==false){
					        alert("Please either select who you are seeking from the list\n\n                                      OR\n\nCHECK the \"Not Telling\" box to the right of the options list.");
							$(formfieldname).focus();
			                return false;
					 }
					 */
				} else {
					if (i=="14" || i=="15"){
						// do textarea box
						if ($(formfieldname).value=="" && $(ntformfieldname).checked==false){
						        alert("Please either enter some descriptive text for tattoos or piercings,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the text box.");
								$(formfieldname).focus();
				                return false;
						 }
					} else {
						// do select lists
						if ($(formfieldname).options.selectedIndex=="0"){
							if (i>=5){
								if ($(formfieldname).options[0].selected==true && $(ntformfieldname).checked==false){
								        alert("Please either select an option from the list,\n\n                      OR\n\nCHECK the \"Not Telling\" box to the right of the options.");
										$(formfieldname).focus();
						                return false;
								 }	
							}else{
								if ($(formfieldname).options[0].selected==true){
								        alert("You MUST select an option from the list!");
										$(formfieldname).focus();
						                return false;
								 }
							}
							
						}
					}
				}
			}
		 }
		 $("frm").submit();
    }
    if (step == "5"){
		 $("continue_but").innerHTML = "<img src=\"img/btn_continue.gif\" onclick=\"alert('You have already pressed the continue button once!');\" alt=\"Thats it!\" /> <font color=Red>... Please wait, request processing ...</font>";
		//alert($("continue_but").innerHTML);
         $("frm").submit();
		 //document.location.href= pages[5];
    }
}



function validateEmail()
{ mailerror = false;
    var e = $("emailaddress").value;

    // - first reset all states
    $("invalidemail").style.display = "none";
    $("validemail").style.display = "none";

    if(e.indexOf("@")==-1 || e.indexOf(".")==-1  || e.indexOf(' ', 0) != -1 || e.indexOf(',', 0) != -1){
        $("invalidemail").style.display = "inline";
        mailerror = true;
        return false;
    }else{
        $("validemail").style.display = "inline";
    }

}

function errorOff(){
	mailerror = false;
	passerror = false;
}

function validatePasswords()
{
    var pass1 = $("password").value;
    var pass2 = $("confirmpassword").value;

    // - first reset all states
    $("passwordincorrect").style.display = "none";
    $("passwordcorrect").style.display = "none";

    if (pass1 == "" || pass2 =="") {
            $("passwordincorrect").style.display = "inline";
            passerror = true;
            return false;
    }

    if(pass1!=pass2){
        $("passwordincorrect").style.display = "inline";
        passerror = true;
        return false;
    }else{
        $("passwordcorrect").style.display = "inline";
        passerror = false;
    }
}

function addPhoto(id) {

    var obj = $(id);
    //obj.style.display = "block";

    new Effect.Appear(obj.id, {duration: 1});
}

function doAppear(id){
    var obj = $(id);

    if(obj.style.display=="none"){
    new Effect.BlindDown(obj.id, {duration: 3})
    }else{
    new Effect.BlindUp(obj.id, {duration: 2})
    }

}

// switch preview on selection input type="file": onchange="switchimage(this.id,'Preview');"
// IE only though.
function switchimage(id, previewID) {

	inputfile = new Object();
	inputfile = $(id);

	var imagepath = inputfile.value;

	if (imagepath != "") {

		imagetype = new Array(".gif",".jpg",".jpeg",".png");

		for (i=0;i<4;i++) {
			if (imagepath.toLowerCase().indexOf(imagetype[i]) > -1) {
				document.images[previewID].src = 'file:///'+imagepath;
			}
		}

	}

}

// reset preview to empty.gif selection input type="file": onchange="switchimage(this.id,'Preview');"

function resetimage(url, previewID) {
	document.images[previewID].src = url;
	$('Foto').value = 'empty';
}

function checkEmail(myresponse)
{ mailerror = false;
    var e = $("emailaddress").value;

    // - first reset all states
    $("invalidemail").style.display = "none";
    $("validemail").style.display = "none";

	// get good or bad response from database on email/username
	
    if(myresponse=="bad"){
        $("invalidemail").style.display = "inline";
		alert("Please select another email address.\nThe address you have entered is already registered with us.");
		$("emailaddress").focus();
        mailerror = true;
        return false;
    }else{
        $("validemail").style.display = "inline";
		//$("userid").value = myresponse;
    }

}
function startCheckEmail(accessid,profileid){
	var e = $("emailaddress").value;
	var p = $("password").value;
	theurl = 'http://www.thefetishparty.com/index.cfm?fuseaction=Register.CheckUser';
	theurl = theurl+'&emailaddress='+e;
	theurl = theurl+'&password='+p;
	theurl = theurl+'&access='+accessid;
	theurl = theurl+'&profile='+profileid;
	//alert(theurl);
	if (p!=""){
		loadXMLDoc(theurl);
	}	
}

function ignore(num) {	// null function
	alert("null function call, data:"+num); 
}
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange() {    // only if req shows "complete"
    if (req.readyState == 4) {   // only if "OK"
        if (req.status == 200) { // ...processing statements go here...
	      response  = req.responseXML.documentElement;
    	  method    = response.getElementsByTagName('method')[0].firstChild.data;
    	  result    = response.getElementsByTagName('result')[0].firstChild.data;
		  // alert(method + '(' + result + ')');
		  eval(method + '(' + result + ')');
        } else {
			// put here to handle old version of firefox
			if (req.status == 0) { // ...processing statements go here...
		      response  = req.responseXML.documentElement;
	    	  method    = response.getElementsByTagName('method')[0].firstChild.data;
	    	  result    = response.getElementsByTagName('result')[0].firstChild.data;
			  // alert(method + '(' + result + ')');
			  eval(method + '(' + result + ')');
	        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
				alert("There was a problem retrieving the XML data:\n" + req.status);
			}
        }
    }
}
function processArray(in_String, out_Array) {
	out_Array = in_String.split(";");
	for ( var i=0; i < out_Array.length; i++ ) { out_Array[i]=out_Array[i].split(","); }
	return out_Array;
}

function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
   }
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
   }
}

function selectInterests(){
      var interests = $("interests");
	  var pickOptions = interests.options;
	  var pickOLength = pickOptions.length;
	  if (pickOLength < 1) {
	    // do nothing
	  } else {
		  for (var i = 0; i < pickOLength; i++) {
		    pickOptions[i].selected = true;
		  }
	  }
}

function selectFetishes(){
      var fetishes = $("fetishes");
	  var pickOptions = fetishes.options;
	  var pickOLength = pickOptions.length;
	  if (pickOLength < 1) {
	    // do nothing
	  } else {
		  for (var i = 0; i < pickOLength; i++) {
		    pickOptions[i].selected = true;
		  }
	  }
}

function selectSeeking(){
      var Seeking = $("question_3_answer");
	  var pickOptions = Seeking.options;
	  var pickOLength = pickOptions.length;
	  if (pickOLength < 1) {
	    // do nothing
	  } else {
		  for (var i = 0; i < pickOLength; i++) {
		    pickOptions[i].selected = true;
		  }
	  }
}

function addPhotoRow(){
	var table1 = document.getElementById("table1");
	var tbody1 = document.getElementById("tbody1");
	var myNewtbody = document.createElement("tbody");
	myNewtbody.id = "tbody1";
	var docFragment = document.createDocumentFragment();
	var trElem, tdElem, txtNode;
	var tableRowLength = table1.rows.length + 1;
	//alert(tableRowLength);
	if (tableRowLength > "10"){
		alert("Sorry, but you have reached the max number of photos allowed.");
	} else {
		var picname = "photo" + tableRowLength;
		var pictitle = "Photo " + tableRowLength;
		var picid = "photo_" + tableRowLength;
		var preview = "imgPreview" + tableRowLength;
		var picnt = "nt_" + picid;
		   // create row element
		   trElem = document.createElement("tr");
		   trElem.setAttribute("id",picname);
		
		   //first column
		   tdElem = document.createElement("td");
				tdElem_data =  document.createElement("IMG");
				tdElem_data.setAttribute("src","http://www.thefetishparty.com/img/bg-photo.gif");
				tdElem_data.setAttribute("id",preview);
				tdElem_data.setAttribute("width","64");
				tdElem_data.setAttribute("height","64");
				tdElem_data.setAttribute("alt","a preview of your photo");
			tdElem.appendChild(tdElem_data);
			trElem.appendChild(tdElem);
			
			//second column
			tdElem = document.createElement("td");
			tdElem.className = "labelmed";
				tdElem_data1 =  document.createElement("H3");
				txtNode = document.createTextNode(pictitle);
				tdElem_data1.appendChild(txtNode);
				tdElem_data2 =  document.createElement("DIV"); 
				tdElem_data2.className = "browsecap";
				txtNode = document.createTextNode("Browse your pc and get that perfect pic");
				tdElem_data2.appendChild(txtNode);
				tdElem_data3 =  document.createElement("INPUT"); 
				tdElem_data3.setAttribute("type","file");
				tdElem_data3.setAttribute("name",picid);
				tdElem_data3.setAttribute("id",picid);
				tdElem_data3.setAttribute("onchange","switchimage(this.id,'"+preview+"');");
				tdElem_data3.setAttribute("accept","image/gif, image/jpeg, image/jpg, image/png");
			tdElem.appendChild(tdElem_data1);
			tdElem.appendChild(tdElem_data2);
			tdElem.appendChild(tdElem_data3);
			trElem.appendChild(tdElem);
		
		   //third column 					  <span class="hide">Not telling</span>
		   tdElem = document.createElement("td");      
			mkdiv =  document.createElement("DIV"); 
			//mkdiv.className = "nottelling";
			//mkinput =  document.createElement("INPUT"); 
			//mkinput.setAttribute("type","checkbox"); 
			//mkinput.setAttribute("name",picnt); 
			//mkinput.setAttribute("value","yes"); 
			//mkinput.setAttribute("id",picnt); 
			//mkdiv.appendChild(mkinput);
				//mkspan = document.createElement("SPAN");
				//mkspan.setAttribute("class","hide");
				//txtNode = document.createTextNode(" Not Telling");
				//mkspan.appendChild(txtNode);
			//mkdiv.appendChild(mkspan);
			tdElem.appendChild(mkdiv); 
			trElem.appendChild(tdElem);
		   
		docFragment.appendChild(trElem);
		myNewtbody.appendChild(docFragment);
		//alert(myNewtbody.innerHTML);
		table1.appendChild(myNewtbody, tbody1);
	}	
}

function popWindow(URL) {
	window.open(URL, "newwindow", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=549");
}
