﻿/*main site scripts*/

function dmcWPSJSSubmit(urlLink) {
	parent.location = urlLink;
}

function writeVolunteerFrame() {
	var urlHash = getUrlVars();
	if(urlHash["EmailSend"] != "" && urlHash["EmailSend"] !== undefined && urlHash["ZipSend"] != "" && urlHash["ZipSend"] !== undefined) {
		document.getElementById("dmcFrameCont").innerHTML = "<iframe frameborder=\"0\" width=\"100%\" scrolling=\"no\" src=\"VolunteerFrame.aspx?EmailSend="+urlHash["EmailSend"]+"&ZipSend="+urlHash["ZipSend"]+"\" style=\"border: 0px none ; margin: 0px; padding: 0px; height: 500px; width: 100%;\" marginheight=\"0\" marginwidth=\"0\"></iframe>";
	} else if(urlHash["EmailSend"] != "" && urlHash["EmailSend"] !== undefined) {
		document.getElementById("dmcFrameCont").innerHTML = "<iframe frameborder=\"0\" width=\"100%\" scrolling=\"no\" src=\"VolunteerFrame.aspx?EmailSend="+urlHash["EmailSend"]+"\" style=\"border: 0px none ; margin: 0px; padding: 0px; height: 500px; width: 100%;\" marginheight=\"0\" marginwidth=\"0\"></iframe>";
	} else if(urlHash["ZipSend"] != "" && urlHash["ZipSend"] !== undefined) {
		document.getElementById("dmcFrameCont").innerHTML = "<iframe frameborder=\"0\" width=\"100%\" scrolling=\"no\" src=\"VolunteerFrame.aspx?ZipSend="+urlHash["ZipSend"]+"\" style=\"border: 0px none ; margin: 0px; padding: 0px; height: 500px; width: 100%;\" marginheight=\"0\" marginwidth=\"0\"></iframe>";
	} else {
		document.getElementById("dmcFrameCont").innerHTML = "<iframe frameborder=\"0\" width=\"100%\" scrolling=\"no\" src=\"VolunteerFrame.aspx\" style=\"border: 0px none ; margin: 0px; padding: 0px; height: 500px; width: 100%;\" marginheight=\"0\" marginwidth=\"0\"></iframe>";
	}
}

function toggleContentTag(elemID) {
    $("#"+elemID).toggle("slow");
}

function submitEmailSignup() {
	var emailSend = document.getElementById("EmailSend").value;	
	var zipSend = document.getElementById("ZipSend").value;
	window.location.href = "http://texansagainstgambling.org/Volunteer.aspx?EmailSend="+emailSend+"&ZipSend="+zipSend;
}

function submitSearch() {
	var sterm = document.getElementById("dmcSearchInput").value;
	window.location.href = "http://texansagainstgambling.org/Search.aspx?process=search_content_files&searchText="+sterm;
}

function changeTms(tmsFile) {
	var currentPage = window.location.href;
	var urlHash = getUrlVars();
	if(urlHash["tmsid"] != undefined && urlHash["tmsid"] != "") {
		if(currentPage.indexOf("?") > 0) {
			currentPage = currentPage.replace("&tmsid="+urlHash["tmsid"]+"","");
			currentPage = currentPage.replace("tmsid="+urlHash["tmsid"]+"","");
			currentPage += "&tmsid=tms/"+tmsFile+".txt";	
		} else {
			currentPage = currentPage.replace("tmsid="+urlHash["tmsid"]+"","");
			currentPage += "tmsid=tms/"+tmsFile+".txt";
		}
		window.location.href = currentPage;	
	} else {
		if(currentPage.indexOf("?") > 0) {
			currentPage = currentPage.replace("&tmsid="+urlHash["tmsid"]+"","");
			currentPage = currentPage.replace("tmsid="+urlHash["tmsid"]+"","");
			currentPage += "&tmsid=tms/"+tmsFile+".txt";	
		} else {
			currentPage += "?tmsid=tms/"+tmsFile+".txt";
		}
		window.location.href = currentPage;
	}
}

function submitContributeForm() {
	var FirstName = document.getElementById("FirstName").value;
	var LastName = document.getElementById("LastName").value;
	var Address = document.getElementById("Address").value;
	var Address2 = document.getElementById("Address2").value;
	var City = document.getElementById("City").value;
	var State = document.getElementById("State").value;
	var ZipCode = document.getElementById("ZipCode").value;
	var PhoneNumber = document.getElementById("PhoneNumber").value;
	var Occupation = document.getElementById("Occupation").value;
	var Employer = document.getElementById("Employer").value;
	//var Amount = $("#Amount").val();
	$("#mess_resp").html("Processing data...");
	if(FirstName != "" && LastName != "" && Address != "" && City != "" && State != "" && ZipCode != "") {
		setTimeout("tagSubmitContributeForm('default');",2000);
	} else {
		$("#mess_resp").html("Please include all required fields.");
	}
}

function tagSubmitContributeForm(mode) {
	var data = new Array();
	var myRand = parseInt(Math.random()*999999999);
	var filePath = "../dmc_main/server.aspx";
	var myForm = document.form1;
	var queryString = "rand="+myRand;
	var bodyEmail = "<strong>Website Donate Form Data</strong><br /><br />";
	var today = new Date();
	for(var i=0; i<myForm.length; i++) {
		if(myForm[i].name != "__VIEWSTATE" && myForm[i].name.indexOf("Contrib") == -1) {
			data[myForm[i].name] = myForm[i].value;
			queryString += '&'+myForm[i].name+'='+escape(myForm[i].value);
			bodyEmail += myForm[i].name+' - '+escape(myForm[i].value)+'<br />';
		}
	}
	if(queryString.length > 0) {
		//add date added
		queryString += '&da='+today;
		//add date added
		
		//add amount
		if(document.getElementById("Contrib_25").checked == true) { queryString += '&Amount=25.00'; bodyEmail += 'Amount = 25.00<br />'; } else
		if(document.getElementById("Contrib_35").checked == true) { queryString += '&Amount=35.00'; bodyEmail += 'Amount = 35.00<br />'; } else
		if(document.getElementById("Contrib_50").checked == true) { queryString += '&Amount=50.00'; bodyEmail += 'Amount = 50.00<br />'; } else
		if(document.getElementById("Contrib_100").checked == true) { queryString += '&Amount=100.00'; bodyEmail += 'Amount = 100.00<br />'; } else
		if(document.getElementById("Contrib_250").checked == true) { queryString += '&Amount=250.00'; bodyEmail += 'Amount = 250.00<br />'; } else
		if(document.getElementById("Contrib_500").checked == true) { queryString += '&Amount=500.00'; bodyEmail += 'Amount = 500.00<br />'; } else
		if(document.getElementById("Contrib_1000").checked == true) { queryString += '&Amount=1000.00'; bodyEmail += 'Amount = 1000.00<br />'; } else
		if(document.getElementById("Contrib_Other").checked == true) { queryString += '&Amount='+myForm["Contrib_other_amount"].value; bodyEmail += 'Amount = '+myForm["Contrib_other_amount"].value+'<br />'; } else
		{ queryString += '&Amount=0.00'; bodyEmail += 'Amount = 0.00<br />'; }
		
		//add amount
		
		//send email
		jqSendEmail(adminEmailContactTo, adminEmailContactFrom, "Website Donate Form Submission", bodyEmail);
		
		$.get(filePath, queryString ,
		function(data){
			$("#mess_resp").html("Transferring to PayPal...");
			$("#PayPalRedirect").html(sanitizeServerAjaxCall(data));
			//alert(sanitizeServerAjaxCall(data));
			setTimeout("document.PayPalForm.submit();",5000);
		});
		
	} else {
		$("#mess_resp").html("Please include all required fields");
		setTimeout("clearMessResp()",20000);
	}
}