//Must have jquery library included!


function input_clear_on_click(element,text){

	$(element).click(function(event){
					$(this).css("color","black");				  
					if(this.value==text)
						  {
						  	this.value='';
						  }
				});
}


$('#PTCServiceSignup').submit(function() {
		userChose = $("input[name='yesno']:checked").val();
		userID=gup('id');
		
		if (userChose==null){
  			alert('Please select an option');
			return false;
		}else{
			if (userChose=="Yes"){
				sendPTCEmail("jgoldstone@schicktech.com,ptc.operations.billing@pattersoncompanies.com",userID);
				updateDicomTable("getPTCSupport",userID);
				return false;
			}
			if (userChose=="No"){
  				updateDicomTable("dropPTCSupport",userID);
				return false;
			}
		}
});

function sendPTCEmail(email,id){

$.ajax({
   			type: "GET",
   			url: "https://"+window.location.hostname+"/portal/dicom_download/email_PTC_support.php?id="+id+"&address="+email,
   			data: "",
   			success: function(msg){
				
   			}
 		});

}

function updateDicomTable(action,requester){
	$.ajax({
   					type: "POST",
   					url: "https://"+window.location.hostname+"/portal/dicom_download/update_table.php?requester="+requester+"&action="+action,
   					data: "",
   					success: function(msg){
						window.location = "https://"+window.location.hostname+"/items.php?itemid=7680";

   					}
 		   });
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

		
function focusCursorOn(fieldtofocus){	

		
		function focusOnUserField() {
				fieldtofocus.focus()
			}
		
	   if (window.addEventListener){
			window.addEventListener('load', focusOnUserField, false);
		}
	   else if (window.attachEvent){
		   window.attachEvent('onload', focusOnUserField);
	   }
}