//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='';
						  }
				});
}

 if (typeof jQuery == 'undefined') { 
 }else{
	 
	 
	 
	 $('#PTCServiceSignup').submit(function(e) {
		userChose = $("input[name='yesno']:checked").val();
		userID=gup('id');
		e.preventDefault(); 
		if (userChose==null){
  			alert('Please select an options');
			return false;
		}else{
			if (userChose=="Yes"){
				sendEmail("jgoldstone@schicktech.com,ptc.operations.billing@pattersoncompanies.com",userID,"/portal/dicom_download/email_PTC_support.php");
				updateDicomTable("getPTCSupport",userID);
				return true;
			}
			if (userChose=="No"){
				
  				updateDicomTable("dropPTCSupport",userID);
				return true;
			}
		}
});


$('#adaPoster').submit(function(e) {
		e.preventDefault(); 
		if (formIsValid()){
			var dentistInfo = {};
			$.each($('#adaPoster').serializeArray(), function(i, field) {
				dentistInfo[field.name] = field.value;
			});
			
			updateADAPosterTable(dentistInfo);
			
			$(this).slideUp("medium",function() {
				$(this).parent().hide("fast",function() {
					$(this).parent().parent().append('<img src="/images/web_graphics/adaPoster/checkmark.gif" style="width: 37px; margin-right: 9px;"><p>Thank you for your request '+dentistInfo["name"]+'.  You will receive your poster within 5 business days .</p>');
				});	
			});
		}
});


$('#resend').click(function(){
        $(this).hide();
		sendEmail("WebVerification@schicktech.com",gup("id"),"/portal/dicom_download/email_resend_request.php");
		insertDicomTable('resendRequest',gup("id"));
		$(this).parent().append("<p><b>Your request has been resent.</b></p>");
			
});


 }



function sendEmail(email,id,templatePath){

$.ajax({
   			type: "POST",
   			url: window.location.protocol+"//"+window.location.hostname+templatePath,
   			data: "id="+id+"&address="+email,
   			success: function(msg){	
   			}
 });
}

function updateADAPosterTable(dentistData){
	$.ajax({
   					type: "POST",
   					url: window.location.protocol+"//"+window.location.hostname+"/adaPoster/update_table.php",
   					data: dentistData,
   					success: function(msg){
   					}
 		   });
}


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

   					}
 		   });
}




function insertDicomTable(action,requester){
	$.ajax({
   					type: "POST",
   					url: window.location.protocol+"//"+window.location.hostname+"/portal/dicom_download/update_table.php",
   					data: "requester="+requester+"&action="+action,
   					success: function(msg){
   					}
 		   });
}



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() {
			 if (fieldtofocus !== "undefined"){
				fieldtofocus.focus()
			 }
			}
		
	   if (window.addEventListener){
			window.addEventListener('load', focusOnUserField, false);
		}
	   else if (window.attachEvent){
		   window.attachEvent('onload', focusOnUserField);
	   }
}
